@minatojs/driver-sqlite
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -0,4 +1,5 @@ | ||
/// <reference types="node" /> | ||
import { Database, Driver, Eval, Executable, Modifier } from '@minatojs/core'; | ||
import { Builder, Caster } from '@minatojs/sql-utils'; | ||
import init from '@minatojs/sql.js'; | ||
import init from 'sql.js'; | ||
export interface SQLiteFieldInfo { | ||
@@ -22,2 +23,4 @@ name: string; | ||
caster: Caster; | ||
writeTask: NodeJS.Timeout; | ||
sqlite: init.SqlJsStatic; | ||
constructor(database: Database, config: SQLiteDriver.Config); | ||
@@ -27,2 +30,3 @@ private _getColDefs; | ||
prepare(table: string): Promise<void>; | ||
init(buffer: ArrayLike<number>): void; | ||
start(): Promise<void>; | ||
@@ -32,3 +36,3 @@ stop(): Promise<void>; | ||
stats(): Promise<{ | ||
size: any; | ||
size: number; | ||
}>; | ||
@@ -35,0 +39,0 @@ remove(sel: Executable): Promise<void>; |
@@ -48,4 +48,5 @@ var __create = Object.create; | ||
var import_sql_utils = require("@minatojs/sql-utils"); | ||
var import_sql = __toESM(require("@minatojs/sql.js")); | ||
var import_sqlstring_sqlite = require("sqlstring-sqlite"); | ||
var import_fs = require("fs"); | ||
var import_sql = __toESM(require("sql.js")); | ||
var import_reggol = __toESM(require("reggol")); | ||
@@ -174,7 +175,14 @@ var logger = new import_reggol.default("sqlite"); | ||
} | ||
async start() { | ||
const sqlite = await (0, import_sql.default)(); | ||
this.db = new sqlite.Database(this.config.path); | ||
init(buffer) { | ||
this.db = new this.sqlite.Database(buffer); | ||
this.db.create_function("regexp", (pattern, str) => +new RegExp(pattern).test(str)); | ||
} | ||
async start() { | ||
const [sqlite, buffer] = await Promise.all([ | ||
(0, import_sql.default)(), | ||
this.config.path === ":memory:" ? null : import_fs.promises.readFile(this.config.path).catch(() => null) | ||
]); | ||
this.sqlite = sqlite; | ||
this.init(buffer); | ||
} | ||
async stop() { | ||
@@ -238,7 +246,7 @@ this.db.close(); | ||
data = model.create(data); | ||
__privateMethod(this, _create, create_fn).call(this, table, data); | ||
const { id } = __privateMethod(this, _create, create_fn).call(this, table, data); | ||
const { autoInc, primary } = model; | ||
if (!autoInc) | ||
if (!autoInc || Array.isArray(primary)) | ||
return data; | ||
return { ...data, ...__privateMethod(this, _get, get_fn).call(this, `select last_insert_rowid() as ${(0, import_sqlstring_sqlite.escapeId)(primary)}`) }; | ||
return { ...data, [primary]: id }; | ||
} | ||
@@ -300,4 +308,15 @@ async upsert(sel, data, keys) { | ||
_run = new WeakSet(); | ||
run_fn = /* @__PURE__ */ __name(function(sql, params = []) { | ||
return __privateMethod(this, _exec, exec_fn).call(this, sql, params, (stmt) => stmt.run(params)); | ||
run_fn = /* @__PURE__ */ __name(function(sql, params = [], callback) { | ||
__privateMethod(this, _exec, exec_fn).call(this, sql, params, (stmt) => stmt.run(params)); | ||
const result = callback == null ? void 0 : callback(); | ||
if (this.config.path) { | ||
const data = this.db.export(); | ||
const timer = this.writeTask = setTimeout(() => { | ||
if (this.writeTask !== timer) | ||
return; | ||
import_fs.promises.writeFile(this.config.path, data); | ||
}, 0); | ||
this.init(data); | ||
} | ||
return result; | ||
}, "#run"); | ||
@@ -318,3 +337,3 @@ _update = new WeakSet(); | ||
const sql = `INSERT INTO ${this.sql.escapeId(table)} (${__privateMethod(this, _joinKeys, joinKeys_fn).call(this, keys)}) VALUES (${keys.map((key) => this.sql.escape(data[key])).join(", ")})`; | ||
return __privateMethod(this, _run, run_fn).call(this, sql); | ||
return __privateMethod(this, _run, run_fn).call(this, sql, [], () => __privateMethod(this, _get, get_fn).call(this, `select last_insert_rowid() as id`)); | ||
}, "#create"); | ||
@@ -321,0 +340,0 @@ var src_default = SQLiteDriver; |
{ | ||
"name": "@minatojs/driver-sqlite", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "SQLite Driver for Minato", | ||
@@ -31,7 +31,8 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@minatojs/tests": "^1.3.0" | ||
"@minatojs/tests": "^1.3.0", | ||
"@types/sql.js": "^1.4.4" | ||
}, | ||
"dependencies": { | ||
"@minatojs/sql-utils": "^1.1.0", | ||
"@minatojs/sql.js": "^1.1.1", | ||
"sql.js": "^1.8.0", | ||
"sqlstring-sqlite": "^0.1.1", | ||
@@ -38,0 +39,0 @@ "cosmokit": "^1.3.3", |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
34746
380
0
2
1
+ Addedsql.js@^1.8.0
+ Addedsql.js@1.12.0(transitive)
- Removed@minatojs/sql.js@^1.1.1
- Removed@minatojs/sql.js@1.1.3(transitive)