Table of contents
import sqlite from "sqlite3";
import { table, AnyPrintable, RowsArray } from "../../src";
With a DB connector
const it = sqlite.verbose();
const db = new it.Database(":memory:");
const runS = (q: string) =>
new Promise<any[]>((rs, rj) =>
db.all(q, (e: any, r: any) => (e ? rj(e) : rs(r)))
);
We can implement a version that is aware of the types
const run = <T extends AnyPrintable>(it: T): Promise<RowsArray<T>> =>
runS(it.stringify());
Then, with some tables
const t1 = table(["a", "b", "c"], "t1");
await runS(`CREATE TABLE t1(a,b,c);`);
await runS(`INSERT INTO t1 VALUES(1,2,3);`);
We can run queries
const value = await run(t1.selectStar());
value;
[{ "a": 1, "b": 2, "c": 3 }]
Typescript knows the identifiers
value.map((it) => it.a);
//@ts-expect-error
value.map((it) => it.u);
This document used eval-md