jeep-sqlite
Advanced tools
Comparing version 0.0.1-alpha.3 to 0.0.1-alpha.4
@@ -18,3 +18,3 @@ 'use strict'; | ||
patchBrowser().then(options => { | ||
return index.bootstrapLazy([["jeep-sqlite.cjs",[[1,"jeep-sqlite",{"echo":[64],"createConnection":[64],"closeConnection":[64],"open":[64],"close":[64],"execute":[64],"run":[64],"query":[64],"isDBExists":[64],"isDBOpen":[64],"deleteDatabase":[64],"isStoreOpen":[64]}]]]], options); | ||
return index.bootstrapLazy([["jeep-sqlite.cjs",[[1,"jeep-sqlite",{"echo":[64],"createConnection":[64],"closeConnection":[64],"open":[64],"close":[64],"execute":[64],"executeSet":[64],"run":[64],"query":[64],"isDBExists":[64],"isDBOpen":[64],"deleteDatabase":[64],"isStoreOpen":[64]}]]]], options); | ||
}); |
@@ -17,3 +17,3 @@ 'use strict'; | ||
return patchEsm().then(() => { | ||
return index.bootstrapLazy([["jeep-sqlite.cjs",[[1,"jeep-sqlite",{"echo":[64],"createConnection":[64],"closeConnection":[64],"open":[64],"close":[64],"execute":[64],"run":[64],"query":[64],"isDBExists":[64],"isDBOpen":[64],"deleteDatabase":[64],"isStoreOpen":[64]}]]]], options); | ||
return index.bootstrapLazy([["jeep-sqlite.cjs",[[1,"jeep-sqlite",{"echo":[64],"createConnection":[64],"closeConnection":[64],"open":[64],"close":[64],"execute":[64],"executeSet":[64],"run":[64],"query":[64],"isDBExists":[64],"isDBOpen":[64],"deleteDatabase":[64],"isStoreOpen":[64]}]]]], options); | ||
}); | ||
@@ -20,0 +20,0 @@ }; |
@@ -9,2 +9,5 @@ import { Component, Method } from '@stencil/core'; | ||
} | ||
//********************** | ||
//* Method Definitions * | ||
//********************** | ||
async echo(value) { | ||
@@ -92,2 +95,23 @@ return { value: value }; | ||
} | ||
async executeSet(options) { | ||
let keys = Object.keys(options); | ||
if (!keys.includes('database')) { | ||
return Promise.reject('Must provide a database name'); | ||
} | ||
if (!keys.includes('set') || options.set.length === 0) { | ||
return Promise.reject('Must provide a non-empty set of SQL statements'); | ||
} | ||
const dbName = options.database; | ||
const setOfStatements = options.set; | ||
let transaction = true; | ||
if (keys.includes('transaction')) | ||
transaction = options.transaction; | ||
try { | ||
const changes = await this._executeSet(dbName, setOfStatements, transaction); | ||
return Promise.resolve(changes); | ||
} | ||
catch (err) { | ||
return Promise.reject(err); | ||
} | ||
} | ||
async run(options) { | ||
@@ -169,5 +193,10 @@ let keys = Object.keys(options); | ||
} | ||
async deleteDatabase(database) { | ||
async deleteDatabase(options) { | ||
const keys = Object.keys(options); | ||
if (!keys.includes('database')) { | ||
return Promise.reject('Must provide a database name'); | ||
} | ||
const dbName = options.database; | ||
try { | ||
return await this._deleteDatabase(database); | ||
return await this._deleteDatabase(dbName); | ||
} | ||
@@ -181,2 +210,5 @@ catch (err) { | ||
} | ||
//******************************* | ||
//* Component Lifecycle Methods * | ||
//******************************* | ||
async componentWillLoad() { | ||
@@ -186,2 +218,5 @@ this.isStore = await this.openStore("jeepSqliteStore", "databases"); | ||
} | ||
//****************************** | ||
//* Private Method Definitions * | ||
//****************************** | ||
async _createConnection(database, version) { | ||
@@ -201,3 +236,3 @@ console.log(`in _createConnection ${database}`); | ||
if (!keys.includes(database)) { | ||
return Promise.reject(`Open: No available connection for ${database}`); | ||
return Promise.reject(`CloseConnection: No available connection for ${database}`); | ||
} | ||
@@ -220,3 +255,3 @@ const mDB = this._dbDict[database]; | ||
catch (err) { | ||
return Promise.reject(`Delete: ${err.message}`); | ||
return Promise.reject(`CloseConnection: ${err.message}`); | ||
} | ||
@@ -255,3 +290,3 @@ } | ||
if (!keys.includes(database)) { | ||
return Promise.reject(`Close: No available connection for ${database}`); | ||
return Promise.reject(`Execute: No available connection for ${database}`); | ||
} | ||
@@ -265,9 +300,29 @@ const mDB = this._dbDict[database]; | ||
catch (err) { | ||
return Promise.reject(`Close: ${err.message}`); | ||
return Promise.reject(`Execute: ${err.message}`); | ||
} | ||
} | ||
async _executeSet(database, setOfStatements, transaction) { | ||
const keys = Object.keys(this._dbDict); | ||
if (!keys.includes(database)) { | ||
return Promise.reject(`ExecuteSet: No available connection for ${database}`); | ||
} | ||
const mDB = this._dbDict[database]; | ||
for (const sStmt of setOfStatements) { | ||
if (!('statement' in sStmt) || !('values' in sStmt)) { | ||
return Promise.reject('ExecuteSet: Must provide a set as ' + 'Array of {statement,values}'); | ||
} | ||
} | ||
try { | ||
const ret = await mDB.execSet(setOfStatements, transaction); | ||
const changes = { changes: { changes: ret.changes, lastId: ret.lastId } }; | ||
return Promise.resolve(changes); | ||
} | ||
catch (err) { | ||
return Promise.reject(`ExecuteSet: ${err.message}`); | ||
} | ||
} | ||
async _run(database, statement, values, transaction) { | ||
const keys = Object.keys(this._dbDict); | ||
if (!keys.includes(database)) { | ||
return Promise.reject(`Close: No available connection for ${database}`); | ||
return Promise.reject(`Run: No available connection for ${database}`); | ||
} | ||
@@ -302,7 +357,7 @@ const mDB = this._dbDict[database]; | ||
if (!keys.includes(database)) { | ||
return Promise.reject(`Close: No available connection for ${database}`); | ||
return Promise.reject(`IsDBExists: No available connection for ${database}`); | ||
} | ||
const mDB = this._dbDict[database]; | ||
try { | ||
const ret = await mDB.isDBExists(database); | ||
const ret = await mDB.isDBExists(database + 'SQLite.db'); | ||
const result = { result: ret }; | ||
@@ -312,3 +367,3 @@ return Promise.resolve(result); | ||
catch (err) { | ||
return Promise.reject(`isDBExists: ${err.message}`); | ||
return Promise.reject(`IsDBExists: ${err.message}`); | ||
} | ||
@@ -319,7 +374,7 @@ } | ||
if (!keys.includes(database)) { | ||
return Promise.reject(`Close: No available connection for ${database}`); | ||
return Promise.reject(`IsDBOpen: No available connection for ${database}`); | ||
} | ||
const mDB = this._dbDict[database]; | ||
try { | ||
const ret = mDB.isDBOpen(database); | ||
const ret = mDB.isDBOpen(database + 'SQLite.db'); | ||
const result = { result: ret }; | ||
@@ -329,3 +384,3 @@ return Promise.resolve(result); | ||
catch (err) { | ||
return Promise.reject(`isDBOpen: ${err.message}`); | ||
return Promise.reject(`IsDBOpen: ${err.message}`); | ||
} | ||
@@ -336,3 +391,3 @@ } | ||
if (!keys.includes(database)) { | ||
return Promise.reject(`Open: No available connection for ${database}`); | ||
return Promise.reject(`DeleteDatabase: No available connection for ${database}`); | ||
} | ||
@@ -345,3 +400,3 @@ const mDB = this._dbDict[database]; | ||
catch (err) { | ||
return Promise.reject(`Delete: ${err.message}`); | ||
return Promise.reject(`DeleteDatabase: ${err.message}`); | ||
} | ||
@@ -523,2 +578,33 @@ } | ||
}, | ||
"executeSet": { | ||
"complexType": { | ||
"signature": "(options: SQLiteSetOptions) => Promise<SQLiteChanges>", | ||
"parameters": [{ | ||
"tags": [], | ||
"text": "" | ||
}], | ||
"references": { | ||
"Promise": { | ||
"location": "global" | ||
}, | ||
"SQLiteChanges": { | ||
"location": "import", | ||
"path": "../../interfaces/interfaces" | ||
}, | ||
"SQLiteSetOptions": { | ||
"location": "import", | ||
"path": "../../interfaces/interfaces" | ||
}, | ||
"SQLiteSet": { | ||
"location": "import", | ||
"path": "../../interfaces/interfaces" | ||
} | ||
}, | ||
"return": "Promise<SQLiteChanges>" | ||
}, | ||
"docs": { | ||
"text": "", | ||
"tags": [] | ||
} | ||
}, | ||
"run": { | ||
@@ -634,3 +720,3 @@ "complexType": { | ||
"complexType": { | ||
"signature": "(database: string) => Promise<void>", | ||
"signature": "(options: SQLiteOptions) => Promise<void>", | ||
"parameters": [{ | ||
@@ -643,2 +729,6 @@ "tags": [], | ||
"location": "global" | ||
}, | ||
"SQLiteOptions": { | ||
"location": "import", | ||
"path": "../../interfaces/interfaces" | ||
} | ||
@@ -645,0 +735,0 @@ }, |
import initSqlJs from 'sql.js'; | ||
import { getDBFromStore, setInitialDBToStore, setDBToStore, removeDBFromStore, isDBInStore } from './utils-store'; | ||
import { dbChanges, beginTransaction, rollbackTransaction, commitTransaction, execute, run, queryAll } from './utils-sqlite'; | ||
import { dbChanges, beginTransaction, rollbackTransaction, commitTransaction, execute, executeSet, run, queryAll } from './utils-sqlite'; | ||
export class Database { | ||
@@ -68,4 +68,6 @@ constructor(databaseName, version, store) { | ||
try { | ||
console.log(`in deleteDB ${database}`); | ||
// test if file exists | ||
const isExists = await this.isDBExists(database); | ||
console.log(`in deleteDB ${database} ${isExists}`); | ||
if (isExists && !this._isDBOpen) { | ||
@@ -79,2 +81,3 @@ // open the database | ||
if (isExists) { | ||
console.log(`in deleteDB ${database} going to remove`); | ||
await removeDBFromStore(database, this.store); | ||
@@ -117,2 +120,38 @@ } | ||
} | ||
async execSet(set, transaction = true) { | ||
if (!this._isDBOpen) { | ||
let msg = `ExecSet: Database ${this.dbName} `; | ||
msg += `not opened`; | ||
return Promise.reject(new Error(msg)); | ||
} | ||
console.log(`in execSet set ${set} ${transaction}`); | ||
const retRes = { changes: -1, lastId: -1 }; | ||
let initChanges = -1; | ||
try { | ||
initChanges = await dbChanges(this.mDb); | ||
if (transaction) | ||
await beginTransaction(this.mDb, this._isDBOpen); | ||
const lastId = await executeSet(this.mDb, set); | ||
if (lastId < 0) { | ||
return Promise.reject(new Error('ExecSet: changes < 0')); | ||
} | ||
if (transaction) | ||
await commitTransaction(this.mDb, this._isDBOpen); | ||
const changes = (await dbChanges(this.mDb)) - initChanges; | ||
retRes.changes = changes; | ||
retRes.lastId = lastId; | ||
return Promise.resolve(retRes); | ||
} | ||
catch (err) { | ||
let msg = `ExecSet: ${err.message}`; | ||
try { | ||
if (transaction) | ||
await rollbackTransaction(this.mDb, this._isDBOpen); | ||
} | ||
catch (err) { | ||
msg += ` : ${err.message}`; | ||
} | ||
return Promise.reject(new Error(`ExecSet: ${msg}`)); | ||
} | ||
} | ||
async selectSQL(sql, values) { | ||
@@ -119,0 +158,0 @@ if (!this._isDBOpen) { |
@@ -82,2 +82,35 @@ export const beginTransaction = async (db, isOpen) => { | ||
}; | ||
export const executeSet = async (db, set) => { | ||
let lastId = -1; | ||
for (let i = 0; i < set.length; i++) { | ||
const statement = 'statement' in set[i] ? set[i].statement : null; | ||
const values = 'values' in set[i] && set[i].values.length > 0 ? set[i].values : null; | ||
if (statement == null || values == null) { | ||
let msg = 'ExecuteSet: Error statement'; | ||
msg += ` or values are null for index ${i}`; | ||
return Promise.reject(new Error(msg)); | ||
} | ||
try { | ||
if (Array.isArray(values[0])) { | ||
for (const val of values) { | ||
const mVal = await replaceUndefinedByNull(val); | ||
console.log(`in executeSet: i ${i} statement ${statement} val ${mVal}`); | ||
await db.exec(statement, mVal); | ||
} | ||
} | ||
else { | ||
console.log(`in executeSet: i ${i} statement ${statement} values ${values}`); | ||
const mVal = await replaceUndefinedByNull(values); | ||
const res = await db.exec(statement, mVal); | ||
console.log(`in executeSet: ${JSON.stringify(res)}`); | ||
} | ||
lastId = await getLastId(db); | ||
console.log(`in executeSet: i ${i} lastId ${lastId}`); | ||
} | ||
catch (err) { | ||
return Promise.reject(new Error(`ExecuteSet: ${err.message}`)); | ||
} | ||
} | ||
return Promise.resolve(lastId); | ||
}; | ||
export const queryAll = async (db, sql, values) => { | ||
@@ -110,3 +143,4 @@ const result = []; | ||
if (values != null && values.length > 0) { | ||
await db.exec(statement, values); | ||
const mVal = await replaceUndefinedByNull(values); | ||
await db.exec(statement, mVal); | ||
} | ||
@@ -123,1 +157,11 @@ else { | ||
}; | ||
export const replaceUndefinedByNull = async (values) => { | ||
const retValues = []; | ||
for (const val of values) { | ||
let mVal = val; | ||
if (typeof val === 'undefined') | ||
mVal = null; | ||
retValues.push(mVal); | ||
} | ||
return Promise.resolve(retValues); | ||
}; |
@@ -7,3 +7,3 @@ export const getDBFromStore = async (dbName, store) => { | ||
catch (err) { | ||
return Promise.reject(`in getDBFromStore ${err}`); | ||
return Promise.reject(`in getDBFromStore ${err.message}`); | ||
} | ||
@@ -20,3 +20,3 @@ }; | ||
catch (err) { | ||
return Promise.reject(`in setDBToStore ${err}`); | ||
return Promise.reject(`in setDBToStore ${err.message}`); | ||
} | ||
@@ -33,3 +33,3 @@ }; | ||
catch (err) { | ||
return Promise.reject(`in setDBToStore ${err}`); | ||
return Promise.reject(`in setDBToStore ${err.message}`); | ||
} | ||
@@ -43,3 +43,3 @@ }; | ||
catch (err) { | ||
return Promise.reject(`in getDBFromStore ${err}`); | ||
return Promise.reject(`in removeDBFromStore ${err.message}`); | ||
} | ||
@@ -46,0 +46,0 @@ }; |
@@ -16,3 +16,3 @@ import { p as promiseResolve, b as bootstrapLazy } from './index-f18cb60b.js'; | ||
patchBrowser().then(options => { | ||
return bootstrapLazy([["jeep-sqlite",[[1,"jeep-sqlite",{"echo":[64],"createConnection":[64],"closeConnection":[64],"open":[64],"close":[64],"execute":[64],"run":[64],"query":[64],"isDBExists":[64],"isDBOpen":[64],"deleteDatabase":[64],"isStoreOpen":[64]}]]]], options); | ||
return bootstrapLazy([["jeep-sqlite",[[1,"jeep-sqlite",{"echo":[64],"createConnection":[64],"closeConnection":[64],"open":[64],"close":[64],"execute":[64],"executeSet":[64],"run":[64],"query":[64],"isDBExists":[64],"isDBOpen":[64],"deleteDatabase":[64],"isStoreOpen":[64]}]]]], options); | ||
}); |
@@ -13,3 +13,3 @@ import { p as promiseResolve, b as bootstrapLazy } from './index-f18cb60b.js'; | ||
return patchEsm().then(() => { | ||
return bootstrapLazy([["jeep-sqlite",[[1,"jeep-sqlite",{"echo":[64],"createConnection":[64],"closeConnection":[64],"open":[64],"close":[64],"execute":[64],"run":[64],"query":[64],"isDBExists":[64],"isDBOpen":[64],"deleteDatabase":[64],"isStoreOpen":[64]}]]]], options); | ||
return bootstrapLazy([["jeep-sqlite",[[1,"jeep-sqlite",{"echo":[64],"createConnection":[64],"closeConnection":[64],"open":[64],"close":[64],"execute":[64],"executeSet":[64],"run":[64],"query":[64],"isDBExists":[64],"isDBOpen":[64],"deleteDatabase":[64],"isStoreOpen":[64]}]]]], options); | ||
}); | ||
@@ -16,0 +16,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
import{p as e,b as n}from"./p-4002b696.js";(()=>{const n=import.meta.url,o={};return""!==n&&(o.resourcesUrl=new URL(".",n).href),e(o)})().then((e=>n([["p-b1d587b6",[[1,"jeep-sqlite",{echo:[64],createConnection:[64],closeConnection:[64],open:[64],close:[64],execute:[64],run:[64],query:[64],isDBExists:[64],isDBOpen:[64],deleteDatabase:[64],isStoreOpen:[64]}]]]],e))); | ||
import{p as e,b as t}from"./p-4002b696.js";(()=>{const t=import.meta.url,n={};return""!==t&&(n.resourcesUrl=new URL(".",t).href),e(n)})().then((e=>t([["p-33e10e09",[[1,"jeep-sqlite",{echo:[64],createConnection:[64],closeConnection:[64],open:[64],close:[64],execute:[64],executeSet:[64],run:[64],query:[64],isDBExists:[64],isDBOpen:[64],deleteDatabase:[64],isStoreOpen:[64]}]]]],e))); |
@@ -8,3 +8,3 @@ /* eslint-disable */ | ||
import { HTMLStencilElement, JSXBase } from "./stencil-public-runtime"; | ||
import { ConnectionOptions, EchoResult, SQLiteChanges, SQLiteExecuteOptions, SQLiteOptions, SQLiteQueryOptions, SQLiteResult, SQLiteRunOptions, SQLiteValues } from "./interfaces/interfaces"; | ||
import { ConnectionOptions, EchoResult, SQLiteChanges, SQLiteExecuteOptions, SQLiteOptions, SQLiteQueryOptions, SQLiteResult, SQLiteRunOptions, SQLiteSet, SQLiteSetOptions, SQLiteValues } from "./interfaces/interfaces"; | ||
export namespace Components { | ||
@@ -15,5 +15,6 @@ interface JeepSqlite { | ||
"createConnection": (options: ConnectionOptions) => Promise<void>; | ||
"deleteDatabase": (database: string) => Promise<void>; | ||
"deleteDatabase": (options: SQLiteOptions) => Promise<void>; | ||
"echo": (value: string) => Promise<EchoResult>; | ||
"execute": (options: SQLiteExecuteOptions) => Promise<SQLiteChanges>; | ||
"executeSet": (options: SQLiteSetOptions) => Promise<SQLiteChanges>; | ||
"isDBExists": (options: SQLiteOptions) => Promise<SQLiteResult>; | ||
@@ -20,0 +21,0 @@ "isDBOpen": (options: SQLiteOptions) => Promise<SQLiteResult>; |
@@ -1,2 +0,2 @@ | ||
import { ConnectionOptions, SQLiteOptions, SQLiteExecuteOptions, SQLiteQueryOptions, SQLiteRunOptions, EchoResult, SQLiteChanges, SQLiteResult, SQLiteValues } from '../../interfaces/interfaces'; | ||
import { ConnectionOptions, SQLiteOptions, SQLiteExecuteOptions, SQLiteQueryOptions, SQLiteRunOptions, SQLiteSetOptions, EchoResult, SQLiteChanges, SQLiteResult, SQLiteValues } from '../../interfaces/interfaces'; | ||
export declare class JeepSqlite { | ||
@@ -9,2 +9,3 @@ echo(value: string): Promise<EchoResult>; | ||
execute(options: SQLiteExecuteOptions): Promise<SQLiteChanges>; | ||
executeSet(options: SQLiteSetOptions): Promise<SQLiteChanges>; | ||
run(options: SQLiteRunOptions): Promise<SQLiteChanges>; | ||
@@ -14,3 +15,3 @@ query(options: SQLiteQueryOptions): Promise<SQLiteValues>; | ||
isDBOpen(options: SQLiteOptions): Promise<SQLiteResult>; | ||
deleteDatabase(database: string): Promise<void>; | ||
deleteDatabase(options: SQLiteOptions): Promise<void>; | ||
isStoreOpen(): Promise<boolean>; | ||
@@ -27,2 +28,3 @@ private store; | ||
private _execute; | ||
private _executeSet; | ||
private _run; | ||
@@ -29,0 +31,0 @@ private _query; |
@@ -0,1 +1,2 @@ | ||
import { SQLiteSet } from '../interfaces/interfaces'; | ||
export declare class Database { | ||
@@ -14,4 +15,5 @@ private _isDBOpen; | ||
executeSQL(sql: string, transaction?: boolean): Promise<number>; | ||
execSet(set: SQLiteSet[], transaction?: boolean): Promise<any>; | ||
selectSQL(sql: string, values: string[]): Promise<any[]>; | ||
runSQL(statement: string, values: any[], transaction?: boolean): Promise<any>; | ||
} |
@@ -7,3 +7,5 @@ export declare const beginTransaction: (db: any, isOpen: boolean) => Promise<void>; | ||
export declare const execute: (db: any, sql: string) => Promise<number>; | ||
export declare const executeSet: (db: any, set: any) => Promise<number>; | ||
export declare const queryAll: (db: any, sql: string, values: any[]) => Promise<any[]>; | ||
export declare const run: (db: any, statement: string, values: any[]) => Promise<number>; | ||
export declare const replaceUndefinedByNull: (values: any[]) => Promise<any[]>; |
{ | ||
"name": "jeep-sqlite", | ||
"version": "0.0.1-alpha.3", | ||
"version": "0.0.1-alpha.4", | ||
"description": "Browser SQLite Stencil Component", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.cjs.js", |
@@ -65,2 +65,3 @@ ![Built With Stencil](https://img.shields.io/badge/-Built%20With%20Stencil-16161d.svg?logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDE5LjIuMSwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IgoJIHZpZXdCb3g9IjAgMCA1MTIgNTEyIiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCA1MTIgNTEyOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI%2BCjxzdHlsZSB0eXBlPSJ0ZXh0L2NzcyI%2BCgkuc3Qwe2ZpbGw6I0ZGRkZGRjt9Cjwvc3R5bGU%2BCjxwYXRoIGNsYXNzPSJzdDAiIGQ9Ik00MjQuNywzNzMuOWMwLDM3LjYtNTUuMSw2OC42LTkyLjcsNjguNkgxODAuNGMtMzcuOSwwLTkyLjctMzAuNy05Mi43LTY4LjZ2LTMuNmgzMzYuOVYzNzMuOXoiLz4KPHBhdGggY2xhc3M9InN0MCIgZD0iTTQyNC43LDI5Mi4xSDE4MC40Yy0zNy42LDAtOTIuNy0zMS05Mi43LTY4LjZ2LTMuNkgzMzJjMzcuNiwwLDkyLjcsMzEsOTIuNyw2OC42VjI5Mi4xeiIvPgo8cGF0aCBjbGFzcz0ic3QwIiBkPSJNNDI0LjcsMTQxLjdIODcuN3YtMy42YzAtMzcuNiw1NC44LTY4LjYsOTIuNy02OC42SDMzMmMzNy45LDAsOTIuNywzMC43LDkyLjcsNjguNlYxNDEuN3oiLz4KPC9zdmc%2BCg%3D%3D&colorA=16161d&style=flat-square) | ||
| execute | ✅ | | ||
| executeSet | ✅ | | ||
| run | ✅ | | ||
@@ -76,2 +77,3 @@ | query | ✅ | | ||
```html | ||
@@ -165,5 +167,58 @@ <!DOCTYPE html> | ||
} | ||
// Test executeSet | ||
await jeepSqlite.createConnection({ | ||
database:"testSet", | ||
version: 1 | ||
}); | ||
ret = await jeepSqlite.isDBExists({database:"testSet"}); | ||
console.log(`is "testSet" database exist : ${ret.result}`); | ||
if (ret.result) { | ||
await jeepSqlite.deleteDatabase({database:"testSet"}); | ||
} | ||
const createSchemaContacts = ` | ||
CREATE TABLE IF NOT EXISTS contacts ( | ||
id INTEGER PRIMARY KEY NOT NULL, | ||
email TEXT UNIQUE NOT NULL, | ||
name TEXT, | ||
FirstName TEXT, | ||
company TEXT, | ||
size REAL, | ||
age INTEGER, | ||
MobileNumber TEXT | ||
); | ||
CREATE INDEX IF NOT EXISTS contacts_index_name ON contacts (name); | ||
CREATE INDEX IF NOT EXISTS contacts_index_email ON contacts (email); | ||
PRAGMA user_version = 1; | ||
`; | ||
// open db testSet | ||
await jeepSqlite.open({database: "testSet"}); | ||
const isDBSet = await jeepSqlite.isDBOpen({database: "testSet"}) | ||
const setContacts = [ | ||
{ statement:"INSERT INTO contacts (name,FirstName,email,company,age,MobileNumber) VALUES (?,?,?,?,?,?);", | ||
values:["Simpson","Tom","Simpson@example.com",null,69,"4405060708"] | ||
}, | ||
{ statement:"INSERT INTO contacts (name,FirstName,email,company,age,MobileNumber) VALUES (?,?,?,?,?,?);", | ||
values:[ | ||
["Jones","David","Jones@example.com",,42.1,"4404030201"], | ||
["Whiteley","Dave","Whiteley@example.com",,45.3,"4405162732"], | ||
["Brown","John","Brown@example.com",null,35,"4405243853"] | ||
] | ||
}, | ||
{ statement:"UPDATE contacts SET age = ? , MobileNumber = ? WHERE id = ?;", | ||
values:[51.4,"4404030202",2] | ||
} | ||
]; | ||
// Create testSet schema | ||
ret = await jeepSqlite.execute({database: "testSet", statements: createSchemaContacts}); | ||
console.log(`after Contact Execute 1 ${JSON.stringify(ret)}`); | ||
// Create testSet contact | ||
ret = await jeepSqlite.executeSet({database: "testSet", set: setContacts}); | ||
console.log(`after Contact Execute 1 ${JSON.stringify(ret)}`); | ||
if (ret.changes.changes !== 5) { | ||
return Promise.reject(new Error("ExecuteSet 5 contacts failed")); | ||
} | ||
await jeepSqlite.closeConnection({database:"testNew"}); | ||
await jeepSqlite.closeConnection({database:"testSet"}); | ||
console.log("db success"); | ||
@@ -170,0 +225,0 @@ } catch (err) { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1132437
22056
232