Skip to content

Commit 9c90f90

Browse files
committed
Port wa-sqlite driver to new api; other tweaks.
1 parent cacaa04 commit 9c90f90

File tree

26 files changed

+532
-699
lines changed

26 files changed

+532
-699
lines changed

benchmarks/src/implementations/better-sqlite3.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ import DatabaseConstructor from 'better-sqlite3';
33
import { promises as fs } from 'fs';
44
import assert from 'node:assert';
55
import { join } from 'path';
6-
import Prando from 'prando';
76
import { Benchmark } from '../Benchmark.js';
8-
import { numberName } from '../util.js';
7+
import { numberName, createRandom } from '../util.js';
98

109
export class BetterSqlite3Impl extends Benchmark {
1110
private db!: bsqlite.Database;
1211
private dir: string;
13-
private random = new Prando.default(0);
12+
private random = createRandom(0);
1413

1514
constructor(
1615
public name: string,

benchmarks/src/implementations/node-sqlite.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import { promises as fs } from 'fs';
22
import assert from 'node:assert';
33
import { join } from 'path';
4-
import Prando from 'prando';
54
import { Benchmark } from '../Benchmark.js';
6-
import { numberName } from '../util.js';
5+
import { numberName, createRandom } from '../util.js';
76

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

1110
export class NodeSqliteImpl extends Benchmark {
1211
private db!: sqlite.DatabaseSync;
1312
private dir: string;
14-
private random = new Prando.default(0);
13+
private random = createRandom(0);
1514

1615
constructor(
1716
public name: string,

benchmarks/src/implementations/node-sqlite3.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import { Benchmark } from '../Benchmark.js';
22
import { join } from 'path';
33
import { promises as fs } from 'fs';
4-
import Prando from 'prando';
54
import assert from 'node:assert';
6-
import { numberName } from '../util.js';
5+
import { numberName, createRandom } from '../util.js';
76
import sqlite3 from 'sqlite3';
87
import { open, Database } from 'sqlite';
98

109
export class NodeSqlite3Impl extends Benchmark {
1110
private db!: Database;
1211
private dir: string;
13-
private random = new Prando.default(0);
12+
private random = createRandom(0);
1413

1514
constructor(
1615
public name: string,

benchmarks/src/implementations/sjp-json.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { promises as fs } from 'fs';
22
import assert from 'node:assert';
33
import { join } from 'path';
4-
import Prando from 'prando';
54
import { SqliteConnectionPool } from '@sqlite-js/api';
65
import { Benchmark } from '../Benchmark.js';
7-
import { numberName } from '../util.js';
6+
import { numberName, createRandom } from '../util.js';
87

98
export class JSPJsonImpl extends Benchmark {
109
private db!: SqliteConnectionPool;
1110
private dir: string;
12-
private random = new Prando.default(0);
11+
private random = createRandom(0);
1312

1413
constructor(
1514
public name: string,

benchmarks/src/implementations/sjp-optimized.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { promises as fs } from 'fs';
22
import assert from 'node:assert';
33
import { join } from 'path';
4-
import Prando from 'prando';
54
import { SqliteConnectionPool } from '@sqlite-js/api';
65
import { Benchmark } from '../Benchmark.js';
7-
import { numberName } from '../util.js';
6+
import { numberName, createRandom } from '../util.js';
87

98
export class JSPOptimizedImpl extends Benchmark {
109
private db!: SqliteConnectionPool;
1110
private dir: string;
12-
private random = new Prando.default(0);
11+
private random = createRandom(0);
1312

1413
constructor(
1514
public name: string,

benchmarks/src/implementations/sjp.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { promises as fs } from 'fs';
22
import assert from 'node:assert';
33
import { join } from 'path';
4-
import Prando from 'prando';
54
import { SqliteConnectionPool } from '@sqlite-js/api';
65
import { Benchmark } from '../Benchmark.js';
7-
import { numberName } from '../util.js';
6+
import { numberName, createRandom } from '../util.js';
87

98
export class JSPImpl extends Benchmark {
109
private db!: SqliteConnectionPool;
1110
private dir: string;
12-
private random = new Prando.default(0);
11+
private random = createRandom(0);
1312

1413
constructor(
1514
public name: string,

benchmarks/src/util.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as Prando from 'prando';
2+
13
const digits = [
24
'',
35
'one',
@@ -34,6 +36,28 @@ const names100 = [
3436
...digits.map((digit) => `ninety${digit != '' ? '-' + digit : ''}`)
3537
];
3638

39+
type PrandoInstance = import('prando').default;
40+
type PrandoConstructor = new (seed?: number | string) => PrandoInstance;
41+
42+
function resolvePrandoConstructor(): PrandoConstructor {
43+
const mod = Prando as unknown as {
44+
default?: PrandoConstructor;
45+
};
46+
if (typeof (Prando as unknown) === 'function') {
47+
return Prando as unknown as PrandoConstructor;
48+
}
49+
if (mod.default) {
50+
return mod.default;
51+
}
52+
throw new Error('Unable to locate Prando constructor');
53+
}
54+
55+
const PRANDO_CTOR = resolvePrandoConstructor();
56+
57+
export function createRandom(seed?: number | string): PrandoInstance {
58+
return new PRANDO_CTOR(seed);
59+
}
60+
3761
export function numberName(n: number): string {
3862
if (n == 0) {
3963
return 'zero';

benchmarks/tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
"target": "ES2022",
66
"strict": true,
77
"module": "NodeNext",
8+
"moduleResolution": "NodeNext",
89
"outDir": "lib",
910
"sourceMap": true,
1011
"declaration": true,
1112
"rootDir": "src",
12-
"typeRoots": ["./src/types", "./node_modules/@types"]
13+
"typeRoots": ["./src/types", "./node_modules/@types"],
14+
"esModuleInterop": true,
15+
"allowSyntheticDefaultImports": true
1316
},
1417
"include": ["src"],
1518
"references": [{ "path": "../packages/api" }]

packages/api/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88
"test": "vitest",
99
"clean": "tsc -b --clean && rm -rf lib"
1010
},
11+
"types": "./lib/index.d.ts",
1112
"exports": {
12-
".": "./lib/index.js"
13+
".": {
14+
"types": "./lib/index.d.ts",
15+
"default": "./lib/index.js"
16+
}
1317
},
1418
"keywords": [],
1519
"author": "",

packages/better-sqlite3-driver/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88
"test": "pnpm build && vitest",
99
"clean": "tsc -b --clean && tsc -b ./test/tsconfig.json --clean && rm -rf lib test/lib"
1010
},
11+
"types": "./lib/index.d.ts",
1112
"exports": {
12-
".": "./lib/index.js"
13+
".": {
14+
"types": "./lib/index.d.ts",
15+
"default": "./lib/index.js"
16+
}
1317
},
1418
"keywords": [],
1519
"author": "",

0 commit comments

Comments
 (0)