Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v22.5.1
v22.20.0
4 changes: 2 additions & 2 deletions benchmarks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@sqlite-js/api": "workspace:^"
},
"devDependencies": {
"@types/node": "^20.14.2",
"typescript": "^5.4.5"
"@types/node": "^24.9.1",
"typescript": "^5.9.3"
}
}
5 changes: 2 additions & 3 deletions benchmarks/src/implementations/better-sqlite3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import DatabaseConstructor from 'better-sqlite3';
import { promises as fs } from 'fs';
import assert from 'node:assert';
import { join } from 'path';
import Prando from 'prando';
import { Benchmark } from '../Benchmark.js';
import { numberName } from '../util.js';
import { numberName, createRandom } from '../util.js';

export class BetterSqlite3Impl extends Benchmark {
private db!: bsqlite.Database;
private dir: string;
private random = new Prando.default(0);
private random = createRandom(0);

constructor(
public name: string,
Expand Down
5 changes: 2 additions & 3 deletions benchmarks/src/implementations/node-sqlite.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { promises as fs } from 'fs';
import assert from 'node:assert';
import { join } from 'path';
import Prando from 'prando';
import { Benchmark } from '../Benchmark.js';
import { numberName } from '../util.js';
import { numberName, createRandom } from '../util.js';

//@ts-ignore
import * as sqlite from 'node:sqlite';

export class NodeSqliteImpl extends Benchmark {
private db!: sqlite.DatabaseSync;
private dir: string;
private random = new Prando.default(0);
private random = createRandom(0);

constructor(
public name: string,
Expand Down
5 changes: 2 additions & 3 deletions benchmarks/src/implementations/node-sqlite3.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { Benchmark } from '../Benchmark.js';
import { join } from 'path';
import { promises as fs } from 'fs';
import Prando from 'prando';
import assert from 'node:assert';
import { numberName } from '../util.js';
import { numberName, createRandom } from '../util.js';
import sqlite3 from 'sqlite3';
import { open, Database } from 'sqlite';

export class NodeSqlite3Impl extends Benchmark {
private db!: Database;
private dir: string;
private random = new Prando.default(0);
private random = createRandom(0);

constructor(
public name: string,
Expand Down
5 changes: 2 additions & 3 deletions benchmarks/src/implementations/sjp-json.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { promises as fs } from 'fs';
import assert from 'node:assert';
import { join } from 'path';
import Prando from 'prando';
import { SqliteConnectionPool } from '@sqlite-js/api';
import { Benchmark } from '../Benchmark.js';
import { numberName } from '../util.js';
import { numberName, createRandom } from '../util.js';

export class JSPJsonImpl extends Benchmark {
private db!: SqliteConnectionPool;
private dir: string;
private random = new Prando.default(0);
private random = createRandom(0);

constructor(
public name: string,
Expand Down
5 changes: 2 additions & 3 deletions benchmarks/src/implementations/sjp-optimized.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { promises as fs } from 'fs';
import assert from 'node:assert';
import { join } from 'path';
import Prando from 'prando';
import { SqliteConnectionPool } from '@sqlite-js/api';
import { Benchmark } from '../Benchmark.js';
import { numberName } from '../util.js';
import { numberName, createRandom } from '../util.js';

export class JSPOptimizedImpl extends Benchmark {
private db!: SqliteConnectionPool;
private dir: string;
private random = new Prando.default(0);
private random = createRandom(0);

constructor(
public name: string,
Expand Down
5 changes: 2 additions & 3 deletions benchmarks/src/implementations/sjp.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { promises as fs } from 'fs';
import assert from 'node:assert';
import { join } from 'path';
import Prando from 'prando';
import { SqliteConnectionPool } from '@sqlite-js/api';
import { Benchmark } from '../Benchmark.js';
import { numberName } from '../util.js';
import { numberName, createRandom } from '../util.js';

export class JSPImpl extends Benchmark {
private db!: SqliteConnectionPool;
private dir: string;
private random = new Prando.default(0);
private random = createRandom(0);

constructor(
public name: string,
Expand Down
24 changes: 24 additions & 0 deletions benchmarks/src/util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as Prando from 'prando';

const digits = [
'',
'one',
Expand Down Expand Up @@ -34,6 +36,28 @@ const names100 = [
...digits.map((digit) => `ninety${digit != '' ? '-' + digit : ''}`)
];

type PrandoInstance = import('prando').default;
type PrandoConstructor = new (seed?: number | string) => PrandoInstance;

function resolvePrandoConstructor(): PrandoConstructor {
const mod = Prando as unknown as {
default?: PrandoConstructor;
};
if (typeof (Prando as unknown) === 'function') {
return Prando as unknown as PrandoConstructor;
}
if (mod.default) {
return mod.default;
}
throw new Error('Unable to locate Prando constructor');
}

const PRANDO_CTOR = resolvePrandoConstructor();

export function createRandom(seed?: number | string): PrandoInstance {
return new PRANDO_CTOR(seed);
}

export function numberName(n: number): string {
if (n == 0) {
return 'zero';
Expand Down
5 changes: 4 additions & 1 deletion benchmarks/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
"target": "ES2022",
"strict": true,
"module": "NodeNext",
"moduleResolution": "NodeNext",
"outDir": "lib",
"sourceMap": true,
"declaration": true,
"rootDir": "src",
"typeRoots": ["./src/types", "./node_modules/@types"]
"typeRoots": ["./src/types", "./node_modules/@types"],
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
},
"include": ["src"],
"references": [{ "path": "../packages/api" }]
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
"devDependencies": {
"@types/better-sqlite3": "^7.6.9",
"@types/mocha": "^10.0.6",
"@types/node": "^20.14.2",
"@types/node": "^24.9.1",
"expect": "^29.7.0",
"mocha": "^10.4.0",
"prettier": "^3.2.5",
"ts-node": "^10.9.2",
"tsx": "^4.16.2",
"typescript": "^5.4.5",
"vitest": "^1.5.0"
"typescript": "^5.9.3",
"vitest": "^2.0.5"
},
"packageManager": "pnpm@9.6.0+sha512.38dc6fba8dba35b39340b9700112c2fe1e12f10b17134715a4aa98ccf7bb035e76fd981cf0bb384dfa98f8d6af5481c2bef2f4266a24bfa20c34eb7147ce0b5e"
}
10 changes: 7 additions & 3 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
"test": "vitest",
"clean": "tsc -b --clean && rm -rf lib"
},
"types": "./lib/index.d.ts",
"exports": {
".": "./lib/index.js"
".": {
"types": "./lib/index.d.ts",
"default": "./lib/index.js"
}
},
"keywords": [],
"author": "",
Expand All @@ -18,8 +22,8 @@
"@sqlite-js/driver": "workspace:^"
},
"devDependencies": {
"@types/node": "^22.3.0",
"typescript": "^5.5.4",
"@types/node": "^24.9.1",
"typescript": "^5.9.3",
"vitest": "^2.0.5",
"@sqlite-js/better-sqlite3-driver": "workspace:^",
"@sqlite-js/driver-tests": "workspace:^"
Expand Down
14 changes: 7 additions & 7 deletions packages/api/src/impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,12 @@ export class ConnectionImpl implements SqliteConnection {
}

async begin(options?: TransactionOptions): Promise<SqliteBeginTransaction> {
await this.init();
this.init();

if ((options?.type ?? 'exclusive') == 'exclusive') {
await this._beginExclusive!.select();
await this._beginExclusive!.run();
} else {
await this._begin!.select();
await this._begin!.run();
}

return new BeginTransactionImpl(this);
Expand All @@ -316,18 +316,18 @@ export class ConnectionImpl implements SqliteConnection {
this.init();

if ((options?.type ?? 'exclusive') == 'exclusive') {
await this._beginExclusive!.select();
await this._beginExclusive!.run();
} else {
await this._begin!.select();
await this._begin!.run();
}
try {
const tx = new TransactionImpl(this);
const result = await callback(tx);

await this.commit!.select();
await this.commit!.run();
return result;
} catch (e) {
await this.rollback!.select();
await this.rollback!.run();
throw e;
}
}
Expand Down
10 changes: 7 additions & 3 deletions packages/better-sqlite3-driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
"test": "pnpm build && vitest",
"clean": "tsc -b --clean && tsc -b ./test/tsconfig.json --clean && rm -rf lib test/lib"
},
"types": "./lib/index.d.ts",
"exports": {
".": "./lib/index.js"
".": {
"types": "./lib/index.d.ts",
"default": "./lib/index.js"
}
},
"keywords": [],
"author": "",
Expand All @@ -19,8 +23,8 @@
"@sqlite-js/driver": "workspace:^"
},
"devDependencies": {
"@types/node": "^22.3.0",
"typescript": "^5.5.4",
"@types/node": "^24.9.1",
"typescript": "^5.9.3",
"vitest": "^2.0.5",
"@sqlite-js/driver-tests": "workspace:^"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { describeDriverTests } from '@sqlite-js/driver-tests';
import { BetterSqliteDriver } from '../../lib/index.js';
import { deleteDb } from './util.js';

describeDriverTests(
'better-sqlite3-async-pool',
{ getColumns: true, rawResults: true, allowsMissingParameters: false },
(path) => BetterSqliteDriver.open(path)
async (path) => {
await deleteDb(path);
return BetterSqliteDriver.open(path);
}
);
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { BetterSqliteDriver } from '../../lib/index.js';
import { describeDriverTests } from '@sqlite-js/driver-tests';
import { deleteDb } from './util.js';

describeDriverTests(
'better-sqlite3',
{ getColumns: true, rawResults: true, allowsMissingParameters: false },
(path) => BetterSqliteDriver.openInProcess(path)
async (path) => {
await deleteDb(path);
return BetterSqliteDriver.openInProcess(path);
}
);
12 changes: 12 additions & 0 deletions packages/better-sqlite3-driver/test/src/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as fs from 'node:fs/promises';
import * as path from 'node:path';

export async function deleteDb(dbPath: string) {
const dir = path.dirname(dbPath);
try {
await fs.mkdir(dir);
} catch (e) {}
try {
await fs.rm(dbPath);
} catch (e) {}
}
4 changes: 2 additions & 2 deletions packages/driver-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@sqlite-js/driver": "workspace:^"
},
"devDependencies": {
"@types/node": "^22.3.0",
"typescript": "^5.5.4"
"@types/node": "^24.9.1",
"typescript": "^5.9.3"
}
}
24 changes: 10 additions & 14 deletions packages/driver-tests/src/driver-tests.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import * as fs from 'node:fs/promises';
import * as path from 'node:path';
import { beforeEach, describe, test } from './test.js';
import { expect } from 'expect';
import { beforeEach, describe, test, expect } from './test.js';
import { SqliteDriverConnectionPool } from '@sqlite-js/driver';

export interface DriverFeatures {
Expand All @@ -13,28 +10,27 @@ export interface DriverFeatures {
export function describeDriverTests(
name: string,
features: DriverFeatures,
factory: (path: string) => SqliteDriverConnectionPool
factory: (path: string) => Promise<SqliteDriverConnectionPool>
) {
describe(`${name} - driver tests`, () => {
let dbPath: string;

const open = async () => {
const dir = path.dirname(dbPath);
try {
await fs.mkdir(dir);
} catch (e) {}
try {
await fs.rm(dbPath);
} catch (e) {}
const db = factory(dbPath);
const db = await factory(dbPath);
return db;
};

beforeEach((context) => {
const testNameSanitized = context.fullName.replaceAll(
let testNameSanitized = context.fullName.replaceAll(
/[\s\/\\>\.\-\:]+/g,
'_'
);

if (testNameSanitized.length > 10) {
testNameSanitized =
testNameSanitized.substring(testNameSanitized.length - 7) +
String(Math.random()).substring(1, 4);
}
dbPath = `test-db/${testNameSanitized}.db`;
});

Expand Down
1 change: 1 addition & 0 deletions packages/driver-tests/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './driver-tests.js';
export * from './test.js';
Loading
Loading