@g9tm/lynxcontrols-sqlite 1.4.0
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/README.md +12 -0
- package/contract/cases.json +463 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/codecs/codecs.d.ts +68 -0
- package/dist/codecs/codecs.d.ts.map +1 -0
- package/dist/codecs/codecs.js +201 -0
- package/dist/codecs/codecs.js.map +1 -0
- package/dist/contract/run-contract.d.ts +94 -0
- package/dist/contract/run-contract.d.ts.map +1 -0
- package/dist/contract/run-contract.js +159 -0
- package/dist/contract/run-contract.js.map +1 -0
- package/dist/driver/types.d.ts +87 -0
- package/dist/driver/types.d.ts.map +1 -0
- package/dist/driver/types.js +14 -0
- package/dist/driver/types.js.map +1 -0
- package/dist/errors.d.ts +39 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +57 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/query/builders.d.ts +216 -0
- package/dist/query/builders.d.ts.map +1 -0
- package/dist/query/builders.js +490 -0
- package/dist/query/builders.js.map +1 -0
- package/dist/query/compile.d.ts +42 -0
- package/dist/query/compile.d.ts.map +1 -0
- package/dist/query/compile.js +307 -0
- package/dist/query/compile.js.map +1 -0
- package/dist/query/expr.d.ts +201 -0
- package/dist/query/expr.d.ts.map +1 -0
- package/dist/query/expr.js +247 -0
- package/dist/query/expr.js.map +1 -0
- package/dist/repo/audit.d.ts +19 -0
- package/dist/repo/audit.d.ts.map +1 -0
- package/dist/repo/audit.js +36 -0
- package/dist/repo/audit.js.map +1 -0
- package/dist/repo/repository.d.ts +233 -0
- package/dist/repo/repository.d.ts.map +1 -0
- package/dist/repo/repository.js +715 -0
- package/dist/repo/repository.js.map +1 -0
- package/dist/schema/columns.d.ts +115 -0
- package/dist/schema/columns.d.ts.map +1 -0
- package/dist/schema/columns.js +112 -0
- package/dist/schema/columns.js.map +1 -0
- package/dist/schema/entity.d.ts +135 -0
- package/dist/schema/entity.d.ts.map +1 -0
- package/dist/schema/entity.js +227 -0
- package/dist/schema/entity.js.map +1 -0
- package/dist/schema/policies.d.ts +89 -0
- package/dist/schema/policies.d.ts.map +1 -0
- package/dist/schema/policies.js +54 -0
- package/dist/schema/policies.js.map +1 -0
- package/dist/session/ambient.d.ts +32 -0
- package/dist/session/ambient.d.ts.map +1 -0
- package/dist/session/ambient.js +28 -0
- package/dist/session/ambient.js.map +1 -0
- package/dist/session/cache.d.ts +62 -0
- package/dist/session/cache.d.ts.map +1 -0
- package/dist/session/cache.js +239 -0
- package/dist/session/cache.js.map +1 -0
- package/dist/session/database.d.ts +221 -0
- package/dist/session/database.d.ts.map +1 -0
- package/dist/session/database.js +430 -0
- package/dist/session/database.js.map +1 -0
- package/dist/session/locator.d.ts +33 -0
- package/dist/session/locator.d.ts.map +1 -0
- package/dist/session/locator.js +39 -0
- package/dist/session/locator.js.map +1 -0
- package/dist/session/migrations.d.ts +75 -0
- package/dist/session/migrations.d.ts.map +1 -0
- package/dist/session/migrations.js +88 -0
- package/dist/session/migrations.js.map +1 -0
- package/dist/session/mutex.d.ts +7 -0
- package/dist/session/mutex.d.ts.map +1 -0
- package/dist/session/mutex.js +27 -0
- package/dist/session/mutex.js.map +1 -0
- package/dist/session/rows.d.ts +17 -0
- package/dist/session/rows.d.ts.map +1 -0
- package/dist/session/rows.js +52 -0
- package/dist/session/rows.js.map +1 -0
- package/dist/session/schema-setup.d.ts +21 -0
- package/dist/session/schema-setup.d.ts.map +1 -0
- package/dist/session/schema-setup.js +227 -0
- package/dist/session/schema-setup.js.map +1 -0
- package/dist/session/scope.d.ts +117 -0
- package/dist/session/scope.d.ts.map +1 -0
- package/dist/session/scope.js +233 -0
- package/dist/session/scope.js.map +1 -0
- package/dist/session/write-hooks.d.ts +84 -0
- package/dist/session/write-hooks.d.ts.map +1 -0
- package/dist/session/write-hooks.js +55 -0
- package/dist/session/write-hooks.js.map +1 -0
- package/dist/values/ids.d.ts +46 -0
- package/dist/values/ids.d.ts.map +1 -0
- package/dist/values/ids.js +84 -0
- package/dist/values/ids.js.map +1 -0
- package/dist/values/int64.d.ts +33 -0
- package/dist/values/int64.d.ts.map +1 -0
- package/dist/values/int64.js +105 -0
- package/dist/values/int64.js.map +1 -0
- package/dist/values/local-date-time.d.ts +61 -0
- package/dist/values/local-date-time.d.ts.map +1 -0
- package/dist/values/local-date-time.js +122 -0
- package/dist/values/local-date-time.js.map +1 -0
- package/dist/values/sql-value.d.ts +36 -0
- package/dist/values/sql-value.d.ts.map +1 -0
- package/dist/values/sql-value.js +70 -0
- package/dist/values/sql-value.js.map +1 -0
- package/package.json +27 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
function pragmaStatements(pragmas, durability) {
|
|
2
|
+
const out = [];
|
|
3
|
+
if (pragmas.journalMode) out.push(`PRAGMA journal_mode=${pragmas.journalMode.toUpperCase()}`);
|
|
4
|
+
out.push(`PRAGMA synchronous=${'normal' === durability ? 'NORMAL' : 'FULL'}`);
|
|
5
|
+
if (void 0 !== pragmas.busyTimeoutMs) out.push(`PRAGMA busy_timeout=${Math.max(0, Math.floor(pragmas.busyTimeoutMs))}`);
|
|
6
|
+
if (void 0 !== pragmas.foreignKeys) out.push(`PRAGMA foreign_keys=${pragmas.foreignKeys ? 'ON' : 'OFF'}`);
|
|
7
|
+
if (pragmas.tempStore) out.push(`PRAGMA temp_store=${pragmas.tempStore.toUpperCase()}`);
|
|
8
|
+
if (void 0 !== pragmas.cacheSize) out.push(`PRAGMA cache_size=${Math.trunc(pragmas.cacheSize)}`);
|
|
9
|
+
if (void 0 !== pragmas.mmapSize) out.push(`PRAGMA mmap_size=${Math.max(0, Math.trunc(pragmas.mmapSize))}`);
|
|
10
|
+
return out;
|
|
11
|
+
}
|
|
12
|
+
export { pragmaStatements };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"driver/types.js","sources":["../../src/driver/types.ts"],"sourcesContent":["import type { G9AbortSignal } from '@g9tm/lynxcontrols-foundation';\nimport type { G9SqlValue } from '../values/sql-value';\n\n/** One statement of a batch: SQL with `?` placeholders and its positional parameters. */\nexport interface G9DriverStatement {\n readonly sql: string;\n readonly params: readonly G9SqlValue[];\n}\n\n/** The result of one statement (plan/specs/05-Persistence.md §3). */\nexport interface G9SqlResult {\n /** Result column names in order (empty for a statement that returns no rows). */\n readonly columns: readonly string[];\n /** Row-major values in column order. */\n readonly rows: readonly (readonly G9SqlValue[])[];\n /** Rows changed by an INSERT/UPDATE/DELETE (0 otherwise). */\n readonly changes: number;\n /** Rowid of the last insert on this connection (number or int64 tag). */\n readonly lastInsertRowId: G9SqlValue;\n}\n\n/** Opaque session handle; invalid after `close` (and after a user switch the session layer performs). */\nexport type G9SessionToken = string & { readonly __g9Session: true };\n/** Opaque transaction handle; invalid after `commit`/`rollback`. */\nexport type G9TxToken = string & { readonly __g9Tx: true };\n\n/** Durability of committed writes (D13): `full` (default) survives power loss; `normal` may lose the last commits. */\nexport type G9Durability = 'full' | 'normal';\n\n/** Per-connection PRAGMA values a driver applies on open, before any statement (names are whitelisted). */\nexport interface G9ConnectionPragmas {\n readonly journalMode?: 'wal' | 'delete' | 'truncate' | 'memory';\n readonly busyTimeoutMs?: number;\n readonly foreignKeys?: boolean;\n readonly tempStore?: 'memory' | 'file' | 'default';\n /** `PRAGMA cache_size`: negative = KiB, positive = pages. */\n readonly cacheSize?: number;\n readonly mmapSize?: number;\n}\n\n/** How a driver opens a database session. */\nexport interface G9OpenOptions {\n /** Database file path, or `':memory:'`. */\n readonly path: string;\n readonly readOnly?: boolean;\n /** Create the file when it does not exist. Without it, a missing file fails with `not-found`. */\n readonly create?: boolean;\n readonly durability?: G9Durability;\n readonly pragmas?: G9ConnectionPragmas;\n}\n\n/** Options of one driver batch: transaction, cancellation, row cap and atomicity. */\nexport interface G9RunOptions {\n /** Run inside this transaction. */\n readonly tx?: G9TxToken;\n /** Cancels statements that have not started (and the rest of a batch). */\n readonly signal?: G9AbortSignal;\n /** Maximum rows any one statement may return; more fails with `too-many-rows` (never truncated). */\n readonly maxRows?: number;\n /** Without `tx`: wrap the batch in one transaction, so it applies entirely or not at all. */\n readonly atomic?: boolean;\n}\n\n/** What a driver supports (negotiated once per database). */\nexport interface G9DriverCapabilities {\n readonly sqliteVersion: string;\n /** SQLite's per-statement variable limit. */\n readonly maxVariables: number;\n readonly json1: boolean;\n readonly returning: boolean;\n readonly upsert: boolean;\n /** Whether a running statement can be interrupted (`sqlite3_interrupt`). */\n readonly interrupt: boolean;\n}\n\n/**\n * The platform boundary (plan/specs/05-Persistence.md §3): native (Android/iOS), Lynxtron (desktop) and the Node\n * reference driver implement it; `cases.json` is its contract. One `run` = one bridge round trip for N statements.\n */\nexport interface G9SqliteDriver {\n readonly name: string;\n capabilities(): Promise<G9DriverCapabilities>;\n open(options: G9OpenOptions): Promise<G9SessionToken>;\n run(\n session: G9SessionToken,\n statements: readonly G9DriverStatement[],\n options?: G9RunOptions,\n ): Promise<G9SqlResult[]>;\n begin(session: G9SessionToken, mode: 'deferred' | 'immediate'): Promise<G9TxToken>;\n commit(tx: G9TxToken): Promise<void>;\n rollback(tx: G9TxToken): Promise<void>;\n close(session: G9SessionToken): Promise<void>;\n}\n\n/** The PRAGMA statements for {@link G9ConnectionPragmas}, in application order (for drivers). */\nexport function pragmaStatements(pragmas: G9ConnectionPragmas, durability: G9Durability | undefined): string[] {\n const out: string[] = [];\n if (pragmas.journalMode) out.push(`PRAGMA journal_mode=${pragmas.journalMode.toUpperCase()}`);\n out.push(`PRAGMA synchronous=${durability === 'normal' ? 'NORMAL' : 'FULL'}`);\n if (pragmas.busyTimeoutMs !== undefined)\n out.push(`PRAGMA busy_timeout=${Math.max(0, Math.floor(pragmas.busyTimeoutMs))}`);\n if (pragmas.foreignKeys !== undefined) out.push(`PRAGMA foreign_keys=${pragmas.foreignKeys ? 'ON' : 'OFF'}`);\n if (pragmas.tempStore) out.push(`PRAGMA temp_store=${pragmas.tempStore.toUpperCase()}`);\n if (pragmas.cacheSize !== undefined) out.push(`PRAGMA cache_size=${Math.trunc(pragmas.cacheSize)}`);\n if (pragmas.mmapSize !== undefined) out.push(`PRAGMA mmap_size=${Math.max(0, Math.trunc(pragmas.mmapSize))}`);\n return out;\n}\n"],"names":["pragmaStatements","pragmas","durability","out","undefined","Math"],"mappings":"AA+FO,SAASA,iBAAiBC,OAA4B,EAAEC,UAAoC;IACjG,MAAMC,MAAgB,EAAE;IACxB,IAAIF,QAAQ,WAAW,EAAEE,IAAI,IAAI,CAAC,CAAC,oBAAoB,EAAEF,QAAQ,WAAW,CAAC,WAAW,IAAI;IAC5FE,IAAI,IAAI,CAAC,CAAC,mBAAmB,EAAED,AAAe,aAAfA,aAA0B,WAAW,QAAQ;IAC5E,IAAID,AAA0BG,WAA1BH,QAAQ,aAAa,EACvBE,IAAI,IAAI,CAAC,CAAC,oBAAoB,EAAEE,KAAK,GAAG,CAAC,GAAGA,KAAK,KAAK,CAACJ,QAAQ,aAAa,IAAI;IAClF,IAAIA,AAAwBG,WAAxBH,QAAQ,WAAW,EAAgBE,IAAI,IAAI,CAAC,CAAC,oBAAoB,EAAEF,QAAQ,WAAW,GAAG,OAAO,OAAO;IAC3G,IAAIA,QAAQ,SAAS,EAAEE,IAAI,IAAI,CAAC,CAAC,kBAAkB,EAAEF,QAAQ,SAAS,CAAC,WAAW,IAAI;IACtF,IAAIA,AAAsBG,WAAtBH,QAAQ,SAAS,EAAgBE,IAAI,IAAI,CAAC,CAAC,kBAAkB,EAAEE,KAAK,KAAK,CAACJ,QAAQ,SAAS,GAAG;IAClG,IAAIA,AAAqBG,WAArBH,QAAQ,QAAQ,EAAgBE,IAAI,IAAI,CAAC,CAAC,iBAAiB,EAAEE,KAAK,GAAG,CAAC,GAAGA,KAAK,KAAK,CAACJ,QAAQ,QAAQ,IAAI;IAC5G,OAAOE;AACT"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { G9Error } from '@g9tm/lynxcontrols-foundation';
|
|
2
|
+
/**
|
|
3
|
+
* Why a SQLite operation failed (plan/specs/05-Persistence.md §3). Stable; switch on it.
|
|
4
|
+
*
|
|
5
|
+
* - `outcome-unknown`: the transport failed around a commit. The write may or may not be durable: reconcile (by
|
|
6
|
+
* operation id), never blindly retry.
|
|
7
|
+
* - `too-many-rows`: a statement produced more rows than `maxRows` allowed. Rows are never truncated silently.
|
|
8
|
+
* - `not-found`: the database file does not exist and `create` was not requested.
|
|
9
|
+
*/
|
|
10
|
+
export type G9SqliteErrorCode = 'busy' | 'locked' | 'constraint' | 'corrupt' | 'readonly' | 'full' | 'cancelled' | 'interrupted' | 'misuse' | 'not-found' | 'outcome-unknown' | 'too-many-rows' | 'vetoed' | 'other';
|
|
11
|
+
/** Extra facts about a {@link G9SqliteError}. */
|
|
12
|
+
export interface G9SqliteErrorDetails {
|
|
13
|
+
/** SQLite's (extended) result code, when the engine produced one. */
|
|
14
|
+
readonly sqliteCode?: number;
|
|
15
|
+
/** The failing statement's SQL, when known. Parameters are never included (they may be private data). */
|
|
16
|
+
readonly sql?: string;
|
|
17
|
+
/** Statements of a non-atomic batch that completed before the failure. */
|
|
18
|
+
readonly completedStatements?: number;
|
|
19
|
+
/** The underlying error. */
|
|
20
|
+
readonly cause?: unknown;
|
|
21
|
+
}
|
|
22
|
+
/** Every failure of `@g9tm/lynxcontrols-sqlite` and its drivers. */
|
|
23
|
+
export declare class G9SqliteError extends G9Error {
|
|
24
|
+
readonly code: G9SqliteErrorCode;
|
|
25
|
+
readonly sqliteCode: number | undefined;
|
|
26
|
+
readonly sql: string | undefined;
|
|
27
|
+
readonly completedStatements: number | undefined;
|
|
28
|
+
/** The underlying error (also set as the standard `cause` property where the runtime reads it). */
|
|
29
|
+
readonly innerError: unknown;
|
|
30
|
+
constructor(code: G9SqliteErrorCode, message: string, details?: G9SqliteErrorDetails);
|
|
31
|
+
}
|
|
32
|
+
/** `true` for a {@link G9SqliteError}, optionally of one of the given codes. */
|
|
33
|
+
export declare function isG9SqliteError(error: unknown, ...codes: G9SqliteErrorCode[]): error is G9SqliteError;
|
|
34
|
+
/**
|
|
35
|
+
* Maps a SQLite (extended) result code to a {@link G9SqliteErrorCode}. The primary code is the low byte
|
|
36
|
+
* (https://sqlite.org/rescode.html).
|
|
37
|
+
*/
|
|
38
|
+
export declare function sqliteErrorCodeFor(resultCode: number): G9SqliteErrorCode;
|
|
39
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAExD;;;;;;;GAOG;AACH,MAAM,MAAM,iBAAiB,GACzB,MAAM,GACN,QAAQ,GACR,YAAY,GACZ,SAAS,GACT,UAAU,GACV,MAAM,GACN,WAAW,GACX,aAAa,GACb,QAAQ,GACR,WAAW,GACX,iBAAiB,GACjB,eAAe,GACf,QAAQ,GACR,OAAO,CAAC;AAEZ,iDAAiD;AACjD,MAAM,WAAW,oBAAoB;IACnC,qEAAqE;IACrE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,yGAAyG;IACzG,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,0EAA0E;IAC1E,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IACtC,4BAA4B;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,oEAAoE;AACpE,qBAAa,aAAc,SAAQ,OAAO;IACxC,SAAkB,IAAI,EAAE,iBAAiB,CAAC;IAC1C,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,GAAG,SAAS,CAAC;IACjD,mGAAmG;IACnG,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;gBAEjB,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB;CAUzF;AAED,gFAAgF;AAChF,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,KAAK,EAAE,iBAAiB,EAAE,GAAG,KAAK,IAAI,aAAa,CAErG;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,iBAAiB,CAwBxE"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { G9Error } from "@g9tm/lynxcontrols-foundation";
|
|
2
|
+
function _define_property(obj, key, value) {
|
|
3
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
else obj[key] = value;
|
|
10
|
+
return obj;
|
|
11
|
+
}
|
|
12
|
+
class G9SqliteError extends G9Error {
|
|
13
|
+
constructor(code, message, details = {}){
|
|
14
|
+
super(code, message), _define_property(this, "code", void 0), _define_property(this, "sqliteCode", void 0), _define_property(this, "sql", void 0), _define_property(this, "completedStatements", void 0), _define_property(this, "innerError", void 0);
|
|
15
|
+
this.name = 'G9SqliteError';
|
|
16
|
+
this.code = code;
|
|
17
|
+
this.sqliteCode = details.sqliteCode;
|
|
18
|
+
this.sql = details.sql;
|
|
19
|
+
this.completedStatements = details.completedStatements;
|
|
20
|
+
this.innerError = details.cause;
|
|
21
|
+
if (void 0 !== details.cause) Object.defineProperty(this, 'cause', {
|
|
22
|
+
value: details.cause,
|
|
23
|
+
configurable: true
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function isG9SqliteError(error, ...codes) {
|
|
28
|
+
return error instanceof G9SqliteError && (0 === codes.length || codes.indexOf(error.code) >= 0);
|
|
29
|
+
}
|
|
30
|
+
function sqliteErrorCodeFor(resultCode) {
|
|
31
|
+
switch(0xff & resultCode){
|
|
32
|
+
case 5:
|
|
33
|
+
return 'busy';
|
|
34
|
+
case 6:
|
|
35
|
+
return 'locked';
|
|
36
|
+
case 19:
|
|
37
|
+
return 'constraint';
|
|
38
|
+
case 11:
|
|
39
|
+
case 26:
|
|
40
|
+
return 'corrupt';
|
|
41
|
+
case 8:
|
|
42
|
+
return 'readonly';
|
|
43
|
+
case 13:
|
|
44
|
+
return 'full';
|
|
45
|
+
case 9:
|
|
46
|
+
return 'interrupted';
|
|
47
|
+
case 21:
|
|
48
|
+
return 'misuse';
|
|
49
|
+
case 14:
|
|
50
|
+
return 'not-found';
|
|
51
|
+
default:
|
|
52
|
+
return 'other';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export { G9SqliteError, isG9SqliteError, sqliteErrorCodeFor };
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sources":["../src/errors.ts"],"sourcesContent":["import { G9Error } from '@g9tm/lynxcontrols-foundation';\n\n/**\n * Why a SQLite operation failed (plan/specs/05-Persistence.md §3). Stable; switch on it.\n *\n * - `outcome-unknown`: the transport failed around a commit. The write may or may not be durable: reconcile (by\n * operation id), never blindly retry.\n * - `too-many-rows`: a statement produced more rows than `maxRows` allowed. Rows are never truncated silently.\n * - `not-found`: the database file does not exist and `create` was not requested.\n */\nexport type G9SqliteErrorCode =\n | 'busy'\n | 'locked'\n | 'constraint'\n | 'corrupt'\n | 'readonly'\n | 'full'\n | 'cancelled'\n | 'interrupted'\n | 'misuse'\n | 'not-found'\n | 'outcome-unknown'\n | 'too-many-rows'\n | 'vetoed'\n | 'other';\n\n/** Extra facts about a {@link G9SqliteError}. */\nexport interface G9SqliteErrorDetails {\n /** SQLite's (extended) result code, when the engine produced one. */\n readonly sqliteCode?: number;\n /** The failing statement's SQL, when known. Parameters are never included (they may be private data). */\n readonly sql?: string;\n /** Statements of a non-atomic batch that completed before the failure. */\n readonly completedStatements?: number;\n /** The underlying error. */\n readonly cause?: unknown;\n}\n\n/** Every failure of `@g9tm/lynxcontrols-sqlite` and its drivers. */\nexport class G9SqliteError extends G9Error {\n override readonly code: G9SqliteErrorCode;\n readonly sqliteCode: number | undefined;\n readonly sql: string | undefined;\n readonly completedStatements: number | undefined;\n /** The underlying error (also set as the standard `cause` property where the runtime reads it). */\n readonly innerError: unknown;\n\n constructor(code: G9SqliteErrorCode, message: string, details: G9SqliteErrorDetails = {}) {\n super(code, message);\n this.name = 'G9SqliteError';\n this.code = code;\n this.sqliteCode = details.sqliteCode;\n this.sql = details.sql;\n this.completedStatements = details.completedStatements;\n this.innerError = details.cause;\n if (details.cause !== undefined) Object.defineProperty(this, 'cause', { value: details.cause, configurable: true });\n }\n}\n\n/** `true` for a {@link G9SqliteError}, optionally of one of the given codes. */\nexport function isG9SqliteError(error: unknown, ...codes: G9SqliteErrorCode[]): error is G9SqliteError {\n return error instanceof G9SqliteError && (codes.length === 0 || codes.indexOf(error.code) >= 0);\n}\n\n/**\n * Maps a SQLite (extended) result code to a {@link G9SqliteErrorCode}. The primary code is the low byte\n * (https://sqlite.org/rescode.html).\n */\nexport function sqliteErrorCodeFor(resultCode: number): G9SqliteErrorCode {\n switch (resultCode & 0xff) {\n case 5:\n return 'busy';\n case 6:\n return 'locked';\n case 19:\n return 'constraint';\n case 11:\n case 26:\n return 'corrupt';\n case 8:\n return 'readonly';\n case 13:\n return 'full';\n case 9:\n return 'interrupted';\n case 21:\n return 'misuse';\n case 14:\n return 'not-found';\n default:\n return 'other';\n }\n}\n"],"names":["G9SqliteError","G9Error","code","message","details","undefined","Object","isG9SqliteError","error","codes","sqliteErrorCodeFor","resultCode"],"mappings":";;;;;;;;;;;AAuCO,MAAMA,sBAAsBC;IAQjC,YAAYC,IAAuB,EAAEC,OAAe,EAAEC,UAAgC,CAAC,CAAC,CAAE;QACxF,KAAK,CAACF,MAAMC,UARd,uBAAkB,QAAlB,SACA,uBAAS,cAAT,SACA,uBAAS,OAAT,SACA,uBAAS,uBAAT,SAEA,uBAAS,cAAT;QAIE,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,IAAI,GAAGD;QACZ,IAAI,CAAC,UAAU,GAAGE,QAAQ,UAAU;QACpC,IAAI,CAAC,GAAG,GAAGA,QAAQ,GAAG;QACtB,IAAI,CAAC,mBAAmB,GAAGA,QAAQ,mBAAmB;QACtD,IAAI,CAAC,UAAU,GAAGA,QAAQ,KAAK;QAC/B,IAAIA,AAAkBC,WAAlBD,QAAQ,KAAK,EAAgBE,OAAO,cAAc,CAAC,IAAI,EAAE,SAAS;YAAE,OAAOF,QAAQ,KAAK;YAAE,cAAc;QAAK;IACnH;AACF;AAGO,SAASG,gBAAgBC,KAAc,EAAE,GAAGC,KAA0B;IAC3E,OAAOD,iBAAiBR,iBAAkBS,CAAAA,AAAiB,MAAjBA,MAAM,MAAM,IAAUA,MAAM,OAAO,CAACD,MAAM,IAAI,KAAK;AAC/F;AAMO,SAASE,mBAAmBC,UAAkB;IACnD,OAAQA,AAAa,OAAbA;QACN,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;QACL,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT;YACE,OAAO;IACX;AACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export * from './codecs/codecs.js';
|
|
2
|
+
export * from './contract/run-contract.js';
|
|
3
|
+
export * from './driver/types.js';
|
|
4
|
+
export * from './errors.js';
|
|
5
|
+
export * from './query/builders.js';
|
|
6
|
+
export * from './query/compile.js';
|
|
7
|
+
export * from './query/expr.js';
|
|
8
|
+
export * from './repo/audit.js';
|
|
9
|
+
export * from './repo/repository.js';
|
|
10
|
+
export * from './schema/columns.js';
|
|
11
|
+
export * from './schema/entity.js';
|
|
12
|
+
export * from './schema/policies.js';
|
|
13
|
+
export * from './session/ambient.js';
|
|
14
|
+
export type { G9CacheHandle } from './session/cache.js';
|
|
15
|
+
export type { G9BusyOptions, G9ResolvedSqliteOptions, G9SqliteOptions, G9TransactionOptions, } from './session/database.js';
|
|
16
|
+
export * from './session/locator.js';
|
|
17
|
+
export * from './session/migrations.js';
|
|
18
|
+
export { createIndexSql, createTableSql, indexName } from './session/schema-setup.js';
|
|
19
|
+
export { createG9Sqlite, G9Sqlite, G9SqliteScope, G9SqliteTransaction } from './session/scope.js';
|
|
20
|
+
export * from './session/write-hooks.js';
|
|
21
|
+
export * from './values/ids.js';
|
|
22
|
+
export * from './values/int64.js';
|
|
23
|
+
export * from './values/local-date-time.js';
|
|
24
|
+
export * from './values/sql-value.js';
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,YAAY,EACV,aAAa,EACb,uBAAuB,EACvB,eAAe,EACf,oBAAoB,GACrB,MAAM,oBAAoB,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC/F,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export * from "./codecs/codecs.js";
|
|
2
|
+
export * from "./contract/run-contract.js";
|
|
3
|
+
export * from "./driver/types.js";
|
|
4
|
+
export * from "./errors.js";
|
|
5
|
+
export * from "./query/builders.js";
|
|
6
|
+
export * from "./query/compile.js";
|
|
7
|
+
export * from "./query/expr.js";
|
|
8
|
+
export * from "./repo/audit.js";
|
|
9
|
+
export * from "./repo/repository.js";
|
|
10
|
+
export * from "./schema/columns.js";
|
|
11
|
+
export * from "./schema/entity.js";
|
|
12
|
+
export * from "./schema/policies.js";
|
|
13
|
+
export * from "./session/ambient.js";
|
|
14
|
+
export * from "./session/locator.js";
|
|
15
|
+
export * from "./session/migrations.js";
|
|
16
|
+
export * from "./session/write-hooks.js";
|
|
17
|
+
export * from "./values/ids.js";
|
|
18
|
+
export * from "./values/int64.js";
|
|
19
|
+
export * from "./values/local-date-time.js";
|
|
20
|
+
export * from "./values/sql-value.js";
|
|
21
|
+
export { createIndexSql, createTableSql, indexName } from "./session/schema-setup.js";
|
|
22
|
+
export { G9Sqlite, G9SqliteScope, G9SqliteTransaction, createG9Sqlite } from "./session/scope.js";
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { type G9Codec, type G9CodecContext } from '../codecs/codecs.js';
|
|
2
|
+
import type { G9EntityDescriptor, G9RefsOf, G9Row } from '../schema/entity.js';
|
|
3
|
+
import type { G9SqlValue } from '../values/sql-value.js';
|
|
4
|
+
import { type G9CompileContext, type G9SqlFragment } from './compile.js';
|
|
5
|
+
import { type G9ColumnRef, type G9Expr, type G9Predicate } from './expr.js';
|
|
6
|
+
/** A built statement: SQL with `?` placeholders and its parameters (MAUI `SqlStatement`). */
|
|
7
|
+
export interface G9SqlStatement {
|
|
8
|
+
readonly sql: string;
|
|
9
|
+
readonly params: readonly G9SqlValue[];
|
|
10
|
+
}
|
|
11
|
+
/** MAUI `SqlStatement.InlinedSql`: the statement with literals inlined, for logs only. */
|
|
12
|
+
export declare function inlinedSql(statement: G9SqlStatement): string;
|
|
13
|
+
/** How the rows of a built SELECT decode. */
|
|
14
|
+
export type G9ResultShape = {
|
|
15
|
+
readonly kind: 'entity';
|
|
16
|
+
readonly entity: G9EntityDescriptor;
|
|
17
|
+
} | {
|
|
18
|
+
readonly kind: 'projection';
|
|
19
|
+
readonly columns: readonly {
|
|
20
|
+
alias: string;
|
|
21
|
+
codec: G9Codec<unknown> | undefined;
|
|
22
|
+
}[];
|
|
23
|
+
} | {
|
|
24
|
+
readonly kind: 'raw';
|
|
25
|
+
};
|
|
26
|
+
/** Settings for building a statement outside a database (MAUI's static factory read process-wide settings). */
|
|
27
|
+
export interface G9BuildOptions {
|
|
28
|
+
readonly codec?: G9CodecContext;
|
|
29
|
+
/** The culture used by `withCulture()` with no key (MAUI: the current UI culture's two-letter name, capitalised). */
|
|
30
|
+
readonly defaultCulture?: () => string;
|
|
31
|
+
readonly maxInListParameters?: number;
|
|
32
|
+
/** Bypass every entity's always-filter (`db.unfiltered`). Soft delete is governed per query. */
|
|
33
|
+
readonly bypassFilters?: boolean;
|
|
34
|
+
}
|
|
35
|
+
type Selector<E> = (refs: G9RefsOf<E>) => G9ColumnRef | readonly G9ColumnRef[];
|
|
36
|
+
/** Row type of a projection: a record of columns/expressions maps key by key; a column or list is keyed by name. */
|
|
37
|
+
export type G9Projection<P> = P extends G9ColumnRef | readonly G9ColumnRef[] ? Record<string, unknown> : {
|
|
38
|
+
-readonly [K in keyof P]: P[K] extends G9ColumnRef<infer T> ? T : unknown;
|
|
39
|
+
};
|
|
40
|
+
type AnyEntity = G9EntityDescriptor;
|
|
41
|
+
type JoinType = 'LEFT JOIN' | 'INNER JOIN' | 'CROSS JOIN' | 'JOIN';
|
|
42
|
+
type DeletedMode = 'exclude' | 'include' | 'only';
|
|
43
|
+
interface Join {
|
|
44
|
+
readonly type: JoinType;
|
|
45
|
+
readonly entity: AnyEntity;
|
|
46
|
+
readonly on: G9Expr;
|
|
47
|
+
}
|
|
48
|
+
/** Filters an entity contributes to a managed query: always-filter and soft-delete visibility. */
|
|
49
|
+
export declare function entityFilters(entity: AnyEntity, deleted: DeletedMode, options: G9BuildOptions): G9Predicate[];
|
|
50
|
+
declare abstract class G9BaseBuilder<E extends AnyEntity> {
|
|
51
|
+
/** @internal */ protected readonly root: E;
|
|
52
|
+
/** @internal */ protected joins: Join[];
|
|
53
|
+
/** @internal */ protected whereParts: G9Expr[];
|
|
54
|
+
/** @internal */ protected culture: string | null | 'default';
|
|
55
|
+
/** @internal */ protected localized: Set<string>;
|
|
56
|
+
/** @internal */ protected deleted: DeletedMode;
|
|
57
|
+
constructor(root: E);
|
|
58
|
+
/** @internal Entity known to this query (root or joined). */
|
|
59
|
+
protected known(entity: AnyEntity): AnyEntity;
|
|
60
|
+
/** MAUI `WithCulture`: read localized columns in this culture (default: the database's culture key). */
|
|
61
|
+
withCulture(cultureKey?: string | null): this;
|
|
62
|
+
/** MAUI `Localize`: treat these columns as localized for this query. */
|
|
63
|
+
localize<J extends AnyEntity>(entityOrSelector: J | Selector<E>, selector?: Selector<J>): this;
|
|
64
|
+
/** MAUI `Where`: adds a predicate (several calls are ANDed). With an entity first, on a joined entity. */
|
|
65
|
+
where<J extends AnyEntity>(entityOrPredicate: J | ((refs: G9RefsOf<E>) => G9Predicate), predicate?: (refs: G9RefsOf<J>) => G9Predicate): this;
|
|
66
|
+
/** MAUI `WhereLocalized`: a predicate whose columns are read localized (in `cultureKey`, or the default). */
|
|
67
|
+
whereLocalized<J extends AnyEntity>(entityOrPredicate: J | ((refs: G9RefsOf<E>) => G9Predicate), predicateOrCulture?: ((refs: G9RefsOf<J>) => G9Predicate) | string | null, cultureKey?: string | null): this;
|
|
68
|
+
/** MAUI `WhereRaw`: a raw predicate with positional parameters (outside id normalisation and codecs). */
|
|
69
|
+
whereRaw(sql: string, ...params: unknown[]): this;
|
|
70
|
+
/** Soft-deleted rows are included (N05). */
|
|
71
|
+
includeDeleted(): this;
|
|
72
|
+
/** Only soft-deleted rows (N05). */
|
|
73
|
+
onlyDeleted(): this;
|
|
74
|
+
/** @internal */
|
|
75
|
+
protected split<F>(first: unknown, second: unknown): [AnyEntity, F];
|
|
76
|
+
/** @internal */
|
|
77
|
+
protected context(options: G9BuildOptions, qualify: boolean): G9CompileContext;
|
|
78
|
+
/** @internal WHERE clause including the root entity's managed filters. */
|
|
79
|
+
protected whereClause(ctx: G9CompileContext, options: G9BuildOptions): G9SqlFragment | null;
|
|
80
|
+
}
|
|
81
|
+
/** MAUI `SqliteSelectQueryBuilder<T>` (+ the shared `SqliteQueryBuilder<T>` SELECT surface). */
|
|
82
|
+
export declare class G9SelectBuilder<E extends AnyEntity, R = G9Row<E>> extends G9BaseBuilder<E> {
|
|
83
|
+
private selectParts;
|
|
84
|
+
private groupByParts;
|
|
85
|
+
private havingPart;
|
|
86
|
+
private orderByParts;
|
|
87
|
+
private limitValue;
|
|
88
|
+
private offsetValue;
|
|
89
|
+
private distinctValue;
|
|
90
|
+
private projection;
|
|
91
|
+
/** @internal */ readonly __result: R;
|
|
92
|
+
/** MAUI `SelectAll`: every column of the root entity (decoded into rows). */
|
|
93
|
+
selectAll(): G9SelectBuilder<E, G9Row<E>>;
|
|
94
|
+
/**
|
|
95
|
+
* MAUI `Select`: a projection. A single column, a list of columns (named by property), or a record of named
|
|
96
|
+
* expressions (`{ id: x.id, total: count() }`). With an entity first, from a joined entity.
|
|
97
|
+
*/
|
|
98
|
+
select<P>(selector: (refs: G9RefsOf<E>) => P): G9SelectBuilder<E, G9Projection<P>>;
|
|
99
|
+
select<J extends AnyEntity, P>(entity: J, selector: (refs: G9RefsOf<J>) => P): G9SelectBuilder<E, G9Projection<P>>;
|
|
100
|
+
/** MAUI `SelectCount`: `COUNT(*)` as `count`. */
|
|
101
|
+
selectCount(): G9SelectBuilder<E, {
|
|
102
|
+
count: number;
|
|
103
|
+
}>;
|
|
104
|
+
/** MAUI `SelectRaw`: a raw fragment in the SELECT list (name it with `AS` in the SQL). */
|
|
105
|
+
selectRaw(sql: string, ...params: unknown[]): G9SelectBuilder<E, Record<string, unknown>>;
|
|
106
|
+
/** MAUI `SelectValue`: a constant with an alias (`selectValue(1, 'Synced')`). */
|
|
107
|
+
selectValue(value: unknown, alias: string): G9SelectBuilder<E, Record<string, unknown>>;
|
|
108
|
+
/**
|
|
109
|
+
* MAUI `SelectCoalesce`: `COALESCE(column, fallback) AS alias`. The fallback is a value, or a column of a
|
|
110
|
+
* (joined) entity given as `(entity, selector)`.
|
|
111
|
+
*/
|
|
112
|
+
selectCoalesce<J extends AnyEntity>(entity: J, column: (refs: G9RefsOf<J>) => G9ColumnRef, fallbackValue: unknown, alias: string): G9SelectBuilder<E, Record<string, unknown>>;
|
|
113
|
+
selectCoalesce<J extends AnyEntity, F extends AnyEntity>(entity: J, column: (refs: G9RefsOf<J>) => G9ColumnRef, fallbackEntity: F, fallbackColumn: (refs: G9RefsOf<F>) => G9ColumnRef, alias: string): G9SelectBuilder<E, Record<string, unknown>>;
|
|
114
|
+
/**
|
|
115
|
+
* MAUI `Join`: `join(Other, (root, other) => …)` joins the root with `Other`; `join(Left, Right, (l, r) => …)`
|
|
116
|
+
* joins a new `Right` to an already-known `Left`. Default `LEFT JOIN`. A joined entity's own filters go into the
|
|
117
|
+
* ON clause, so a LEFT JOIN stays a LEFT JOIN.
|
|
118
|
+
*/
|
|
119
|
+
join<A extends AnyEntity, B extends AnyEntity>(first: A, second: B | ((left: G9RefsOf<E>, right: G9RefsOf<A>) => G9Predicate), third?: ((left: G9RefsOf<A>, right: G9RefsOf<B>) => G9Predicate) | JoinType, joinType?: JoinType): this;
|
|
120
|
+
/** MAUI `LeftJoin`. */
|
|
121
|
+
leftJoin<A extends AnyEntity, B extends AnyEntity>(first: A, second: B | ((left: G9RefsOf<E>, right: G9RefsOf<A>) => G9Predicate), third?: (left: G9RefsOf<A>, right: G9RefsOf<B>) => G9Predicate): this;
|
|
122
|
+
/** MAUI `InnerJoin`. */
|
|
123
|
+
innerJoin<A extends AnyEntity, B extends AnyEntity>(first: A, second: B | ((left: G9RefsOf<E>, right: G9RefsOf<A>) => G9Predicate), third?: (left: G9RefsOf<A>, right: G9RefsOf<B>) => G9Predicate): this;
|
|
124
|
+
private addJoin;
|
|
125
|
+
/** MAUI `OrderBy`: ascending by one or more columns (with an entity first, of a joined entity). */
|
|
126
|
+
orderBy<J extends AnyEntity>(entityOrSelector: J | Selector<E>, selector?: Selector<J>): this;
|
|
127
|
+
/** MAUI `OrderByDescending`. */
|
|
128
|
+
orderByDescending<J extends AnyEntity>(entityOrSelector: J | Selector<E>, selector?: Selector<J>): this;
|
|
129
|
+
/** MAUI `OrderByRaw`: `orderByRaw('Name COLLATE NOCASE ASC')`. */
|
|
130
|
+
orderByRaw(sql: string): this;
|
|
131
|
+
/** MAUI `GroupBy`. */
|
|
132
|
+
groupBy<J extends AnyEntity>(entityOrSelector: J | Selector<E>, selector?: Selector<J>): this;
|
|
133
|
+
/** MAUI `Having`: `having((x) => gt(count(), 1))`. */
|
|
134
|
+
having(predicate: (refs: G9RefsOf<E>) => G9Predicate): this;
|
|
135
|
+
/** MAUI `HavingRaw`. */
|
|
136
|
+
havingRaw(sql: string, ...params: unknown[]): this;
|
|
137
|
+
/** MAUI `Limit`. */
|
|
138
|
+
limit(count: number): this;
|
|
139
|
+
/** MAUI `Offset`; without a limit it is emitted as `LIMIT -1 OFFSET n` (SQLite has no bare OFFSET). */
|
|
140
|
+
offset(count: number): this;
|
|
141
|
+
/** MAUI `Distinct`. */
|
|
142
|
+
distinct(): this;
|
|
143
|
+
/** @internal Compiles the statement and how its rows decode. */
|
|
144
|
+
compile(options?: G9BuildOptions): {
|
|
145
|
+
statement: G9SqlStatement;
|
|
146
|
+
shape: G9ResultShape;
|
|
147
|
+
};
|
|
148
|
+
/** MAUI `Build()`: `{ sql, params }`. */
|
|
149
|
+
build(options?: G9BuildOptions): G9SqlStatement;
|
|
150
|
+
/** MAUI `BuildStatement()` (same as {@link build}). */
|
|
151
|
+
buildStatement(options?: G9BuildOptions): G9SqlStatement;
|
|
152
|
+
/** MAUI `BuildInlinedSql()`: diagnostics only. */
|
|
153
|
+
buildInlinedSql(options?: G9BuildOptions): string;
|
|
154
|
+
}
|
|
155
|
+
/** One `SET` assignment. */
|
|
156
|
+
interface SetClause {
|
|
157
|
+
readonly ref: G9ColumnRef;
|
|
158
|
+
readonly value: unknown;
|
|
159
|
+
}
|
|
160
|
+
/** MAUI `SqliteUpdateQueryBuilder<T>`. */
|
|
161
|
+
export declare class G9UpdateBuilder<E extends AnyEntity> extends G9BaseBuilder<E> {
|
|
162
|
+
private sets;
|
|
163
|
+
private allRowsValue;
|
|
164
|
+
/** MAUI `Set`: `set((x) => x.status, 3)` or `set('status', 3)`. The value goes through the column's codec. */
|
|
165
|
+
set<K extends keyof G9Row<E> & string>(column: K | ((refs: G9RefsOf<E>) => G9ColumnRef), value: G9Row<E>[K] | unknown): this;
|
|
166
|
+
/** @internal Assignments so far (the repository adds audit stamps). */
|
|
167
|
+
get assignments(): readonly SetClause[];
|
|
168
|
+
/** MAUI `AllRows`: this UPDATE is meant to affect every row. */
|
|
169
|
+
allRows(): this;
|
|
170
|
+
/** @internal */
|
|
171
|
+
compile(options?: G9BuildOptions, extraSets?: readonly SetClause[]): G9SqlStatement;
|
|
172
|
+
/** MAUI `Build()`. */
|
|
173
|
+
build(options?: G9BuildOptions): G9SqlStatement;
|
|
174
|
+
/** MAUI `BuildStatement()`. */
|
|
175
|
+
buildStatement(options?: G9BuildOptions): G9SqlStatement;
|
|
176
|
+
/** MAUI `BuildInlinedSql()`. */
|
|
177
|
+
buildInlinedSql(options?: G9BuildOptions): string;
|
|
178
|
+
/** @internal The WHERE predicate (soft-delete rewrite turns a delete into an update with it). */
|
|
179
|
+
get predicateParts(): readonly G9Expr[];
|
|
180
|
+
/** @internal */
|
|
181
|
+
get isAllRows(): boolean;
|
|
182
|
+
}
|
|
183
|
+
/** MAUI `SqliteDeleteQueryBuilder<T>`. */
|
|
184
|
+
export declare class G9DeleteBuilder<E extends AnyEntity> extends G9BaseBuilder<E> {
|
|
185
|
+
private allRowsValue;
|
|
186
|
+
/** MAUI `AllRows`: this DELETE is meant to remove every row. */
|
|
187
|
+
allRows(): this;
|
|
188
|
+
/** @internal */
|
|
189
|
+
compile(options?: G9BuildOptions): G9SqlStatement;
|
|
190
|
+
/** MAUI `Build()`. */
|
|
191
|
+
build(options?: G9BuildOptions): G9SqlStatement;
|
|
192
|
+
/** MAUI `BuildStatement()`. */
|
|
193
|
+
buildStatement(options?: G9BuildOptions): G9SqlStatement;
|
|
194
|
+
/** MAUI `BuildInlinedSql()`. */
|
|
195
|
+
buildInlinedSql(options?: G9BuildOptions): string;
|
|
196
|
+
/** @internal Converts this delete into the soft-delete update of the same rows. */
|
|
197
|
+
toSoftDeleteUpdate(): G9UpdateBuilder<E>;
|
|
198
|
+
/** @internal */
|
|
199
|
+
get isAllRows(): boolean;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* MAUI `SqliteQueryFactory`: starts a builder for an entity, usable without a database (build the statement,
|
|
203
|
+
* execute it elsewhere). Repositories return the same builders from `compose()`.
|
|
204
|
+
*/
|
|
205
|
+
export declare const G9Sql: {
|
|
206
|
+
/** MAUI `Select<T>()`. */
|
|
207
|
+
readonly select: <E extends AnyEntity>(entity: E) => G9SelectBuilder<E>;
|
|
208
|
+
/** MAUI `Update<T>()`. */
|
|
209
|
+
readonly update: <E extends AnyEntity>(entity: E) => G9UpdateBuilder<E>;
|
|
210
|
+
/** MAUI `Delete<T>()`. */
|
|
211
|
+
readonly delete: <E extends AnyEntity>(entity: E) => G9DeleteBuilder<E>;
|
|
212
|
+
/** MAUI `GetTableName`. */
|
|
213
|
+
readonly tableName: (entity: AnyEntity) => string;
|
|
214
|
+
};
|
|
215
|
+
export {};
|
|
216
|
+
//# sourceMappingURL=builders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../../src/query/builders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,cAAc,EAAyB,MAAM,kBAAkB,CAAC;AAE5F,OAAO,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAKL,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAInB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAO,KAAK,WAAW,EAAE,KAAK,MAAM,EAAE,KAAK,WAAW,EAAiC,MAAM,QAAQ,CAAC;AAE7G,6FAA6F;AAC7F,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,CAAC;CACxC;AAED,0FAA0F;AAC1F,wBAAgB,UAAU,CAAC,SAAS,EAAE,cAAc,GAAG,MAAM,CAE5D;AAED,6CAA6C;AAC7C,MAAM,MAAM,aAAa,GACrB;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAA;CAAE,GAChE;IAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,CA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