Comparing version 0.3.13 to 0.3.14
36
index.js
@@ -124,14 +124,28 @@ "use strict"; | ||
return (...bindParameters) => { | ||
// TODO: Use libsql transaction API. | ||
this.exec("BEGIN"); | ||
try { | ||
const result = fn(...bindParameters); | ||
this.exec("COMMIT"); | ||
return result; | ||
} catch (err) { | ||
this.exec("ROLLBACK"); | ||
throw err; | ||
} | ||
const db = this; | ||
const wrapTxn = (mode) => { | ||
return (...bindParameters) => { | ||
db.exec("BEGIN " + mode); | ||
try { | ||
const result = fn(...bindParameters); | ||
db.exec("COMMIT"); | ||
return result; | ||
} catch (err) { | ||
db.exec("ROLLBACK"); | ||
throw err; | ||
} | ||
}; | ||
}; | ||
const properties = { | ||
default: { value: wrapTxn("") }, | ||
deferred: { value: wrapTxn("DEFERRED") }, | ||
immediate: { value: wrapTxn("IMMEDIATE") }, | ||
exclusive: { value: wrapTxn("EXCLUSIVE") }, | ||
database: { value: this, enumerable: true }, | ||
}; | ||
Object.defineProperties(properties.default.value, properties); | ||
Object.defineProperties(properties.deferred.value, properties); | ||
Object.defineProperties(properties.immediate.value, properties); | ||
Object.defineProperties(properties.exclusive.value, properties); | ||
return properties.default.value; | ||
} | ||
@@ -138,0 +152,0 @@ |
{ | ||
"name": "libsql", | ||
"version": "0.3.13", | ||
"version": "0.3.14", | ||
"description": "A better-sqlite3 compatible API for libSQL that supports Bun, Deno, and Node", | ||
@@ -73,10 +73,10 @@ "os": [ | ||
"optionalDependencies": { | ||
"@libsql/darwin-arm64": "0.3.13", | ||
"@libsql/darwin-x64": "0.3.13", | ||
"@libsql/linux-arm64-gnu": "0.3.13", | ||
"@libsql/linux-arm64-musl": "0.3.13", | ||
"@libsql/linux-x64-gnu": "0.3.13", | ||
"@libsql/linux-x64-musl": "0.3.13", | ||
"@libsql/win32-x64-msvc": "0.3.13" | ||
"@libsql/darwin-arm64": "0.3.14", | ||
"@libsql/darwin-x64": "0.3.14", | ||
"@libsql/linux-arm64-gnu": "0.3.14", | ||
"@libsql/linux-arm64-musl": "0.3.14", | ||
"@libsql/linux-x64-gnu": "0.3.14", | ||
"@libsql/linux-x64-musl": "0.3.14", | ||
"@libsql/win32-x64-msvc": "0.3.14" | ||
} | ||
} |
@@ -127,14 +127,28 @@ "use strict"; | ||
return async (...bindParameters) => { | ||
// TODO: Use libsql transaction API. | ||
await this.exec("BEGIN"); | ||
try { | ||
const result = fn(...bindParameters); | ||
await this.exec("COMMIT"); | ||
return result; | ||
} catch (err) { | ||
await this.exec("ROLLBACK"); | ||
throw err; | ||
} | ||
const db = this; | ||
const wrapTxn = (mode) => { | ||
return async (...bindParameters) => { | ||
await db.exec("BEGIN " + mode); | ||
try { | ||
const result = fn(...bindParameters); | ||
await db.exec("COMMIT"); | ||
return result; | ||
} catch (err) { | ||
await db.exec("ROLLBACK"); | ||
throw err; | ||
} | ||
}; | ||
}; | ||
const properties = { | ||
default: { value: wrapTxn("") }, | ||
deferred: { value: wrapTxn("DEFERRED") }, | ||
immediate: { value: wrapTxn("IMMEDIATE") }, | ||
exclusive: { value: wrapTxn("EXCLUSIVE") }, | ||
database: { value: this, enumerable: true }, | ||
}; | ||
Object.defineProperties(properties.default.value, properties); | ||
Object.defineProperties(properties.deferred.value, properties); | ||
Object.defineProperties(properties.immediate.value, properties); | ||
Object.defineProperties(properties.exclusive.value, properties); | ||
return properties.default.value; | ||
} | ||
@@ -141,0 +155,0 @@ |
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
36194
816