-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprobe-store.mjs
More file actions
24 lines (24 loc) · 1.69 KB
/
Copy pathprobe-store.mjs
File metadata and controls
24 lines (24 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import os from 'node:os'; import fs from 'node:fs'; import path from 'node:path';
const R = 'file:///C:/projects/quereus/packages/';
const { Database } = await import(R + 'quereus/dist/src/index.js');
const { createIsolatedStoreModule } = await import(R + 'quereus-store/dist/src/index.js');
const { createLevelDBProvider } = await import(R + 'quereus-plugin-leveldb/dist/src/index.js');
const dir = path.join(os.tmpdir(), `probe-store-${Date.now()}`);
fs.mkdirSync(dir, { recursive: true });
const db = new Database();
db.registerModule('store', createIsolatedStoreModule({ provider: createLevelDBProvider({ basePath: dir.split(path.sep).join('/') }) }));
db.setOption('default_vtab_module', 'store');
const q = async (sql) => { const rows = []; for await (const r of db.eval(sql)) rows.push(r); return rows; };
const show = async (l, sql) => { try { console.log(l.padEnd(28), JSON.stringify(await q(sql))); } catch (e) { console.log(l.padEnd(28), 'ERR ' + e.message); } };
await db.exec(`create table il (d timespan primary key)`);
await db.exec(`insert into il values ('PT2H'), ('PT90M')`);
await show('all', `select d from il`);
await show('eq exact', `select d from il where d = 'PT2H'`);
await show('eq equiv', `select d from il where d = 'PT120M'`);
await show('in-list', `select d from il where d in ('PT120M','PT30M')`);
await show('in-list exact', `select d from il where d in ('PT2H','PT30M')`);
await show('or form', `select d from il where d = 'PT120M' or d = 'PT30M'`);
console.log('plan in-list:');
for await (const r of db.eval(`explain query plan select d from il where d in ('PT120M','PT30M')`)) console.log(' ', JSON.stringify(r).slice(0, 300));
await db.close();
fs.rmSync(dir, { recursive: true, force: true });