Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@kikko-land/electron-better-sqlite3-backend

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kikko-land/electron-better-sqlite3-backend - npm Package Compare versions

Comparing version 0.8.4 to 0.9.0

14

CHANGELOG.md
# @kikko-land/electron-better-sqlite3-backend
## 0.9.0
### Minor Changes
- a0170a6: Introduce new backend API
### Patch Changes
- Updated dependencies [dc4ac77]
- Updated dependencies [a0170a6]
- Updated dependencies [bf55118]
- @kikko-land/kikko@0.16.0
- @kikko-land/d1-backend@0.4.0
## 0.8.4

@@ -4,0 +18,0 @@

102

dist/index.es.js

@@ -1,68 +0,62 @@

import { initJobsState as k, getTime as a, acquireWithTrJobOrWait as v, releaseTrJobIfPossible as B } from "@kikko-land/kikko";
const E = (m) => ({ dbName: f }) => {
const l = k();
let n = !0, r;
const u = async (t, e) => {
if (!r)
throw new Error("Failed to run queries, db not initialized");
const c = a(), y = a(), b = await v(l, e), p = a() - y, d = [];
try {
const s = t.type === "usual" ? t.values : t.preparedValues.map(
(o) => ({
text: t.query.text,
values: o
})
);
for (const o of s) {
const h = a(), x = (() => {
import { initJobsState as p, buildSyncQueryRunner as b, getTime as n } from "@kikko-land/kikko";
const h = (l) => ({ dbName: u }) => {
const d = p();
let s = !0, e;
const w = b({
execPrepared(t, a) {
if (!e)
throw new Error("Failed to run queries, db not initialized");
const r = [];
for (const o of a) {
const c = n(), f = (() => {
try {
return r.all(o.text, o.values);
return e.all(t.text, o);
} catch (i) {
throw i instanceof Error && (i.message = `Error while executing query: ${o.text} - ${i.message}`), i;
throw i instanceof Error && (i.message = `Error while executing query: ${t.text} - ${i.message}`), i;
}
})(), T = a();
d.push({
rows: x,
})(), m = n();
r.push({
rows: f,
performance: {
execTime: T - h
execTime: m - c
}
});
}
} catch (s) {
if (e != null && e.rollbackOnFail)
try {
r.all("ROLLBACK", []);
} catch (o) {
console.error("Failed to rollback", s, o);
}
throw s;
} finally {
B(l, b, e);
return r;
},
execUsual(t) {
if (!e)
throw new Error("Failed to run queries, db not initialized");
return {
rows: e.all(
t.text,
t.values
),
performance: {}
};
},
rollback() {
if (!e)
throw new Error("Failed to run queries, db not initialized");
e.all("ROLLBACK", []);
}
const w = a();
return Promise.resolve({
result: d,
performance: {
totalTime: w - c,
blockTime: p
}
});
};
});
return {
async initialize() {
if (n)
if (s)
throw new Error("Failed to start DB cause it is stopped");
r = await window.sqliteDb(m(f)), n && r.close();
e = await window.sqliteDb(l(u)), s && e.close();
},
async execQueries(t, e) {
return u({ type: "usual", values: t }, e);
async execQueries(t, a) {
const r = n(), o = await w.run(d, t, a), c = n();
return {
...o,
performance: {
...o.performance,
totalTime: c - r
}
};
},
async execPreparedQuery(t, e, c) {
return u(
{ type: "prepared", query: t, preparedValues: e },
c
);
},
stop() {
return n = !0, r && r.close(), Promise.resolve();
return s = !0, e && e.close(), Promise.resolve();
}

@@ -72,4 +66,4 @@ };

export {
E as electronBetterSqlite3Backend
h as electronBetterSqlite3Backend
};
//# sourceMappingURL=index.es.js.map

@@ -1,2 +0,2 @@

(function(o,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("@kikko-land/kikko")):typeof define=="function"&&define.amd?define(["exports","@kikko-land/kikko"],e):(o=typeof globalThis<"u"?globalThis:o||self,e(o.core={},o.kikko))})(this,function(o,e){"use strict";const m=p=>({dbName:y})=>{const u=e.initJobsState();let l=!0,n;const d=async(r,t)=>{if(!n)throw new Error("Failed to run queries, db not initialized");const c=e.getTime(),T=e.getTime(),b=await e.acquireWithTrJobOrWait(u,t),h=e.getTime()-T,f=[];try{const s=r.type==="usual"?r.values:r.preparedValues.map(i=>({text:r.query.text,values:i}));for(const i of s){const g=e.getTime(),x=(()=>{try{return n.all(i.text,i.values)}catch(a){throw a instanceof Error&&(a.message=`Error while executing query: ${i.text} - ${a.message}`),a}})(),v=e.getTime();f.push({rows:x,performance:{execTime:v-g}})}}catch(s){if(t!=null&&t.rollbackOnFail)try{n.all("ROLLBACK",[])}catch(i){console.error("Failed to rollback",s,i)}throw s}finally{e.releaseTrJobIfPossible(u,b,t)}const w=e.getTime();return Promise.resolve({result:f,performance:{totalTime:w-c,blockTime:h}})};return{async initialize(){if(l)throw new Error("Failed to start DB cause it is stopped");n=await window.sqliteDb(p(y)),l&&n.close()},async execQueries(r,t){return d({type:"usual",values:r},t)},async execPreparedQuery(r,t,c){return d({type:"prepared",query:r,preparedValues:t},c)},stop(){return l=!0,n&&n.close(),Promise.resolve()}}};o.electronBetterSqlite3Backend=m,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
(function(r,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("@kikko-land/kikko")):typeof define=="function"&&define.amd?define(["exports","@kikko-land/kikko"],e):(r=typeof globalThis<"u"?globalThis:r||self,e(r.core={},r.kikko))})(this,function(r,e){"use strict";const u=d=>({dbName:f})=>{const m=e.initJobsState();let a=!0,t;const p=e.buildSyncQueryRunner({execPrepared(i,c){if(!t)throw new Error("Failed to run queries, db not initialized");const n=[];for(const o of c){const l=e.getTime(),w=(()=>{try{return t.all(i.text,o)}catch(s){throw s instanceof Error&&(s.message=`Error while executing query: ${i.text} - ${s.message}`),s}})(),b=e.getTime();n.push({rows:w,performance:{execTime:b-l}})}return n},execUsual(i){if(!t)throw new Error("Failed to run queries, db not initialized");return{rows:t.all(i.text,i.values),performance:{}}},rollback(){if(!t)throw new Error("Failed to run queries, db not initialized");t.all("ROLLBACK",[])}});return{async initialize(){if(a)throw new Error("Failed to start DB cause it is stopped");t=await window.sqliteDb(d(f)),a&&t.close()},async execQueries(i,c){const n=e.getTime(),o=await p.run(m,i,c),l=e.getTime();return{...o,performance:{...o.performance,totalTime:l-n}}},stop(){return a=!0,t&&t.close(),Promise.resolve()}}};r.electronBetterSqlite3Backend=u,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
//# sourceMappingURL=index.umd.js.map
{
"name": "@kikko-land/electron-better-sqlite3-backend",
"version": "0.8.4",
"version": "0.9.0",
"author": "Sergey Popov",

@@ -61,5 +61,5 @@ "license": "MIT",

"dependencies": {
"@kikko-land/kikko": "^0.15.0",
"@kikko-land/kikko": "^0.16.0",
"@kikko-land/boono-sql": "^0.3.0",
"@kikko-land/d1-backend": "^0.3.4",
"@kikko-land/d1-backend": "^0.4.0",
"@kikko-land/sql.js": "^1.6.8",

@@ -66,0 +66,0 @@ "better-sqlite3": ">=7.6.2"

import {
acquireWithTrJobOrWait,
buildSyncQueryRunner,
getTime,
IDbBackend,
IExecQueriesResult,
initJobsState,

@@ -10,4 +9,4 @@ IPrimitiveValue,

IQueryResult,
IRunRes,
ITransactionOpts,
releaseTrJobIfPossible,
} from "@kikko-land/kikko";

@@ -39,35 +38,10 @@

const runQueries = async (
queries:
| { type: "usual"; values: IQuery[] }
| {
type: "prepared";
query: IQuery;
preparedValues: IPrimitiveValue[][];
},
trOpts?: ITransactionOpts
) => {
if (!db) {
throw new Error(`Failed to run queries, db not initialized`);
}
const totalStartedAt = getTime();
const queryRunner = buildSyncQueryRunner({
execPrepared(query: IQuery, preparedValues: IPrimitiveValue[][]) {
if (!db) {
throw new Error(`Failed to run queries, db not initialized`);
}
const startBlockAt = getTime();
const job = await acquireWithTrJobOrWait(jobsState, trOpts);
const endBlockAt = getTime();
const blockTime = endBlockAt - startBlockAt;
const result: IExecQueriesResult["result"] = [];
try {
const queriesToRun =
queries.type === "usual"
? queries.values
: queries.preparedValues.map(
(v): IQuery => ({
text: queries.query.text,
values: v,
})
);
for (const q of queriesToRun) {
const result: IRunRes[] = [];
for (const v of preparedValues) {
const startTime = getTime();

@@ -77,6 +51,6 @@

try {
return db.all(q.text, q.values) as IQueryResult;
return db.all(query.text, v) as IQueryResult;
} catch (e) {
if (e instanceof Error) {
e.message = `Error while executing query: ${q.text} - ${e.message}`;
e.message = `Error while executing query: ${query.text} - ${e.message}`;
}

@@ -96,27 +70,26 @@ throw e;

}
} catch (e) {
if (trOpts?.rollbackOnFail) {
try {
db.all("ROLLBACK", []);
} catch (rollbackError) {
console.error(`Failed to rollback`, e, rollbackError);
}
return result;
},
execUsual(queriesToRun: IQuery): IRunRes {
if (!db) {
throw new Error(`Failed to run queries, db not initialized`);
}
throw e;
} finally {
releaseTrJobIfPossible(jobsState, job, trOpts);
}
return {
rows: db.all(
queriesToRun.text,
queriesToRun.values
) as IRunRes["rows"],
performance: {},
};
},
rollback() {
if (!db) {
throw new Error(`Failed to run queries, db not initialized`);
}
db.all("ROLLBACK", []);
},
});
const totalFinishedAt = getTime();
return Promise.resolve({
result,
performance: {
totalTime: totalFinishedAt - totalStartedAt,
blockTime,
},
});
};
return {

@@ -133,14 +106,23 @@ async initialize() {

},
async execQueries(queries: IQuery[], transactionOpts?: ITransactionOpts) {
return runQueries({ type: "usual", values: queries }, transactionOpts);
},
async execPreparedQuery(
query: IQuery,
preparedValues: IPrimitiveValue[][],
async execQueries(
q:
| { type: "usual"; values: IQuery[] }
| {
type: "prepared";
query: IQuery;
preparedValues: IPrimitiveValue[][];
},
transactionOpts?: ITransactionOpts
): Promise<IExecQueriesResult> {
return runQueries(
{ type: "prepared", query, preparedValues },
transactionOpts
);
) {
const startedAt = getTime();
const res = await queryRunner.run(jobsState, q, transactionOpts);
const endAt = getTime();
return {
...res,
performance: {
...res.performance,
totalTime: endAt - startedAt,
},
};
},

@@ -147,0 +129,0 @@ stop() {

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