@hamur/db 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +38 -2
- package/dist/chunks/browser-bun-sql-2yeva2qv.js +53 -0
- package/dist/chunks/browser-bun-sqlite-xxptm4db.js +72 -0
- package/dist/chunks/browser-client-ehmpv0kf.js +130 -0
- package/dist/chunks/browser-d1-a16d23f0.js +8 -0
- package/dist/chunks/browser-index-3t2ajr9m.js +510 -0
- package/dist/chunks/browser-index-kf697bfy.js +113 -0
- package/dist/chunks/browser-index-ppkx8k0t.js +28 -0
- package/dist/chunks/bun-bun-sql-vaz9ggc8.js +54 -0
- package/dist/chunks/bun-bun-sqlite-qcd011rm.js +73 -0
- package/dist/chunks/bun-client-cnt1ddnf.js +131 -0
- package/dist/chunks/bun-d1-d36z1pyr.js +9 -0
- package/dist/chunks/bun-index-06tj00dn.js +11 -0
- package/dist/chunks/bun-index-9na2zkqq.js +224 -0
- package/dist/chunks/bun-index-b47nngck.js +352 -0
- package/dist/chunks/bun-index-hrx1eqma.js +29 -0
- package/dist/chunks/bun-index-pd6k99dv.js +114 -0
- package/dist/src/cli.js +1692 -0
- package/dist/src/devtools.js +153 -0
- package/dist/src/index.js +1491 -0
- package/dist/src/server/index.js +584 -0
- package/dist/src/storage/define.js +7 -0
- package/dist/types/src/build/connections.d.ts +8 -0
- package/dist/types/src/build/databases.d.ts +20 -0
- package/dist/types/src/build/factories.d.ts +6 -0
- package/dist/types/src/build/migrations.d.ts +21 -0
- package/dist/types/src/build/queue.d.ts +7 -0
- package/dist/types/src/build/schema.d.ts +50 -0
- package/dist/types/src/build/tables.d.ts +7 -0
- package/dist/types/src/build/types.d.ts +4 -0
- package/dist/types/src/cli.d.ts +26 -0
- package/dist/types/src/connectors/bun-sql.d.ts +3 -0
- package/dist/types/src/connectors/bun-sqlite.d.ts +3 -0
- package/dist/types/src/connectors/client-fakes.d.ts +57 -0
- package/dist/types/src/connectors/client.d.ts +3 -0
- package/dist/types/src/connectors/d1-fake.d.ts +32 -0
- package/dist/types/src/connectors/d1.d.ts +26 -0
- package/dist/types/src/connectors/node-sqlite.d.ts +3 -0
- package/dist/types/src/connectors/node-test.d.ts +17 -0
- package/dist/types/src/connectors/suite.d.ts +13 -0
- package/dist/types/src/devtools.d.ts +6 -0
- package/dist/types/src/index.d.ts +25 -0
- package/dist/types/src/module.d.ts +6 -0
- package/dist/types/src/options.d.ts +9 -0
- package/dist/types/src/runtime/connector.d.ts +53 -0
- package/dist/types/src/runtime/database.d.ts +15 -0
- package/dist/types/src/runtime/migrate.d.ts +56 -0
- package/dist/types/src/runtime/query.d.ts +12 -0
- package/dist/types/src/runtime/queue-process.d.ts +1 -0
- package/dist/types/src/runtime/queue.d.ts +85 -0
- package/dist/types/src/runtime/registry.d.ts +16 -0
- package/dist/types/src/server/client.d.ts +3 -0
- package/dist/types/src/server/databases.d.ts +4 -0
- package/dist/types/src/server/define-factory.d.ts +9 -0
- package/dist/types/src/server/devtools-routes.d.ts +4 -0
- package/dist/types/src/server/devtools.d.ts +26 -0
- package/dist/types/src/server/door-dev.d.ts +3 -0
- package/dist/types/src/server/door.d.ts +2 -0
- package/dist/types/src/server/factory-core.d.ts +12 -0
- package/dist/types/src/server/factory.d.ts +6 -0
- package/dist/types/src/server/fake.d.ts +35 -0
- package/dist/types/src/server/index.d.ts +12 -0
- package/dist/types/src/server/migrations.d.ts +5 -0
- package/dist/types/src/server/page.d.ts +26 -0
- package/dist/types/src/server/plugin.d.ts +1 -0
- package/dist/types/src/server/queue.d.ts +6 -0
- package/dist/types/src/server/table-entities.d.ts +33 -0
- package/dist/types/src/server/task.d.ts +6 -0
- package/dist/types/src/storage/define.d.ts +12 -0
- package/dist/types/src/storage/driver.d.ts +36 -0
- package/dist/types/src/storage/index.d.ts +3 -0
- package/dist/types/src/types.d.ts +103 -0
- package/package.json +40 -4
- package/src/build/connections.ts +225 -0
- package/src/build/databases.ts +101 -0
- package/src/build/factories.ts +135 -0
- package/src/build/migrations.ts +247 -0
- package/src/build/queue.ts +29 -0
- package/src/build/schema.ts +636 -0
- package/src/build/tables.ts +20 -0
- package/src/build/types.ts +46 -0
- package/src/cli.ts +153 -0
- package/src/connectors/bun-sql.ts +68 -0
- package/src/connectors/bun-sqlite.ts +69 -0
- package/src/connectors/client-fakes.ts +257 -0
- package/src/connectors/client.ts +161 -0
- package/src/connectors/d1-fake.ts +92 -0
- package/src/connectors/d1.ts +151 -0
- package/src/connectors/node-sqlite.ts +83 -0
- package/src/connectors/node-test.ts +31 -0
- package/src/connectors/suite.ts +406 -0
- package/src/devtools.ts +264 -0
- package/src/env.d.ts +28 -0
- package/src/index.ts +46 -0
- package/src/module.ts +36 -0
- package/src/options.ts +104 -0
- package/src/runtime/connector.ts +87 -0
- package/src/runtime/database.ts +353 -0
- package/src/runtime/migrate.ts +307 -0
- package/src/runtime/query.ts +82 -0
- package/src/runtime/queue-process.ts +39 -0
- package/src/runtime/queue.ts +380 -0
- package/src/runtime/registry.ts +61 -0
- package/src/server/client.ts +6 -0
- package/src/server/databases.ts +24 -0
- package/src/server/define-factory.ts +22 -0
- package/src/server/devtools-routes.ts +34 -0
- package/src/server/devtools.ts +205 -0
- package/src/server/door-dev.ts +6 -0
- package/src/server/door.ts +4 -0
- package/src/server/factory-core.ts +91 -0
- package/src/server/factory.ts +19 -0
- package/src/server/fake.ts +348 -0
- package/src/server/index.ts +17 -0
- package/src/server/migrations.ts +26 -0
- package/src/server/page.ts +181 -0
- package/src/server/plugin.ts +14 -0
- package/src/server/queue.ts +38 -0
- package/src/server/table-entities.ts +29 -0
- package/src/server/task.ts +15 -0
- package/src/storage/define.ts +12 -0
- package/src/storage/driver.ts +419 -0
- package/src/storage/index.ts +7 -0
- package/src/types.ts +101 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Dialect } from "../types.ts";
|
|
2
|
+
interface Token {
|
|
3
|
+
kind: "word" | "ident" | "string" | "punct";
|
|
4
|
+
text: string;
|
|
5
|
+
/** A word in lower case; empty for the others, so a quoted identifier never matches a keyword. */
|
|
6
|
+
lower: string;
|
|
7
|
+
}
|
|
8
|
+
/** Quoted identifiers kept, comments and strings reduced to one token each, so a `;` or `(` inside them never splits a statement. */
|
|
9
|
+
export declare function tokenize(sql: string, dialect: Dialect): Token[];
|
|
10
|
+
export interface Column {
|
|
11
|
+
name: string;
|
|
12
|
+
/** The TypeScript type without `| null`. */
|
|
13
|
+
base: string;
|
|
14
|
+
notNull: boolean;
|
|
15
|
+
primary: boolean;
|
|
16
|
+
/** Whether PRIMARY KEY makes the column not null: always, except on SQLite where only `INTEGER PRIMARY KEY` (the rowid), STRICT and WITHOUT ROWID do. */
|
|
17
|
+
pkNotNull: boolean;
|
|
18
|
+
/** A `DEFAULT` clause. */
|
|
19
|
+
hasDefault: boolean;
|
|
20
|
+
/** The database fills the value: `GENERATED`, identity, `serial`, `AUTO_INCREMENT`, `AUTOINCREMENT`. */
|
|
21
|
+
auto: boolean;
|
|
22
|
+
/** The declared type is exactly `INTEGER`, so a SQLite `PRIMARY KEY` on it is the rowid. */
|
|
23
|
+
integer: boolean;
|
|
24
|
+
/** Set when the column's type is `unknown` for a type typegen does not read. */
|
|
25
|
+
warning?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface Table {
|
|
28
|
+
name: string;
|
|
29
|
+
columns: Map<string, Column>;
|
|
30
|
+
}
|
|
31
|
+
export interface MigrationSource {
|
|
32
|
+
file: string;
|
|
33
|
+
sql: string;
|
|
34
|
+
}
|
|
35
|
+
export interface Schema {
|
|
36
|
+
tables: Map<string, Table>;
|
|
37
|
+
warnings: string[];
|
|
38
|
+
}
|
|
39
|
+
/** The TypeScript type of a declared column type, or undefined for one typegen does not read. */
|
|
40
|
+
export declare function mapType(dialect: Dialect, declared: string): string | undefined;
|
|
41
|
+
/** The key of a table or column name in `Schema`: only Postgres tells the case of a name apart. */
|
|
42
|
+
export declare const nameKey: (dialect: Dialect, name: string) => string;
|
|
43
|
+
/** The tables the migrations leave, read in order; any statement but `CREATE TABLE`, `ALTER TABLE` and `DROP TABLE` is ignored. */
|
|
44
|
+
export declare function readSchema(dialect: Dialect, migrations: readonly MigrationSource[]): Schema;
|
|
45
|
+
/** The warnings of columns that are still in a table at the end, after the ones raised while reading. */
|
|
46
|
+
export declare function warningsOf(schema: Schema): string[];
|
|
47
|
+
export declare const typeOfColumn: (column: Column) => string;
|
|
48
|
+
/** A column an insert may leave out: nullable, with a default, filled by the database, or SQLite's rowid alias. */
|
|
49
|
+
export declare const isOptionalOnInsert: (column: Column, dialect: Dialect) => boolean;
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { HamurContext } from "hamur/kit";
|
|
2
|
+
/** Why a module cannot keep `columns` in the app's `table`, as the migrations leave it; `undefined` when it can. */
|
|
3
|
+
export declare function tableProblem(hamur: HamurContext, { connection, table, columns }: {
|
|
4
|
+
connection?: string;
|
|
5
|
+
table: string;
|
|
6
|
+
columns: readonly string[];
|
|
7
|
+
}): Promise<string | undefined>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type HamurContext } from "hamur/kit";
|
|
2
|
+
import type { Dialect, ResolvedDbOptions } from "../types.ts";
|
|
3
|
+
/** `.hamur/types/db.d.ts`, one `HamurDatabases` entry per connection with the tables its migrations leave; `dialects` are the configured ones, before `dev` replaced a connection. */
|
|
4
|
+
export declare function setupTypes(options: ResolvedDbOptions, hamur: HamurContext, dialects?: Record<string, Dialect>): void;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type HamurContext } from "hamur/kit";
|
|
2
|
+
export { tableProblem } from "./build/tables.ts";
|
|
3
|
+
export interface DbCommand {
|
|
4
|
+
command: "migrate" | "status" | "new";
|
|
5
|
+
/** The migration name of `new`. */
|
|
6
|
+
name?: string;
|
|
7
|
+
/** `--connection`: one connection instead of every one. */
|
|
8
|
+
connection?: string;
|
|
9
|
+
out(line: string): void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The body of `hamur db`, on a context `createContext` made with the dev config (or the production one for `--prod`).
|
|
13
|
+
* Resolves to the exit code; a failure rejects with the message the CLI prints.
|
|
14
|
+
*/
|
|
15
|
+
export declare function runDbCommand(args: DbCommand, hamur: HamurContext): Promise<number>;
|
|
16
|
+
export interface QueueCommand {
|
|
17
|
+
command: "failed" | "retry";
|
|
18
|
+
/** The row id of `retry`. */
|
|
19
|
+
id?: string;
|
|
20
|
+
out(line: string): void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The body of `hamur task failed` and `hamur task retry <id>`, on a context `createContext` made with the production
|
|
24
|
+
* config: they read the queue table of the server's own connection. Resolves to the exit code.
|
|
25
|
+
*/
|
|
26
|
+
export declare function runQueueCommand(args: QueueCommand, hamur: HamurContext): Promise<number>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type Connector, type ConnectorOptions } from "../runtime/connector.ts";
|
|
2
|
+
/** `new Bun.SQL(url)`, or `Bun.SQL`'s own env default without one; the adapter it chose must be the connection's dialect. */
|
|
3
|
+
export default function openBunSql({ name, dialect, url }: ConnectorOptions): Promise<Connector>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type Connector, type ConnectorOptions } from "../runtime/connector.ts";
|
|
2
|
+
/** `Database` of `bun:sqlite` on `path` (against the working directory, its directory created), WAL unless in memory. */
|
|
3
|
+
export default function openBunSqlite({ path }: ConnectorOptions): Connector;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { DatabaseClient } from "../types.ts";
|
|
2
|
+
/** A driver over `bun:sqlite` that takes `$n` placeholders, as a Postgres driver does, and `?`; one connection, so `reserve` gives it. */
|
|
3
|
+
export declare function fakeSqliteClient(): DatabaseClient & {
|
|
4
|
+
ended: boolean;
|
|
5
|
+
};
|
|
6
|
+
/** `pg`'s `QueryResult`. */
|
|
7
|
+
export interface QueryResult {
|
|
8
|
+
rows: Record<string, unknown>[];
|
|
9
|
+
rowCount: number | null;
|
|
10
|
+
}
|
|
11
|
+
/** `pg`'s `PoolClient`: `query` resolves to one `QueryResult` per statement, a list when the text holds several. */
|
|
12
|
+
export interface PoolClient {
|
|
13
|
+
query(text: string, values?: unknown[]): Promise<QueryResult>;
|
|
14
|
+
/** An error (or `true`) destroys the connection instead of returning it to the pool. */
|
|
15
|
+
release(error?: Error | boolean): void;
|
|
16
|
+
}
|
|
17
|
+
/** `pg`'s `Pool`. */
|
|
18
|
+
export interface Pool {
|
|
19
|
+
query(text: string, values?: unknown[]): Promise<QueryResult>;
|
|
20
|
+
connect(): Promise<PoolClient>;
|
|
21
|
+
end(): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
/** `mysql2`'s `ResultSetHeader`: what a write resolves to. */
|
|
24
|
+
export interface ResultSetHeader {
|
|
25
|
+
affectedRows: number;
|
|
26
|
+
/** A string above `Number.MAX_SAFE_INTEGER` with `supportBigNumbers`. */
|
|
27
|
+
insertId: number | string;
|
|
28
|
+
}
|
|
29
|
+
type MysqlResult = [Record<string, unknown>[] | ResultSetHeader, unknown];
|
|
30
|
+
/** `mysql2/promise`'s `PoolConnection`. */
|
|
31
|
+
export interface PoolConnection {
|
|
32
|
+
/** Text protocol: `values` are escaped into the text on the client, one per `?`, quotes or not. */
|
|
33
|
+
query(sql: string, values?: unknown[]): Promise<MysqlResult>;
|
|
34
|
+
/** A server-side prepared statement: `values` are bound, never put in the text. */
|
|
35
|
+
execute(sql: string, values?: unknown[]): Promise<MysqlResult>;
|
|
36
|
+
release(): void;
|
|
37
|
+
/** Closes the connection instead of returning it to the pool. */
|
|
38
|
+
destroy(): void;
|
|
39
|
+
}
|
|
40
|
+
/** `mysql2/promise`'s `Pool`. */
|
|
41
|
+
export interface MysqlPool {
|
|
42
|
+
query(sql: string, values?: unknown[]): Promise<MysqlResult>;
|
|
43
|
+
execute(sql: string, values?: unknown[]): Promise<MysqlResult>;
|
|
44
|
+
getConnection(): Promise<PoolConnection>;
|
|
45
|
+
end(): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
/** A `pg` `Pool` over `Bun.SQL`: text parameters, the simple protocol without values, and a list of results for several statements. */
|
|
48
|
+
export declare function fakePgPool(url: string): Pool & {
|
|
49
|
+
released: Array<Error | boolean | undefined>;
|
|
50
|
+
};
|
|
51
|
+
/** A `mysql2/promise` `Pool` over `Bun.SQL`, its pool options as given: `supportBigNumbers` reads a BIGINT above 2^53 as a string. */
|
|
52
|
+
export declare function fakeMysqlPool(url: string, { supportBigNumbers }?: {
|
|
53
|
+
supportBigNumbers?: boolean;
|
|
54
|
+
}): MysqlPool & {
|
|
55
|
+
destroyed: number;
|
|
56
|
+
};
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type Connector, type ConnectorOptions } from "../runtime/connector.ts";
|
|
2
|
+
/** The app's file, its default export `defineDatabaseClient(() => client)` called once at the connection's first query. */
|
|
3
|
+
export default function openClient({ name, dialect, client: load }: ConnectorOptions): Promise<Connector>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Database as SQLite, type SQLQueryBindings } from "bun:sqlite";
|
|
2
|
+
interface FakeResult {
|
|
3
|
+
results: Record<string, unknown>[];
|
|
4
|
+
success: true;
|
|
5
|
+
meta: {
|
|
6
|
+
changes: number;
|
|
7
|
+
last_row_id: number;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
declare class FakeStatement {
|
|
11
|
+
readonly db: SQLite;
|
|
12
|
+
readonly text: string;
|
|
13
|
+
readonly values: SQLQueryBindings[];
|
|
14
|
+
constructor(db: SQLite, text: string, values?: SQLQueryBindings[]);
|
|
15
|
+
bind(...values: unknown[]): FakeStatement;
|
|
16
|
+
execute(): FakeResult;
|
|
17
|
+
all(): Promise<FakeResult>;
|
|
18
|
+
run(): Promise<FakeResult>;
|
|
19
|
+
first(column?: string): Promise<unknown>;
|
|
20
|
+
}
|
|
21
|
+
/** A D1 binding (`env.DB`) over `bun:sqlite` for tests: `prepare().bind().all()/first()/run()`, an atomic `batch` and `exec`. */
|
|
22
|
+
export declare function fakeD1(path?: string): {
|
|
23
|
+
prepare: (text: string) => FakeStatement;
|
|
24
|
+
batch(statements: FakeStatement[]): Promise<FakeResult[]>;
|
|
25
|
+
/** As D1's `exec`: the trimmed text split at `\n`, each line a query of its own. */
|
|
26
|
+
exec(text: string): Promise<{
|
|
27
|
+
count: number;
|
|
28
|
+
duration: number;
|
|
29
|
+
}>;
|
|
30
|
+
close: () => void;
|
|
31
|
+
};
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type Connector, type ConnectorOptions } from "../runtime/connector.ts";
|
|
2
|
+
interface D1Result {
|
|
3
|
+
results?: Record<string, unknown>[];
|
|
4
|
+
meta: {
|
|
5
|
+
changes?: number;
|
|
6
|
+
last_row_id?: number | null;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
interface D1PreparedStatement {
|
|
10
|
+
bind(...values: unknown[]): D1PreparedStatement;
|
|
11
|
+
all(): Promise<D1Result>;
|
|
12
|
+
run(): Promise<D1Result>;
|
|
13
|
+
}
|
|
14
|
+
/** The part of a D1 binding (`env.DB`) the connector calls. */
|
|
15
|
+
export interface D1Database {
|
|
16
|
+
prepare(query: string): D1PreparedStatement;
|
|
17
|
+
batch(statements: D1PreparedStatement[]): Promise<D1Result[]>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The statements of SQLite text, split at `;` outside quotes, brackets and comments, comments dropped; a `CREATE TRIGGER` runs
|
|
21
|
+
* to its `END`. D1's own `exec` sends each line as a query of its own, so multi-line text cannot go through it.
|
|
22
|
+
*/
|
|
23
|
+
export declare function sqliteStatements(sql: string): string[];
|
|
24
|
+
/** `env[binding]` of `cloudflare:workers`; `batch` is D1's `batch`, and `transaction` is refused, as D1 has none. */
|
|
25
|
+
export default function openD1({ name, binding }: ConnectorOptions, env?: () => Promise<Record<string, unknown>>): Promise<Connector>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type Connector, type ConnectorOptions } from "../runtime/connector.ts";
|
|
2
|
+
/** `DatabaseSync` of `node:sqlite` (Node ≥ 24) on `path` (against the working directory, its directory created), WAL unless in memory. */
|
|
3
|
+
export default function openNodeSqlite({ path }: ConnectorOptions): Connector;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { after, before, test } from "node:test";
|
|
2
|
+
/** The part of `bun:test` that `suite.ts` calls, on `node:test` and `node:assert`, so the connector suite runs under real `node`. */
|
|
3
|
+
type Expected = string | Error | undefined;
|
|
4
|
+
export declare function expect(actual: unknown): {
|
|
5
|
+
toBe: (expected: unknown) => void;
|
|
6
|
+
toEqual: (expected: unknown) => void;
|
|
7
|
+
toBeUndefined: () => void;
|
|
8
|
+
toThrow: (expected?: Expected) => void;
|
|
9
|
+
rejects: {
|
|
10
|
+
toThrow: (expected?: Expected) => Promise<void>;
|
|
11
|
+
toBe: (expected: unknown) => Promise<void>;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export declare const describe: ((name: string, fn: () => void) => Promise<void>) & {
|
|
15
|
+
skipIf: (skip: boolean) => (name: string, fn: () => void) => Promise<void>;
|
|
16
|
+
};
|
|
17
|
+
export { after as afterAll, before as beforeAll, test };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Connector } from "../runtime/connector.ts";
|
|
2
|
+
import type { Dialect } from "../types.ts";
|
|
3
|
+
export interface SuiteOptions {
|
|
4
|
+
/** The reason the suite is skipped (a missing server URL). */
|
|
5
|
+
skip?: string;
|
|
6
|
+
/** `false` when the connector refuses `transaction` (d1). */
|
|
7
|
+
transactions?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The connector suite. `open` makes a fresh connector on an empty database each time it is called; the suite owns the table
|
|
11
|
+
* `hamur_suite` and drops it at the end.
|
|
12
|
+
*/
|
|
13
|
+
export declare function connectorSuite(label: string, dialect: Dialect, open: () => Connector | Promise<Connector>, { skip, transactions }?: SuiteOptions): void;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** A cell as the grid shows it: `NULL` for null, JSON for an object. */
|
|
2
|
+
export declare function cellText(value: unknown): string;
|
|
3
|
+
/** The pages a table of `total` rows has, at least one. */
|
|
4
|
+
export declare const pageCount: (total: number, pageSize: number) => number;
|
|
5
|
+
declare const _default: import("hamur/app").DevtoolsApp;
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export { default } from "./module.ts";
|
|
2
|
+
export type { Connection, Database, DatabaseClient, DbConfig, Query, SqlFragment, Transaction } from "./types.ts";
|
|
3
|
+
/** Typegen fills it, `HamurDatabases[<connection>] = { dialect, tables, inserts }`; empty until the app has a connection. */
|
|
4
|
+
export interface HamurDatabases {
|
|
5
|
+
}
|
|
6
|
+
/** The connection names of the app, `string` while typegen has written none. */
|
|
7
|
+
export type DatabaseName = keyof HamurDatabases extends never ? string : keyof HamurDatabases & string;
|
|
8
|
+
/** `"default"`, or any name when the app has no `default` connection (a preset without a database of its own). */
|
|
9
|
+
export type DefaultDatabase = "default" extends DatabaseName ? "default" : DatabaseName;
|
|
10
|
+
/** The tables migrations created in connection `C`, `string` while typegen has written none. */
|
|
11
|
+
export type TableName<C extends DatabaseName = DefaultDatabase> = C extends keyof HamurDatabases ? HamurDatabases[C] extends {
|
|
12
|
+
tables: infer T;
|
|
13
|
+
} ? keyof T & string : string : string;
|
|
14
|
+
/** The type of table `T` in the connections `C` that have it; `never` when none does. */
|
|
15
|
+
type TableOf<T, C> = C extends keyof HamurDatabases ? HamurDatabases[C] extends {
|
|
16
|
+
tables: infer Tables;
|
|
17
|
+
} ? T extends keyof Tables ? Tables[T] : never : never : never;
|
|
18
|
+
/** The row of a table, as the migrations leave it: `db.sql<Row<"todos">>`select * from todos``. */
|
|
19
|
+
export type Row<T extends TableName<C>, C extends DatabaseName = DefaultDatabase> = [TableOf<T, C>] extends [never] ? Record<string, unknown> : TableOf<T, C>;
|
|
20
|
+
/** The insert type of table `T` in the connections `C` that have it; `never` when none does. */
|
|
21
|
+
type InsertOf<T, C> = C extends keyof HamurDatabases ? HamurDatabases[C] extends {
|
|
22
|
+
inserts: infer Inserts;
|
|
23
|
+
} ? T extends keyof Inserts ? Inserts[T] : never : never : never;
|
|
24
|
+
/** The values `insert into` takes for a table: a nullable column, one with a `DEFAULT` and one the database fills are optional. */
|
|
25
|
+
export type Insert<T extends TableName<C>, C extends DatabaseName = DefaultDatabase> = [InsertOf<T, C>] extends [never] ? Record<string, unknown> : InsertOf<T, C>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type HamurContext } from "hamur/kit";
|
|
2
|
+
import type { DbConfig, ResolvedDbOptions } from "./types.ts";
|
|
3
|
+
/** The options each context's setup resolved, for `runDbCommand`. */
|
|
4
|
+
export declare const resolvedOptions: WeakMap<HamurContext, ResolvedDbOptions>;
|
|
5
|
+
declare const _default: import("hamur/kit").HamurModule<DbConfig>;
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Dialect, DbConfig, ResolvedConnection, ResolvedDbOptions, Secret } from "./types.ts";
|
|
2
|
+
/** Each connector and the presets it runs on (`static` runs the server only at build, on Bun). */
|
|
3
|
+
export declare const CONNECTORS: Record<ResolvedConnection["connector"], {
|
|
4
|
+
presets: string[];
|
|
5
|
+
}>;
|
|
6
|
+
/** The dialect a literal url names by its scheme, else postgres. */
|
|
7
|
+
export declare function dialectOf(url: Secret | undefined): Dialect;
|
|
8
|
+
/** The checked options, or the build error of the first value that is wrong. */
|
|
9
|
+
export declare function resolveOptions(input: Partial<DbConfig> | undefined): ResolvedDbOptions;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Dialect, RunResult } from "../types.ts";
|
|
2
|
+
/** Another process may hold the write lock (the previous `hamur dev` generation, `hamur db migrate`); wait for it, not fail. */
|
|
3
|
+
export declare const BUSY_TIMEOUT = 5000;
|
|
4
|
+
/** SQLite answers BUSY at once, without the busy timeout, while another connection switches the journal mode; retried as the storage driver does. */
|
|
5
|
+
export declare function journalWal(run: (text: string) => void): void;
|
|
6
|
+
/** What one connection, or one transaction on it, runs: text with the dialect's placeholders and the bound values in order. */
|
|
7
|
+
export interface ConnectorSession {
|
|
8
|
+
all(text: string, params: unknown[]): Promise<Record<string, unknown>[]>;
|
|
9
|
+
run(text: string, params: unknown[]): Promise<RunResult>;
|
|
10
|
+
exec(text: string): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
/** A session inside a transaction. */
|
|
13
|
+
export interface TransactionSession extends ConnectorSession {
|
|
14
|
+
/** Runs `fn` in a savepoint: released when it resolves, rolled back to and rethrown when it rejects. */
|
|
15
|
+
savepoint<R>(fn: (session: ConnectorSession) => Promise<R>): Promise<R>;
|
|
16
|
+
}
|
|
17
|
+
/** One connection held for a whole migration run. */
|
|
18
|
+
export interface ReservedSession extends ConnectorSession {
|
|
19
|
+
/** A transaction on this same connection; `BEGIN IMMEDIATE` on sqlite. */
|
|
20
|
+
transaction<R>(fn: (session: ConnectorSession) => Promise<R>): Promise<R>;
|
|
21
|
+
}
|
|
22
|
+
/** One statement of a connector's own batch: `all` resolves to rows, `run` to the rows written. */
|
|
23
|
+
export interface BatchStatement {
|
|
24
|
+
kind: "all" | "run";
|
|
25
|
+
text: string;
|
|
26
|
+
params: unknown[];
|
|
27
|
+
}
|
|
28
|
+
/** The code that runs one connection's queries on one backend. */
|
|
29
|
+
export interface Connector extends ConnectorSession {
|
|
30
|
+
/** Commits when `fn` resolves, rolls back and rethrows when it rejects. */
|
|
31
|
+
transaction<R>(fn: (session: TransactionSession) => Promise<R>): Promise<R>;
|
|
32
|
+
/** Runs `fn` on one connection (a pool's reserved one, or SQLite's only one) and gives it back when `fn` settles. */
|
|
33
|
+
reserve<R>(fn: (session: ReservedSession) => Promise<R>): Promise<R>;
|
|
34
|
+
/** The backend's own atomic batch in one round trip (D1's); without it `batch` runs in a transaction. */
|
|
35
|
+
batch?(statements: BatchStatement[]): Promise<Array<Record<string, unknown>[] | RunResult>>;
|
|
36
|
+
/** The process shares no connection (D1: every statement is a request of its own), so statements take no process lock. */
|
|
37
|
+
readonly concurrent?: boolean;
|
|
38
|
+
close(): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
/** The options a connector opens with: `url` already read from the runtime config, `path` and `binding` as configured, `client` bundled. */
|
|
41
|
+
export interface ConnectorOptions {
|
|
42
|
+
name: string;
|
|
43
|
+
dialect: Dialect;
|
|
44
|
+
url?: string;
|
|
45
|
+
path?: string;
|
|
46
|
+
binding?: string;
|
|
47
|
+
/** Imports the connection's client file. */
|
|
48
|
+
client?: ClientLoader;
|
|
49
|
+
}
|
|
50
|
+
export type ClientLoader = () => Promise<unknown>;
|
|
51
|
+
export type OpenConnector = (options: ConnectorOptions) => Connector | Promise<Connector>;
|
|
52
|
+
/** `lastInsertRowid` of `bun:sqlite` and `Bun.SQL`: a number, a decimal string above `Number.MAX_SAFE_INTEGER`, none when null. */
|
|
53
|
+
export declare function insertId(value: number | bigint | string | null | undefined): number | string | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Database, Dialect } from "../types.ts";
|
|
2
|
+
import type { Connector, ReservedSession } from "./connector.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Runs `fn`, which uses `db` the way code outside a transaction does, from inside `db.transaction` too: on a pool the calls
|
|
5
|
+
* take another connection. Where one connection serves the process (SQLite) they would wait for the transaction that waits for
|
|
6
|
+
* them, so that fails with what to do instead.
|
|
7
|
+
*/
|
|
8
|
+
export declare function outsideTransaction<R>(db: Database, fn: () => Promise<R>): Promise<R>;
|
|
9
|
+
/** Runs `fn` on one connection of `db` for a migration run; on sqlite under the process lock, so the app's statements wait. */
|
|
10
|
+
export declare function reserveConnection<R>(db: Database, fn: (session: ReservedSession) => Promise<R>): Promise<R>;
|
|
11
|
+
/**
|
|
12
|
+
* One connection's `Database`. `open` makes the connector at the first query. On sqlite one connection serves the
|
|
13
|
+
* process, so every statement and transaction runs under one lock.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createDatabase(name: string, dialect: Dialect, open: () => Connector | Promise<Connector>): Database;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Database } from "../types.ts";
|
|
2
|
+
/** One SQL file of a connection, read and hashed by the build. */
|
|
3
|
+
export interface Migration {
|
|
4
|
+
/** The number, as written: `0001`. */
|
|
5
|
+
id: string;
|
|
6
|
+
/** The rest of the name: `init`. */
|
|
7
|
+
name: string;
|
|
8
|
+
/** `0001_init.sql`. */
|
|
9
|
+
file: string;
|
|
10
|
+
sql: string;
|
|
11
|
+
/** SHA-256 hex of `sql` with CRLF turned into LF. */
|
|
12
|
+
checksum: string;
|
|
13
|
+
}
|
|
14
|
+
export interface MigrationRow {
|
|
15
|
+
id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
checksum: string;
|
|
18
|
+
applied_at: string;
|
|
19
|
+
}
|
|
20
|
+
export interface MigrateOptions {
|
|
21
|
+
/** An applied migration whose file is gone; a rollback deploy has fewer files, so it is not an error. */
|
|
22
|
+
warn?: (message: string) => void;
|
|
23
|
+
applied?: (migration: Migration, ms: number) => void;
|
|
24
|
+
/** How long a run waits for another instance's lock, in ms. */
|
|
25
|
+
lockTimeout?: number;
|
|
26
|
+
}
|
|
27
|
+
export type MigrationState = {
|
|
28
|
+
id: string;
|
|
29
|
+
name: string;
|
|
30
|
+
state: "applied";
|
|
31
|
+
appliedAt: string;
|
|
32
|
+
} | {
|
|
33
|
+
id: string;
|
|
34
|
+
name: string;
|
|
35
|
+
state: "pending" | "changed" | "missing file";
|
|
36
|
+
};
|
|
37
|
+
/** A migration file's text without the UTF-8 BOM an editor may add, which SQLite and Postgres would read as part of a name. */
|
|
38
|
+
export declare const withoutBom: (text: string) => string;
|
|
39
|
+
/** SHA-256 hex of the file without a BOM and with CRLF turned into LF, so neither an editor nor a Windows checkout changes it. */
|
|
40
|
+
export declare function checksumOf(text: string): Promise<string>;
|
|
41
|
+
/**
|
|
42
|
+
* MySQL: the statements of a file, split at `;` outside quotes, backticks and comments, comments dropped. Bun's docs do not say
|
|
43
|
+
* that a multi-statement `.simple()` on MySQL rejects for a later statement's error, so each statement runs on its own. A routine
|
|
44
|
+
* body holding `;` is split too and fails as a syntax error.
|
|
45
|
+
*/
|
|
46
|
+
export declare function mysqlStatements(sql: string): string[];
|
|
47
|
+
/**
|
|
48
|
+
* Applies each pending migration of `db` once, in the order given, on one connection under the dialect's lock; returns
|
|
49
|
+
* those this run applied. The checks of `checkFiles` fail before anything runs; a failed file stops the run, its own transaction
|
|
50
|
+
* rolled back (except on mysql) and the earlier ones kept.
|
|
51
|
+
*/
|
|
52
|
+
export declare function migrate(db: Database, migrations: readonly Migration[], options?: MigrateOptions): Promise<Migration[]>;
|
|
53
|
+
/** Every migration of `db` and its state, in id order; reads, never writes. */
|
|
54
|
+
export declare function migrationStatus(db: Database, migrations: readonly Migration[]): Promise<MigrationState[]>;
|
|
55
|
+
/** Migration numbers in numeric order: `0009` before `0010`, `9999` before `10000`. */
|
|
56
|
+
export declare function compareIds(a: string, b: string): number;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Dialect, SqlValue } from "../types.ts";
|
|
2
|
+
export interface Compiled {
|
|
3
|
+
text: string;
|
|
4
|
+
values: readonly SqlValue[];
|
|
5
|
+
/** The values as the dialect binds them. */
|
|
6
|
+
params: unknown[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The template's text with a placeholder per value, and the values bound in order; no app value ever becomes
|
|
10
|
+
* text. A `SqlFragment` is spliced as its text, its values bound at its place.
|
|
11
|
+
*/
|
|
12
|
+
export declare function compile(method: string, name: string, dialect: Dialect, strings: TemplateStringsArray, values: readonly unknown[]): Compiled;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { Database } from "../types.ts";
|
|
2
|
+
/** `tasks.queue: { driver: "db" }` with its defaults filled. */
|
|
3
|
+
export interface QueueOptions {
|
|
4
|
+
connection: string;
|
|
5
|
+
table: string;
|
|
6
|
+
concurrency: number;
|
|
7
|
+
maxAttempts: number;
|
|
8
|
+
}
|
|
9
|
+
export declare const QUEUE_DEFAULTS: QueueOptions;
|
|
10
|
+
/** A claimed row stays locked this long; the worker renews the lock while its run goes on. */
|
|
11
|
+
export declare const LOCK_MS: number;
|
|
12
|
+
/** A row of the queue table; times are ms since the epoch. */
|
|
13
|
+
export interface QueueRow {
|
|
14
|
+
id: string;
|
|
15
|
+
task: string;
|
|
16
|
+
payload: string;
|
|
17
|
+
runAt: number;
|
|
18
|
+
attempts: number;
|
|
19
|
+
lastError: string | null;
|
|
20
|
+
lockedUntil: number | null;
|
|
21
|
+
createdAt: number;
|
|
22
|
+
failedAt: number | null;
|
|
23
|
+
}
|
|
24
|
+
/** A row this worker holds; `attempts` counts this run, and `claim` is the row's claim count, which only grows: the row is written only while it still has that count. */
|
|
25
|
+
export interface ClaimedRow {
|
|
26
|
+
id: string;
|
|
27
|
+
task: string;
|
|
28
|
+
payload: string;
|
|
29
|
+
attempts: number;
|
|
30
|
+
claim: number;
|
|
31
|
+
}
|
|
32
|
+
/** What `retry` did: `due`, no failed row of that id (`missing`), or a row still locked by a run until `until`. */
|
|
33
|
+
export type RetryResult = {
|
|
34
|
+
state: "due";
|
|
35
|
+
} | {
|
|
36
|
+
state: "missing";
|
|
37
|
+
} | {
|
|
38
|
+
state: "locked";
|
|
39
|
+
until: number;
|
|
40
|
+
};
|
|
41
|
+
export interface QueueTable {
|
|
42
|
+
readonly maxAttempts: number;
|
|
43
|
+
/** `CREATE TABLE IF NOT EXISTS` and its index, once per table object. */
|
|
44
|
+
ensure(): Promise<void>;
|
|
45
|
+
insert(task: string, payload: string, delaySeconds: number): Promise<string>;
|
|
46
|
+
/** Up to `limit` due rows, locked for `LOCK_MS` and their `attempts` and `claims` raised, in one transaction. */
|
|
47
|
+
claim(limit: number): Promise<ClaimedRow[]>;
|
|
48
|
+
/** Extends the lock; `false` when another claim took the row. */
|
|
49
|
+
renew(row: ClaimedRow): Promise<boolean>;
|
|
50
|
+
/** Deletes the row of a run that resolved; after a throw, sets it due after the backoff, or keeps it failed after `maxAttempts`. */
|
|
51
|
+
finish(row: ClaimedRow, failure?: {
|
|
52
|
+
error: unknown;
|
|
53
|
+
}): Promise<void>;
|
|
54
|
+
failed(): Promise<QueueRow[]>;
|
|
55
|
+
/** Sets a failed row due now with its attempts at 0, unless a run still holds its lock. */
|
|
56
|
+
retry(id: string): Promise<RetryResult>;
|
|
57
|
+
}
|
|
58
|
+
/** The wait before the next run of a row whose `attempts`-th run threw: 10 s, doubled each time, at most 1 h. */
|
|
59
|
+
export declare function backoff(attempts: number): number;
|
|
60
|
+
/**
|
|
61
|
+
* The queue table `(id, task, payload, run_at, attempts, last_error, locked_until, created_at, failed_at)` on one
|
|
62
|
+
* connection, in its dialect's SQL. A claim selects due rows with `FOR UPDATE SKIP LOCKED` on postgres and mysql, and inside
|
|
63
|
+
* sqlite's `BEGIN IMMEDIATE`, so one row goes to one worker across processes.
|
|
64
|
+
*/
|
|
65
|
+
export declare function createQueueTable(database: () => Database, options: Pick<QueueOptions, "table" | "maxAttempts">, now?: () => number): QueueTable;
|
|
66
|
+
export interface QueueWorkerOptions {
|
|
67
|
+
concurrency: number;
|
|
68
|
+
/** One run of a claimed row: what it threw, else `undefined`; it never rejects. */
|
|
69
|
+
run(row: ClaimedRow): Promise<{
|
|
70
|
+
error: unknown;
|
|
71
|
+
} | undefined>;
|
|
72
|
+
/** Where a failed claim or write goes; the worker claims again at its next poll. */
|
|
73
|
+
error(error: unknown): void;
|
|
74
|
+
pollMs?: number;
|
|
75
|
+
/** How often the lock of each held run is renewed (default 1 min). */
|
|
76
|
+
renewMs?: number;
|
|
77
|
+
}
|
|
78
|
+
export interface QueueWorker {
|
|
79
|
+
/** Claims now instead of at the next poll (after a local insert). */
|
|
80
|
+
wake(): void;
|
|
81
|
+
/** Stops claiming and resolves once the runs it holds ended; a run cut short is claimed again once its lock expired. */
|
|
82
|
+
stop(): Promise<void>;
|
|
83
|
+
}
|
|
84
|
+
/** Claims due rows up to `concurrency` runs at once, every `pollMs` (1 s) and as soon as a run ends, and renews the lock of each run it holds. */
|
|
85
|
+
export declare function startQueueWorker(queue: QueueTable, options: QueueWorkerOptions): QueueWorker;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Database, ResolvedConnection } from "../types.ts";
|
|
2
|
+
import type { ClientLoader, OpenConnector } from "./connector.ts";
|
|
3
|
+
export type ConnectorLoaders = Record<string, () => Promise<{
|
|
4
|
+
default: OpenConnector;
|
|
5
|
+
}>>;
|
|
6
|
+
/** The client file of each `client` connection, by connection name. */
|
|
7
|
+
export type ClientLoaders = Record<string, ClientLoader>;
|
|
8
|
+
export interface Databases {
|
|
9
|
+
use(name?: string): Database;
|
|
10
|
+
/** Closes every connection that was opened. */
|
|
11
|
+
close(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
/** The value of an `app/env.ts` entry: the server's, read at start, or one the build process reads itself. */
|
|
14
|
+
export type EnvReader = (name: string) => unknown;
|
|
15
|
+
/** One `Database` per connection name for the process, its connector imported and opened at the first query. */
|
|
16
|
+
export declare function createDatabases(connections: Record<string, ResolvedConnection>, loaders: ConnectorLoaders, env: EnvReader, clients?: ClientLoaders): Databases;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { DatabaseClient } from "../types.ts";
|
|
2
|
+
/** The default export of a `client` connection's file; Hamur calls `factory` once per process, at the first query. */
|
|
3
|
+
export declare function defineDatabaseClient(factory: () => DatabaseClient | Promise<DatabaseClient>): typeof factory;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ResolvedConnection } from "../types.ts";
|
|
2
|
+
/** The connections this run uses: the bundled ones, each replaced by its `dev` while prerendering. */
|
|
3
|
+
export declare const active: Record<string, ResolvedConnection>;
|
|
4
|
+
export declare const databases: import("../runtime/registry.ts").Databases;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DatabaseName, DefaultDatabase, Insert, TableName } from "../index.ts";
|
|
2
|
+
import type { Fake } from "./fake.ts";
|
|
3
|
+
/** What `defineFactory` returns, the default export of `server/db/factories/<table>.ts`. */
|
|
4
|
+
export interface Factory<T extends TableName<C>, C extends DatabaseName = DefaultDatabase> {
|
|
5
|
+
readonly make: (n: number, fake: Fake) => Insert<T, C>;
|
|
6
|
+
}
|
|
7
|
+
/** The rows of table `T` as `make(n, fake)` writes them, `n` counting from 1. */
|
|
8
|
+
export declare function defineFactory<T extends TableName<C>, C extends DatabaseName = DefaultDatabase>(make: (n: number, fake: Fake) => Insert<T, C>): Factory<T, C>;
|
|
9
|
+
export declare const isFactory: (value: unknown) => value is Factory<never, never>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const devtoolsDbTables: import("hamur/server").Handler<unknown, Response, unknown, Response, {}>;
|
|
2
|
+
export declare const devtoolsDbRows: import("hamur/server").Handler<unknown, Response, unknown, Response, {}>;
|
|
3
|
+
export declare const devtoolsDbQuery: import("hamur/server").Handler<unknown, Response, unknown, Response, {}>;
|
|
4
|
+
export declare const devtoolsDbMigrations: import("hamur/server").Handler<unknown, Response, unknown, Response, {}>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Database } from "../types.ts";
|
|
2
|
+
/** Rows per page of the Database tab. */
|
|
3
|
+
export declare const PAGE_SIZE = 50;
|
|
4
|
+
/** The rows one SQL run answers at most. */
|
|
5
|
+
export declare const QUERY_ROWS_MAX = 500;
|
|
6
|
+
export declare const SQL_MAX_LENGTH = 100000;
|
|
7
|
+
/** A row as JSON: a bigint as its digits, bytes as `0x<hex>`. */
|
|
8
|
+
export declare function jsonRow(row: Record<string, unknown>): Record<string, unknown>;
|
|
9
|
+
/** `GET api/db/tables?connection=<c>`: `{ connection, connections, dialect, tables }`. */
|
|
10
|
+
export declare function answerTables(request: Request): Promise<Response>;
|
|
11
|
+
/** `GET api/db/rows?connection=<c>&table=<t>&page=<n>`: one page of 50 rows of a table the connection lists, and its row count. */
|
|
12
|
+
export declare function answerRows(request: Request): Promise<Response>;
|
|
13
|
+
/** The one statement of `sql`, or the message of why it is refused. */
|
|
14
|
+
export declare function oneStatement(sql: unknown): string | {
|
|
15
|
+
error: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The rows of `sql`, at most `QUERY_ROWS_MAX + 1`: no connector reads rows one at a time, so a `select` or `with` runs wrapped in
|
|
19
|
+
* `select * from (…) limit <n>` and the database stops at the cap. One that does not parse wrapped (a `with … insert`) runs as typed;
|
|
20
|
+
* a parse error runs nothing, so the statement runs once.
|
|
21
|
+
*/
|
|
22
|
+
export declare function capped(db: Database, sql: string): Promise<Array<Record<string, unknown>>>;
|
|
23
|
+
/** `POST api/db/query` `{ sql, connection? }`: runs one statement and answers `{ columns, rows, truncated, ms }`, at most 500 rows. */
|
|
24
|
+
export declare function answerQuery(request: Request): Promise<Response>;
|
|
25
|
+
/** `GET api/db/migrations?connection=<c>`: each migration with its state, as `hamur db status` reads it. */
|
|
26
|
+
export declare function answerMigrations(request: Request): Promise<Response>;
|