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

@libsql/client

Package Overview
Dependencies
Maintainers
1
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@libsql/client - npm Package Compare versions

Comparing version 0.3.5 to 0.3.6-pre.1

49

lib-cjs/sqlite3.js

@@ -60,6 +60,8 @@ "use strict";

executeStmt(db, "SELECT 1 AS checkThatTheDatabaseCanBeOpened", config.intMode);
return new Sqlite3Client(db, config.intMode);
return new Sqlite3Client(path, options, db, config.intMode);
}
exports._createClient = _createClient;
class Sqlite3Client {
#path;
#options;
#db;

@@ -70,3 +72,5 @@ #intMode;

/** @private */
constructor(db, intMode) {
constructor(path, options, db, intMode) {
this.#path = path;
this.#options = options;
this.#db = db;

@@ -79,20 +83,21 @@ this.#intMode = intMode;

this.#checkNotClosed();
return executeStmt(this.#db, stmt, this.#intMode);
return executeStmt(this.#getDb(), stmt, this.#intMode);
}
async batch(stmts, mode = "deferred") {
this.#checkNotClosed();
const db = this.#getDb();
try {
executeStmt(this.#db, (0, util_js_1.transactionModeToBegin)(mode), this.#intMode);
executeStmt(db, (0, util_js_1.transactionModeToBegin)(mode), this.#intMode);
const resultSets = stmts.map((stmt) => {
if (!this.#db.inTransaction) {
if (!db.inTransaction) {
throw new api_js_1.LibsqlError("The transaction has been rolled back", "TRANSACTION_CLOSED");
}
return executeStmt(this.#db, stmt, this.#intMode);
return executeStmt(db, stmt, this.#intMode);
});
executeStmt(this.#db, "COMMIT", this.#intMode);
executeStmt(db, "COMMIT", this.#intMode);
return resultSets;
}
finally {
if (this.#db.inTransaction) {
executeStmt(this.#db, "ROLLBACK", this.#intMode);
if (db.inTransaction) {
executeStmt(db, "ROLLBACK", this.#intMode);
}

@@ -102,13 +107,16 @@ }

async transaction(mode = "write") {
executeStmt(this.#db, (0, util_js_1.transactionModeToBegin)(mode), this.#intMode);
return new Sqlite3Transaction(this.#db, this.#intMode);
const db = this.#getDb();
executeStmt(db, (0, util_js_1.transactionModeToBegin)(mode), this.#intMode);
this.#db = null; // A new connection will be lazily created on next use
return new Sqlite3Transaction(db, this.#intMode);
}
async executeMultiple(sql) {
this.#checkNotClosed();
const db = this.#getDb();
try {
return executeMultiple(this.#db, sql);
return executeMultiple(db, sql);
}
finally {
if (this.#db.inTransaction) {
executeStmt(this.#db, "ROLLBACK", this.#intMode);
if (db.inTransaction) {
executeStmt(db, "ROLLBACK", this.#intMode);
}

@@ -119,7 +127,9 @@ }

this.#checkNotClosed();
await this.#db.sync();
await this.#getDb().sync();
}
close() {
this.closed = true;
this.#db.close();
if (this.#db !== null) {
this.#db.close();
}
}

@@ -131,2 +141,9 @@ #checkNotClosed() {

}
// Lazily creates the database connection and returns it
#getDb() {
if (this.#db === null) {
this.#db = new libsql_1.default(this.#path, this.#options);
}
return this.#db;
}
}

@@ -133,0 +150,0 @@ exports.Sqlite3Client = Sqlite3Client;

@@ -13,3 +13,3 @@ import Database from "libsql";

/** @private */
constructor(db: Database.Database, intMode: IntMode);
constructor(path: string, options: Database.Options, db: Database.Database, intMode: IntMode);
execute(stmt: InStatement): Promise<ResultSet>;

@@ -16,0 +16,0 @@ batch(stmts: Array<InStatement>, mode?: TransactionMode): Promise<Array<ResultSet>>;

@@ -39,5 +39,7 @@ import Database from "libsql";

executeStmt(db, "SELECT 1 AS checkThatTheDatabaseCanBeOpened", config.intMode);
return new Sqlite3Client(db, config.intMode);
return new Sqlite3Client(path, options, db, config.intMode);
}
export class Sqlite3Client {
#path;
#options;
#db;

@@ -48,3 +50,5 @@ #intMode;

/** @private */
constructor(db, intMode) {
constructor(path, options, db, intMode) {
this.#path = path;
this.#options = options;
this.#db = db;

@@ -57,20 +61,21 @@ this.#intMode = intMode;

this.#checkNotClosed();
return executeStmt(this.#db, stmt, this.#intMode);
return executeStmt(this.#getDb(), stmt, this.#intMode);
}
async batch(stmts, mode = "deferred") {
this.#checkNotClosed();
const db = this.#getDb();
try {
executeStmt(this.#db, transactionModeToBegin(mode), this.#intMode);
executeStmt(db, transactionModeToBegin(mode), this.#intMode);
const resultSets = stmts.map((stmt) => {
if (!this.#db.inTransaction) {
if (!db.inTransaction) {
throw new LibsqlError("The transaction has been rolled back", "TRANSACTION_CLOSED");
}
return executeStmt(this.#db, stmt, this.#intMode);
return executeStmt(db, stmt, this.#intMode);
});
executeStmt(this.#db, "COMMIT", this.#intMode);
executeStmt(db, "COMMIT", this.#intMode);
return resultSets;
}
finally {
if (this.#db.inTransaction) {
executeStmt(this.#db, "ROLLBACK", this.#intMode);
if (db.inTransaction) {
executeStmt(db, "ROLLBACK", this.#intMode);
}

@@ -80,13 +85,16 @@ }

async transaction(mode = "write") {
executeStmt(this.#db, transactionModeToBegin(mode), this.#intMode);
return new Sqlite3Transaction(this.#db, this.#intMode);
const db = this.#getDb();
executeStmt(db, transactionModeToBegin(mode), this.#intMode);
this.#db = null; // A new connection will be lazily created on next use
return new Sqlite3Transaction(db, this.#intMode);
}
async executeMultiple(sql) {
this.#checkNotClosed();
const db = this.#getDb();
try {
return executeMultiple(this.#db, sql);
return executeMultiple(db, sql);
}
finally {
if (this.#db.inTransaction) {
executeStmt(this.#db, "ROLLBACK", this.#intMode);
if (db.inTransaction) {
executeStmt(db, "ROLLBACK", this.#intMode);
}

@@ -97,7 +105,9 @@ }

this.#checkNotClosed();
await this.#db.sync();
await this.#getDb().sync();
}
close() {
this.closed = true;
this.#db.close();
if (this.#db !== null) {
this.#db.close();
}
}

@@ -109,2 +119,9 @@ #checkNotClosed() {

}
// Lazily creates the database connection and returns it
#getDb() {
if (this.#db === null) {
this.#db = new Database(this.#path, this.#options);
}
return this.#db;
}
}

@@ -111,0 +128,0 @@ export class Sqlite3Transaction {

{
"name": "@libsql/client",
"version": "0.3.5",
"version": "0.3.6-pre.1",
"keywords": [

@@ -103,3 +103,3 @@ "libsql",

"js-base64": "^3.7.5",
"libsql": "^0.1.22"
"libsql": "^0.1.24"
},

@@ -106,0 +106,0 @@ "devDependencies": {

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