@athenox/talos
Version:
Talos: a backend you describe instead of write. Declare a schema, write the rules in plain language, map URLs to sentences; a small built-in model turns them into query plans.
40 lines (39 loc) • 2.14 kB
TypeScript
import type { DatabaseSync } from 'node:sqlite';
/** Open (once) the database every helper below writes through. */
export declare function getDb(file?: string): DatabaseSync;
export declare const hashPassword: (pw: string, salt?: string) => string;
export declare function verifyPassword(pw: string, stored: string): boolean;
/** Accounts. Every app needs them and none of them should write this twice. */
export declare function createUserTable(): void;
export declare function addUser(name: string, email: string, role: string, password: string): import("node:sqlite").StatementResultingChanges;
export declare const findUser: (email: string) => Record<string, any> | undefined;
export declare const userById: (id: number) => Record<string, any> | undefined;
export type ColumnType = 'text' | 'int' | 'real';
/**
* Create a table from the same column list the model is shown, so the schema in
* the prompt and the schema on disk cannot drift apart.
*/
export declare function createTable(table: string, columns: {
as: string;
type?: ColumnType;
}[], extra?: string[]): void;
/** Quote an identifier. Identifiers can never be bound, so they are quoted. */
export declare const ident: (name: string) => string;
export type Trace = {
sql: string;
params: unknown[];
rows?: number;
};
export declare const beginTrace: () => void;
export declare const endTrace: () => Trace[];
export declare const all: (sql: string, ...args: unknown[]) => Record<string, any>[];
export declare const one: (sql: string, ...args: unknown[]) => Record<string, any> | undefined;
export declare const run: (sql: string, ...args: unknown[]) => import("node:sqlite").StatementResultingChanges;
/** Fuzzy-resolve free text to a row id, for a value that names a record. */
export declare function lookupIn(table: string, text: string): number | null;
/** The store shape the runtime expects. */
export declare const store: {
all: (sql: string, ...p: unknown[]) => Record<string, any>[];
run: (sql: string, ...p: unknown[]) => import("node:sqlite").StatementResultingChanges;
lookup: (table: string, text: string) => number | null;
};