Socket
Socket
Sign inDemoInstall

@capacitor-community/sqlite

Package Overview
Dependencies
Maintainers
33
Versions
242
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@capacitor-community/sqlite - npm Package Compare versions

Comparing version 3.1.3-1 to 3.1.3-2

dist/esm/web-utils/utils-store.d.ts

6

CHANGELOG.md

@@ -0,1 +1,7 @@

## 3.1.3-2 (2021-07-27)
### Bug Fixes
- copyFromAssets only takes files with SQLite.db suffix on iOS (contrary to Android) issue#152
## 3.1.3-1 (2021-07-24)

@@ -2,0 +8,0 @@

4

dist/esm/definitions.js

@@ -95,3 +95,2 @@ /**

res.result = this._connectionDict.has(database);
console.log(`isConnection ${res.result}`);
return Promise.resolve(res);

@@ -137,3 +136,2 @@ }

const res = await this.sqlite.checkConnectionsConsistency({ dbNames: keys });
console.log(`$$$$$ SQLiteConnection res.result ${res.result}`);
if (!res.result)

@@ -275,3 +273,2 @@ this._connectionDict = new Map();

}
console.log(`&&&&& in DBConnection query ${JSON.stringify(res)}`);
return Promise.resolve(res);

@@ -329,3 +326,2 @@ }

try {
console.log(`$$$ executeSet ${JSON.stringify(set)}`);
/* temporary fix for null */

@@ -332,0 +328,0 @@ const modSet = [];

import { WebPlugin } from '@capacitor/core';
import type { CapacitorSQLitePlugin, capEchoOptions, capSQLiteOptions, capSQLiteExecuteOptions, capSQLiteSetOptions, capSQLiteRunOptions, capSQLiteQueryOptions, capSQLiteImportOptions, capSQLiteExportOptions, capSQLiteSyncDateOptions, capSQLiteUpgradeOptions, capSQLiteTableOptions, capSQLitePathOptions, capEchoResult, capSQLiteResult, capSQLiteChanges, capSQLiteValues, capSQLiteJson, capSQLiteSyncDate, capAllConnectionsOptions, capSetSecretOptions, capChangeSecretOptions } from './definitions';
export declare class CapacitorSQLiteWeb extends WebPlugin implements CapacitorSQLitePlugin {
private store;
private isStore;
constructor();
echo(options: capEchoOptions): Promise<capEchoResult>;

@@ -33,2 +36,4 @@ isSecretStored(): Promise<capSQLiteResult>;

deleteOldDatabases(options: capSQLitePathOptions): Promise<void>;
private openStore;
private setConfig;
}
import { WebPlugin } from '@capacitor/core';
import localForage from 'localforage';
import initSqlJs from 'sql.js';
import { getDBFromStore, setInitialDBToStore, setDBToStore /*,
removeDBFromStore, isDBInStore */ } from './web-utils/utils-store';
export class CapacitorSQLiteWeb extends WebPlugin {
constructor() {
super();
this.isStore = false;
this.isStore = this.openStore("jeepSqliteStore", "databases");
}
async echo(options) {
console.log('ECHO in Web plugin', options);
if (this.isStore) {
try {
const SQL = await initSqlJs( /*{
locateFile: filename => `public/${filename}`
}*/);
// retrieve the database if stored on localforage
const retDB = await getDBFromStore("testSQLite.db", this.store);
let db = null;
if (retDB != null) {
// Open existing database
db = new SQL.Database(retDB);
let res = db.exec("SELECT * FROM test");
console.log(`Select test ${JSON.stringify(res)}`);
res = db.exec("SELECT * FROM hello");
console.log(`Select hello ${JSON.stringify(res)}`);
console.log(">>>> start dropping all tables");
let dropstr = "PRAGMA writable_schema = 1;";
dropstr += "delete from sqlite_master where type in ('table', 'index', 'trigger');";
dropstr += "PRAGMA writable_schema = 0;";
dropstr += "VACUUM;";
dropstr += "PRAGMA INTEGRITY_CHECK;";
db.run(dropstr); // Run the query without returning anything
console.log(">>>> end dropping all tables");
res = db.exec("SELECT * from sqlite_master where type in ('table', 'index', 'trigger');");
console.log(`Select tables ${JSON.stringify(res)}`);
}
else {
// Create a new database
console.log("$$$$ i am in creating the db");
db = new SQL.Database();
await setInitialDBToStore("testSQLite.db", this.store);
}
// NOTE: You can also use new SQL.Database(data) where
// data is an Uint8Array representing an SQLite database file
// Run a query without reading the results
db.run("CREATE TABLE IF NOT EXISTS test (col1, col2);");
// Insert two rows: (1,111) and (2,222)
db.run("INSERT INTO test VALUES (?,?), (?,?)", [1, 111, 2, 222]);
// Prepare a statement
const stmt = db.prepare("SELECT * FROM test WHERE col1 BETWEEN $start AND $end");
stmt.getAsObject({ $start: 1, $end: 1 }); // {col1:1, col2:111}
// Bind new values
stmt.bind({ $start: 1, $end: 2 });
while (stmt.step()) { //
const row = stmt.getAsObject();
console.log(`Here is a row: ${JSON.stringify(row)}`);
}
// free the memory used by the statement
stmt.free();
// You can not use your statement anymore once it has been freed.
// But not freeing your statements causes memory leaks. You don't want that.
// Execute a single SQL string that contains multiple statements
let sqlstr = "CREATE TABLE IF NOT EXISTS hello (a int, b char);";
sqlstr += "INSERT INTO hello VALUES (0, 'hello');";
sqlstr += "INSERT INTO hello VALUES (1, 'world');";
db.run(sqlstr); // Run the query without returning anything
const res = db.exec("SELECT * FROM hello");
console.log(`Select ${JSON.stringify(res)}`);
// store db to store
await setDBToStore(db, "testSQLite.db", this.store);
}
catch (err) {
console.log(`Storage failed: ${err} `);
}
}
else {
console.log(`Store not opened `);
}
return options;

@@ -118,3 +195,23 @@ }

}
openStore(dbName, tableName) {
let ret = false;
const config = this.setConfig(dbName, tableName);
console.log(`config ${JSON.stringify(config)}`);
console.log(`LocalForage ${JSON.stringify(localForage)}`);
this.store = localForage.createInstance(config);
if (this.store != null) {
ret = true;
}
return ret;
}
setConfig(dbName, tableName) {
const config = {
name: dbName,
storeName: tableName,
driver: [localForage.INDEXEDDB],
version: 1,
};
return config;
}
}
//# sourceMappingURL=web.js.map

@@ -6,3 +6,10 @@ 'use strict';

var core = require('@capacitor/core');
var localForage = require('localforage');
var initSqlJs = require('sql.js');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var localForage__default = /*#__PURE__*/_interopDefaultLegacy(localForage);
var initSqlJs__default = /*#__PURE__*/_interopDefaultLegacy(initSqlJs);
/**

@@ -102,3 +109,2 @@ * SQLiteConnection Class

res.result = this._connectionDict.has(database);
console.log(`isConnection ${res.result}`);
return Promise.resolve(res);

@@ -144,3 +150,2 @@ }

const res = await this.sqlite.checkConnectionsConsistency({ dbNames: keys });
console.log(`$$$$$ SQLiteConnection res.result ${res.result}`);
if (!res.result)

@@ -282,3 +287,2 @@ this._connectionDict = new Map();

}
console.log(`&&&&& in DBConnection query ${JSON.stringify(res)}`);
return Promise.resolve(res);

@@ -336,3 +340,2 @@ }

try {
console.log(`$$$ executeSet ${JSON.stringify(set)}`);
/* temporary fix for null */

@@ -475,5 +478,112 @@ const modSet = [];

const getDBFromStore = async (dbName, store) => {
try {
const retDb = await store.getItem(dbName);
return Promise.resolve(retDb);
}
catch (err) {
return Promise.reject(`in getDBFromStore ${err}`);
}
};
const setInitialDBToStore = async (dbName, store) => {
try {
// export the database
const data = null;
// store the database
await store.setItem(dbName, data);
return Promise.resolve();
}
catch (err) {
return Promise.reject(`in setDBToStore ${err}`);
}
};
const setDBToStore = async (mDb, dbName, store) => {
try {
// export the database
const data = mDb.export();
// store the database
await store.setItem(dbName, data);
return Promise.resolve();
}
catch (err) {
return Promise.reject(`in setDBToStore ${err}`);
}
};
class CapacitorSQLiteWeb extends core.WebPlugin {
constructor() {
super();
this.isStore = false;
this.isStore = this.openStore("jeepSqliteStore", "databases");
}
async echo(options) {
console.log('ECHO in Web plugin', options);
if (this.isStore) {
try {
const SQL = await initSqlJs__default['default']( /*{
locateFile: filename => `public/${filename}`
}*/);
// retrieve the database if stored on localforage
const retDB = await getDBFromStore("testSQLite.db", this.store);
let db = null;
if (retDB != null) {
// Open existing database
db = new SQL.Database(retDB);
let res = db.exec("SELECT * FROM test");
console.log(`Select test ${JSON.stringify(res)}`);
res = db.exec("SELECT * FROM hello");
console.log(`Select hello ${JSON.stringify(res)}`);
console.log(">>>> start dropping all tables");
let dropstr = "PRAGMA writable_schema = 1;";
dropstr += "delete from sqlite_master where type in ('table', 'index', 'trigger');";
dropstr += "PRAGMA writable_schema = 0;";
dropstr += "VACUUM;";
dropstr += "PRAGMA INTEGRITY_CHECK;";
db.run(dropstr); // Run the query without returning anything
console.log(">>>> end dropping all tables");
res = db.exec("SELECT * from sqlite_master where type in ('table', 'index', 'trigger');");
console.log(`Select tables ${JSON.stringify(res)}`);
}
else {
// Create a new database
console.log("$$$$ i am in creating the db");
db = new SQL.Database();
await setInitialDBToStore("testSQLite.db", this.store);
}
// NOTE: You can also use new SQL.Database(data) where
// data is an Uint8Array representing an SQLite database file
// Run a query without reading the results
db.run("CREATE TABLE IF NOT EXISTS test (col1, col2);");
// Insert two rows: (1,111) and (2,222)
db.run("INSERT INTO test VALUES (?,?), (?,?)", [1, 111, 2, 222]);
// Prepare a statement
const stmt = db.prepare("SELECT * FROM test WHERE col1 BETWEEN $start AND $end");
stmt.getAsObject({ $start: 1, $end: 1 }); // {col1:1, col2:111}
// Bind new values
stmt.bind({ $start: 1, $end: 2 });
while (stmt.step()) { //
const row = stmt.getAsObject();
console.log(`Here is a row: ${JSON.stringify(row)}`);
}
// free the memory used by the statement
stmt.free();
// You can not use your statement anymore once it has been freed.
// But not freeing your statements causes memory leaks. You don't want that.
// Execute a single SQL string that contains multiple statements
let sqlstr = "CREATE TABLE IF NOT EXISTS hello (a int, b char);";
sqlstr += "INSERT INTO hello VALUES (0, 'hello');";
sqlstr += "INSERT INTO hello VALUES (1, 'world');";
db.run(sqlstr); // Run the query without returning anything
const res = db.exec("SELECT * FROM hello");
console.log(`Select ${JSON.stringify(res)}`);
// store db to store
await setDBToStore(db, "testSQLite.db", this.store);
}
catch (err) {
console.log(`Storage failed: ${err} `);
}
}
else {
console.log(`Store not opened `);
}
return options;

@@ -592,2 +702,22 @@ }

}
openStore(dbName, tableName) {
let ret = false;
const config = this.setConfig(dbName, tableName);
console.log(`config ${JSON.stringify(config)}`);
console.log(`LocalForage ${JSON.stringify(localForage__default['default'])}`);
this.store = localForage__default['default'].createInstance(config);
if (this.store != null) {
ret = true;
}
return ret;
}
setConfig(dbName, tableName) {
const config = {
name: dbName,
storeName: tableName,
driver: [localForage__default['default'].INDEXEDDB],
version: 1,
};
return config;
}
}

@@ -594,0 +724,0 @@

@@ -1,4 +0,9 @@

var capacitorCapacitorSQLite = (function (exports, core) {
var capacitorCapacitorSQLite = (function (exports, core, localForage, initSqlJs) {
'use strict';
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var localForage__default = /*#__PURE__*/_interopDefaultLegacy(localForage);
var initSqlJs__default = /*#__PURE__*/_interopDefaultLegacy(initSqlJs);
/**

@@ -98,3 +103,2 @@ * SQLiteConnection Class

res.result = this._connectionDict.has(database);
console.log(`isConnection ${res.result}`);
return Promise.resolve(res);

@@ -140,3 +144,2 @@ }

const res = await this.sqlite.checkConnectionsConsistency({ dbNames: keys });
console.log(`$$$$$ SQLiteConnection res.result ${res.result}`);
if (!res.result)

@@ -278,3 +281,2 @@ this._connectionDict = new Map();

}
console.log(`&&&&& in DBConnection query ${JSON.stringify(res)}`);
return Promise.resolve(res);

@@ -332,3 +334,2 @@ }

try {
console.log(`$$$ executeSet ${JSON.stringify(set)}`);
/* temporary fix for null */

@@ -471,5 +472,112 @@ const modSet = [];

const getDBFromStore = async (dbName, store) => {
try {
const retDb = await store.getItem(dbName);
return Promise.resolve(retDb);
}
catch (err) {
return Promise.reject(`in getDBFromStore ${err}`);
}
};
const setInitialDBToStore = async (dbName, store) => {
try {
// export the database
const data = null;
// store the database
await store.setItem(dbName, data);
return Promise.resolve();
}
catch (err) {
return Promise.reject(`in setDBToStore ${err}`);
}
};
const setDBToStore = async (mDb, dbName, store) => {
try {
// export the database
const data = mDb.export();
// store the database
await store.setItem(dbName, data);
return Promise.resolve();
}
catch (err) {
return Promise.reject(`in setDBToStore ${err}`);
}
};
class CapacitorSQLiteWeb extends core.WebPlugin {
constructor() {
super();
this.isStore = false;
this.isStore = this.openStore("jeepSqliteStore", "databases");
}
async echo(options) {
console.log('ECHO in Web plugin', options);
if (this.isStore) {
try {
const SQL = await initSqlJs__default['default']( /*{
locateFile: filename => `public/${filename}`
}*/);
// retrieve the database if stored on localforage
const retDB = await getDBFromStore("testSQLite.db", this.store);
let db = null;
if (retDB != null) {
// Open existing database
db = new SQL.Database(retDB);
let res = db.exec("SELECT * FROM test");
console.log(`Select test ${JSON.stringify(res)}`);
res = db.exec("SELECT * FROM hello");
console.log(`Select hello ${JSON.stringify(res)}`);
console.log(">>>> start dropping all tables");
let dropstr = "PRAGMA writable_schema = 1;";
dropstr += "delete from sqlite_master where type in ('table', 'index', 'trigger');";
dropstr += "PRAGMA writable_schema = 0;";
dropstr += "VACUUM;";
dropstr += "PRAGMA INTEGRITY_CHECK;";
db.run(dropstr); // Run the query without returning anything
console.log(">>>> end dropping all tables");
res = db.exec("SELECT * from sqlite_master where type in ('table', 'index', 'trigger');");
console.log(`Select tables ${JSON.stringify(res)}`);
}
else {
// Create a new database
console.log("$$$$ i am in creating the db");
db = new SQL.Database();
await setInitialDBToStore("testSQLite.db", this.store);
}
// NOTE: You can also use new SQL.Database(data) where
// data is an Uint8Array representing an SQLite database file
// Run a query without reading the results
db.run("CREATE TABLE IF NOT EXISTS test (col1, col2);");
// Insert two rows: (1,111) and (2,222)
db.run("INSERT INTO test VALUES (?,?), (?,?)", [1, 111, 2, 222]);
// Prepare a statement
const stmt = db.prepare("SELECT * FROM test WHERE col1 BETWEEN $start AND $end");
stmt.getAsObject({ $start: 1, $end: 1 }); // {col1:1, col2:111}
// Bind new values
stmt.bind({ $start: 1, $end: 2 });
while (stmt.step()) { //
const row = stmt.getAsObject();
console.log(`Here is a row: ${JSON.stringify(row)}`);
}
// free the memory used by the statement
stmt.free();
// You can not use your statement anymore once it has been freed.
// But not freeing your statements causes memory leaks. You don't want that.
// Execute a single SQL string that contains multiple statements
let sqlstr = "CREATE TABLE IF NOT EXISTS hello (a int, b char);";
sqlstr += "INSERT INTO hello VALUES (0, 'hello');";
sqlstr += "INSERT INTO hello VALUES (1, 'world');";
db.run(sqlstr); // Run the query without returning anything
const res = db.exec("SELECT * FROM hello");
console.log(`Select ${JSON.stringify(res)}`);
// store db to store
await setDBToStore(db, "testSQLite.db", this.store);
}
catch (err) {
console.log(`Storage failed: ${err} `);
}
}
else {
console.log(`Store not opened `);
}
return options;

@@ -588,2 +696,22 @@ }

}
openStore(dbName, tableName) {
let ret = false;
const config = this.setConfig(dbName, tableName);
console.log(`config ${JSON.stringify(config)}`);
console.log(`LocalForage ${JSON.stringify(localForage__default['default'])}`);
this.store = localForage__default['default'].createInstance(config);
if (this.store != null) {
ret = true;
}
return ret;
}
setConfig(dbName, tableName) {
const config = {
name: dbName,
storeName: tableName,
driver: [localForage__default['default'].INDEXEDDB],
version: 1,
};
return config;
}
}

@@ -604,3 +732,3 @@

}({}, capacitorExports));
}({}, capacitorExports, localForage, initSqlJs));
//# sourceMappingURL=plugin.js.map
{
"name": "@capacitor-community/sqlite",
"version": "3.1.3-1",
"version": "3.1.3-2",
"description": "Community plugin for native & electron SQLite databases",

@@ -65,5 +65,7 @@ "main": "dist/plugin.cjs.js",

"@rollup/plugin-commonjs": "^19.0.0",
"@rollup/plugin-node-resolve": "^13.0.0",
"@rollup/plugin-node-resolve": "^13.0.4",
"@types/sql.js": "^1.4.2",
"electron": "^13.1.3",
"eslint": "^7.11.0",
"localforage": "^1.9.0",
"prettier": "~2.2.0",

@@ -73,2 +75,3 @@ "prettier-plugin-java": "~1.0.0",

"rollup": "^2.32.0",
"sql.js": "^1.5.0",
"swiftlint": "^1.0.1",

@@ -75,0 +78,0 @@ "typescript": "~4.0.5"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc