@kikko-land/electron-better-sqlite3-backend
Advanced tools
Comparing version 0.1.1 to 0.2.0
# @kikko-land/electron-better-sqlite3-backend | ||
## 0.2.0 | ||
### Minor Changes | ||
- 174767c: Rename kikko to core | ||
### Patch Changes | ||
- Updated dependencies [174767c] | ||
- @kikko-land/kikko@0.2.0 | ||
## 0.1.1 | ||
@@ -4,0 +15,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { IDbBackend } from "@kikko-land/core"; | ||
import { IDbBackend } from "@kikko-land/kikko"; | ||
declare global { | ||
@@ -3,0 +3,0 @@ interface Window { |
{ | ||
"name": "@kikko-land/electron-better-sqlite3-backend", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"author": "Sergey Popov", | ||
@@ -61,3 +61,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"@kikko-land/core": "^0.1.1", | ||
"@kikko-land/kikko": "^0.2.0", | ||
"@kikko-land/sql": "^0.1.1", | ||
@@ -64,0 +64,0 @@ "@kikko-land/sql.js": "^1.6.8", |
@@ -1,6 +0,8 @@ | ||
import { IDbBackend, IQuery, IQueryResult } from "@kikko-land/core"; | ||
import { IDbBackend, IQuery, IQueryResult } from "@kikko-land/kikko"; | ||
declare global { | ||
interface Window { | ||
sqliteDb: (path: string) => Promise<{ | ||
sqliteDb: ( | ||
path: string | ||
) => Promise<{ | ||
close: (callback?: (err: Error | null) => void) => void; | ||
@@ -11,4 +13,4 @@ all: ( | ||
params: any | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
) => any[]; | ||
) => // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
any[]; | ||
}>; | ||
@@ -19,64 +21,63 @@ } | ||
export type ValueType<T> = T extends Promise<infer U> ? U : T; | ||
export const electronBetterSqlite3Backend = | ||
(path: (dbName: string) => string): IDbBackend => | ||
({ dbName, stopped$ }) => { | ||
let db: ValueType<ReturnType<typeof window.sqliteDb>> | undefined = | ||
undefined; | ||
export const electronBetterSqlite3Backend = ( | ||
path: (dbName: string) => string | ||
): IDbBackend => ({ dbName, stopped$ }) => { | ||
let db: ValueType<ReturnType<typeof window.sqliteDb>> | undefined = undefined; | ||
return { | ||
async initialize() { | ||
db = await window.sqliteDb(path(dbName)); | ||
return { | ||
async initialize() { | ||
db = await window.sqliteDb(path(dbName)); | ||
stopped$.subscribe(() => { | ||
if (!db) { | ||
console.error("Failed to stop DB‚Äö it is not initialized"); | ||
stopped$.subscribe(() => { | ||
if (!db) { | ||
console.error("Failed to stop DB‚Äö it is not initialized"); | ||
return; | ||
} | ||
db.close(); | ||
}); | ||
}, | ||
async execQueries( | ||
queries: IQuery[], | ||
opts: { | ||
log: { | ||
suppress: boolean; | ||
transactionId?: string; | ||
}; | ||
return; | ||
} | ||
) { | ||
if (!db) { | ||
throw new Error( | ||
`Failed to run queries: ${queries | ||
.map((q) => q.text) | ||
.join(" ")}, db not initialized` | ||
); | ||
} | ||
db.close(); | ||
}); | ||
}, | ||
async execQueries( | ||
queries: IQuery[], | ||
opts: { | ||
log: { | ||
suppress: boolean; | ||
transactionId?: string; | ||
}; | ||
} | ||
) { | ||
if (!db) { | ||
throw new Error( | ||
`Failed to run queries: ${queries | ||
.map((q) => q.text) | ||
.join(" ")}, db not initialized` | ||
); | ||
} | ||
const result: IQueryResult[] = []; | ||
const result: IQueryResult[] = []; | ||
for (const q of queries) { | ||
const startTime = performance.now(); | ||
for (const q of queries) { | ||
const startTime = performance.now(); | ||
result.push(db.all(q.text, q.values)); | ||
result.push(db.all(q.text, q.values)); | ||
const end = performance.now(); | ||
const end = performance.now(); | ||
if (!opts.log.suppress) { | ||
console.info( | ||
`[${dbName}]${ | ||
opts.log.transactionId | ||
? `[tr_id=${opts.log.transactionId.slice(0, 6)}]` | ||
: "" | ||
} ` + | ||
queries.map((q) => q.text).join(" ") + | ||
" Time: " + | ||
((end - startTime) / 1000).toFixed(4) | ||
); | ||
} | ||
if (!opts.log.suppress) { | ||
console.info( | ||
`[${dbName}]${ | ||
opts.log.transactionId | ||
? `[tr_id=${opts.log.transactionId.slice(0, 6)}]` | ||
: "" | ||
} ` + | ||
queries.map((q) => q.text).join(" ") + | ||
" Time: " + | ||
((end - startTime) / 1000).toFixed(4) | ||
); | ||
} | ||
} | ||
return result; | ||
}, | ||
}; | ||
return result; | ||
}, | ||
}; | ||
}; |
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
Sorry, the diff of this file is not supported yet
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
210
27933
+ Added@kikko-land/kikko@^0.2.0
+ Added@kikko-land/kikko@0.2.1(transitive)
+ Added@kikko-land/query-builder@0.1.1(transitive)
+ Addedrxjs@7.8.1(transitive)
+ Addedts-essentials@9.4.2(transitive)
+ Addedtslib@2.8.1(transitive)
- Removed@kikko-land/core@^0.1.1