@minatojs/driver-sqlite
Advanced tools
Comparing version 3.8.0 to 3.8.1
@@ -23,2 +23,3 @@ import { Database, Driver, Eval, Selection } from '@minatojs/core'; | ||
beforeUnload?: () => void; | ||
private _transactionTask?; | ||
constructor(database: Database, config: SQLiteDriver.Config); | ||
@@ -32,4 +33,6 @@ /** synchronize table schema */ | ||
remove(sel: Selection.Mutable): Promise<{ | ||
matched?: undefined; | ||
removed?: undefined; | ||
} | { | ||
matched: any; | ||
removed: any; | ||
@@ -45,3 +48,4 @@ }>; | ||
upsert(sel: Selection.Mutable, data: any[], keys: string[]): Promise<{}>; | ||
withTransaction(callback: (session: Driver) => Promise<void>): Promise<void>; | ||
} | ||
export default SQLiteDriver; |
@@ -182,2 +182,3 @@ "use strict"; | ||
__publicField(this, "beforeUnload"); | ||
__publicField(this, "_transactionTask"); | ||
this.sql = new SQLiteBuilder(); | ||
@@ -333,3 +334,3 @@ } | ||
const result = __privateMethod(this, _run, run_fn).call(this, `DELETE FROM ${(0, import_sql_utils.escapeId)(table)} WHERE ${filter}`, [], () => __privateMethod(this, _get, get_fn).call(this, `SELECT changes() AS count`)); | ||
return { removed: result.count }; | ||
return { matched: result.count, removed: result.count }; | ||
} | ||
@@ -405,2 +406,10 @@ async get(sel) { | ||
} | ||
async withTransaction(callback) { | ||
if (this._transactionTask) | ||
await this._transactionTask; | ||
return this._transactionTask = new Promise((resolve, reject) => { | ||
__privateMethod(this, _run, run_fn).call(this, "BEGIN TRANSACTION"); | ||
callback(this).then(() => resolve(__privateMethod(this, _run, run_fn).call(this, "COMMIT")), (e) => (__privateMethod(this, _run, run_fn).call(this, "ROLLBACK"), reject(e))); | ||
}); | ||
} | ||
}; | ||
@@ -407,0 +416,0 @@ _joinKeys = new WeakSet(); |
{ | ||
"name": "@minatojs/driver-sqlite", | ||
"version": "3.8.0", | ||
"version": "3.8.1", | ||
"description": "SQLite Driver for Minato", | ||
@@ -29,6 +29,6 @@ "main": "lib/index.js", | ||
"peerDependencies": { | ||
"@minatojs/core": "^2.6.0" | ||
"@minatojs/core": "^2.7.0" | ||
}, | ||
"devDependencies": { | ||
"@minatojs/tests": "^1.8.0" | ||
"@minatojs/tests": "^1.8.1" | ||
}, | ||
@@ -35,0 +35,0 @@ "dependencies": { |
@@ -141,2 +141,4 @@ import { clone, deepEqual, Dict, difference, isNullable, makeArray } from 'cosmokit' | ||
private _transactionTask? | ||
constructor(database: Database, public config: SQLiteDriver.Config) { | ||
@@ -348,3 +350,3 @@ super(database) | ||
const result = this.#run(`DELETE FROM ${escapeId(table)} WHERE ${filter}`, [], () => this.#get(`SELECT changes() AS count`)) | ||
return { removed: result.count } | ||
return { matched: result.count, removed: result.count } | ||
} | ||
@@ -443,4 +445,12 @@ | ||
} | ||
async withTransaction(callback: (session: Driver) => Promise<void>) { | ||
if (this._transactionTask) await this._transactionTask | ||
return this._transactionTask = new Promise<void>((resolve, reject) => { | ||
this.#run('BEGIN TRANSACTION') | ||
callback(this).then(() => resolve(this.#run('COMMIT')), (e) => (this.#run('ROLLBACK'), reject(e))) | ||
}) | ||
} | ||
} | ||
export default SQLiteDriver |
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
51179
935