Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

rg-sqlite-helper

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rg-sqlite-helper - npm Package Compare versions

Comparing version
1.0.49
to
1.0.50
+56
-44
dist/index.cjs

@@ -578,4 +578,5 @@ "use strict";

getConnection() {
if (!this._connection)
if (!this._connection) {
throw new Error("Sql connection closed.");
}
return this._connection;

@@ -613,21 +614,32 @@ }

const res = await this.getFirst(`PRAGMA ${pragmaName}`);
if (res === void 0)
if (res === void 0) {
throw new Error(`unknown pragma ${pragmaName}`);
}
return res[pragmaName] === 1;
}
static async openConnection(databasePath, options = Object(), onFatalError) {
const clazz = new this();
if (!databasePath)
throw new Error("database path not set");
const that = new this();
const driver = getSqliteDriver();
clazz.sqlite3Driver = driver;
if (!HelperFunctions.doesFileExistSync(databasePath)) {
console.warn(`****--file not exists ${import_path.default.resolve(databasePath)}--****`);
that.sqlite3Driver = driver;
if (databasePath != ":memory:") {
if (!databasePath) {
throw new Error("database path not set");
} else {
if (!HelperFunctions.doesFileExistSync(databasePath)) {
if (options.throwIfDatabaseNotFound == true) {
throw new Error(`database file not found at ${import_path.default.resolve(databasePath)}`);
}
console.warn(`****--file not exists ${import_path.default.resolve(databasePath)}--****`);
}
}
}
clazz.onFatalError = onFatalError;
clazz._connection = await SqlWarpper.open({ filename: databasePath, driver: driver.Database });
if (databasePath == ":memory:") {
console.log("using memory db");
}
that.onFatalError = onFatalError;
that._connection = await SqlWarpper.open({ filename: databasePath, driver: driver.Database });
if (Array.isArray(options.executeOnConnection)) {
for (let sql2 of options.executeOnConnection) {
try {
await clazz._connection.exec(sql2);
await that._connection.exec(sql2);
} catch (e2) {

@@ -639,14 +651,14 @@ console.error("Error running on Execute query", (e2 == null ? void 0 : e2.stack) || (e2 == null ? void 0 : e2.toString()));

if (options.disableForeignKeys === true) {
await clazz.setPRAGMA("FOREIGN_KEYS", false);
await that.setPRAGMA("FOREIGN_KEYS", false);
} else {
await clazz.setPRAGMA("FOREIGN_KEYS", true);
await that.setPRAGMA("FOREIGN_KEYS", true);
}
clazz._connection.db.addListener(
that._connection.db.addListener(
"change",
(eventType, database, table, rowId) => {
var _a;
(_a = clazz.databasesListeners.get(table)) == null ? void 0 : _a({ eventType, table, rowId });
(_a = that.databasesListeners.get(table)) == null ? void 0 : _a({ eventType, table, rowId });
}
);
return clazz;
return that;
}

@@ -1223,4 +1235,4 @@ async backup(dest, retires = 20) {

var SqlManager = class {
writeConnection;
readConnection;
_writeConnection;
_readConnection;
databasePath;

@@ -1336,11 +1348,11 @@ openOptions = {};

async loadExtension(path3) {
const write = await this.getWriteConnection();
await write.getSqlite3Object().loadExtension(path3);
const read = await this.getReadConnection();
await read.getSqlite3Object().loadExtension(path3);
const writeConn = await this.getWriteConnection();
await writeConn.getSqlite3Object().loadExtension(path3);
const readConn = await this.getReadConnection();
await readConn.getSqlite3Object().loadExtension(path3);
this.loadedExtensions.add(path3);
}
async getReadConnection() {
if (this.readConnection) {
return this.readConnection;
if (this._readConnection) {
return this._readConnection;
}

@@ -1350,6 +1362,6 @@ return this.openMutex.runExclusive(

var _a;
if (this.readConnection) {
return this.readConnection;
if (this._readConnection) {
return this._readConnection;
}
this.readConnection = await SqlConnection.openConnection(
this._readConnection = await SqlConnection.openConnection(
this.databasePath,

@@ -1365,5 +1377,5 @@ {

for (let ext of this.loadedExtensions) {
await this.readConnection.getSqlite3Object().loadExtension(ext);
await this._readConnection.getSqlite3Object().loadExtension(ext);
}
return this.readConnection;
return this._readConnection;
}

@@ -1373,11 +1385,11 @@ );

async getWriteConnection() {
if (this.writeConnection) {
return this.writeConnection;
if (this._writeConnection) {
return this._writeConnection;
}
return this.openMutex.runExclusive(
async () => {
if (this.writeConnection) {
return this.writeConnection;
if (this._writeConnection) {
return this._writeConnection;
}
this.writeConnection = await SqlConnection.openConnection(
this._writeConnection = await SqlConnection.openConnection(
this.databasePath,

@@ -1391,9 +1403,9 @@ this.openOptions,

for (let ext of this.loadedExtensions) {
await this.writeConnection.getSqlite3Object().loadExtension(ext);
await this._writeConnection.getSqlite3Object().loadExtension(ext);
}
for (let listener of this.databasesListeners) {
console.log("restoring listeners", listener);
this.writeConnection.addTableListener(...listener);
this._writeConnection.addTableListener(...listener);
}
return this.writeConnection;
return this._writeConnection;
}

@@ -1412,10 +1424,10 @@ );

}
destroy() {
async destroy() {
var _a, _b;
(_a = this.writeConnection) == null ? void 0 : _a.destroy().catch(() => {
});
(_b = this.readConnection) == null ? void 0 : _b.destroy().catch(() => {
});
this.writeConnection = void 0;
this.readConnection = void 0;
await ((_a = this._writeConnection) == null ? void 0 : _a.destroy().catch(() => {
}));
await ((_b = this._readConnection) == null ? void 0 : _b.destroy().catch(() => {
}));
this._writeConnection = void 0;
this._readConnection = void 0;
}

@@ -1422,0 +1434,0 @@ async listAllTables() {

import * as SqlWarpper from 'sqlite';
import { Database } from 'sqlite';
import * as events from 'events';
import { sqlite3 as sqlite3$1 } from '@rg-dev/sqlite3';

@@ -38,2 +39,3 @@ type Query = {

disableForeignKeys?: boolean;
throwIfDatabaseNotFound?: boolean;
};

@@ -145,6 +147,6 @@ interface backupFunction {

declare function createKyselyDriver(sqlManager: SqlManager): any;
declare function getSqliteDriver(): any;
declare function getSqliteDriver(): sqlite3$1;
declare class SqlManager implements SqlConnectionInterface {
private writeConnection?;
private readConnection?;
private _writeConnection?;
private _readConnection?;
private readonly databasePath;

@@ -161,3 +163,3 @@ private readonly openOptions;

detectForeignKeyIssue(tableName: string, recordIdentifier: Record<string, any>): Promise<ForeignKeyIssueDetails>;
run(sql: string | Query, ...args: ArgsInput): Promise<SqlWarpper.ISqlite.RunResult<sqlite3.Statement>>;
run(sql: string | Query, ...args: ArgsInput): Promise<SqlWarpper.ISqlite.RunResult<sqlite3$1.Statement>>;
execMigrationQuery(sql: string): Promise<void>;

@@ -169,3 +171,3 @@ loadExtension(path: string): Promise<void>;

removeTableListener(...params: Parameters<SqlConnection["removeTableListener"]>): Promise<void>;
destroy(): void;
destroy(): Promise<void>;
listAllTables(): Promise<{

@@ -172,0 +174,0 @@ name: string;

{
"name": "rg-sqlite-helper",
"version": "1.0.49",
"version": "1.0.50",
"description": "",

@@ -5,0 +5,0 @@ "scripts": {