@gjsify/sqlite 0.1.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.
@@ -0,0 +1,70 @@
1
+ class SqliteError extends Error {
2
+ code = "ERR_SQLITE_ERROR";
3
+ errcode;
4
+ errstr;
5
+ constructor(message, errcode = 0, errstr = "") {
6
+ super(message);
7
+ this.name = "SqliteError";
8
+ this.errcode = errcode;
9
+ this.errstr = errstr || message;
10
+ }
11
+ }
12
+ class InvalidStateError extends Error {
13
+ code = "ERR_INVALID_STATE";
14
+ constructor(message) {
15
+ super(message);
16
+ this.name = "InvalidStateError";
17
+ }
18
+ }
19
+ class InvalidArgTypeError extends TypeError {
20
+ code = "ERR_INVALID_ARG_TYPE";
21
+ constructor(message) {
22
+ super(message);
23
+ this.name = "InvalidArgTypeError";
24
+ }
25
+ }
26
+ class InvalidArgValueError extends Error {
27
+ code = "ERR_INVALID_ARG_VALUE";
28
+ constructor(message) {
29
+ super(message);
30
+ this.name = "InvalidArgValueError";
31
+ }
32
+ }
33
+ class OutOfRangeError extends RangeError {
34
+ code = "ERR_OUT_OF_RANGE";
35
+ constructor(message) {
36
+ super(message);
37
+ this.name = "OutOfRangeError";
38
+ }
39
+ }
40
+ class ConstructCallRequiredError extends TypeError {
41
+ code = "ERR_CONSTRUCT_CALL_REQUIRED";
42
+ constructor(name) {
43
+ super(`Cannot call constructor without \`new\`: ${name}`);
44
+ this.name = "ConstructCallRequiredError";
45
+ }
46
+ }
47
+ class InvalidUrlSchemeError extends TypeError {
48
+ code = "ERR_INVALID_URL_SCHEME";
49
+ constructor(message = "The URL must be of scheme file:") {
50
+ super(message);
51
+ this.name = "InvalidUrlSchemeError";
52
+ }
53
+ }
54
+ class IllegalConstructorError extends TypeError {
55
+ code = "ERR_ILLEGAL_CONSTRUCTOR";
56
+ constructor() {
57
+ super("Illegal constructor");
58
+ this.name = "IllegalConstructorError";
59
+ }
60
+ }
61
+ export {
62
+ ConstructCallRequiredError,
63
+ IllegalConstructorError,
64
+ InvalidArgTypeError,
65
+ InvalidArgValueError,
66
+ InvalidStateError,
67
+ InvalidUrlSchemeError,
68
+ OutOfRangeError,
69
+ SqliteError
70
+ };
@@ -0,0 +1,8 @@
1
+ import { DatabaseSync } from "./database-sync.js";
2
+ import { StatementSync } from "./statement-sync.js";
3
+ import { constants } from "./constants.js";
4
+ export {
5
+ DatabaseSync,
6
+ StatementSync,
7
+ constants
8
+ };
@@ -0,0 +1,114 @@
1
+ import { InvalidArgTypeError, InvalidArgValueError, InvalidStateError, SqliteError } from "./errors.js";
2
+ const MAX_INT64 = 9223372036854775807n;
3
+ const MIN_INT64 = -9223372036854775808n;
4
+ function validateBindValue(value, paramIndex) {
5
+ if (value === null || value === void 0) return;
6
+ const t = typeof value;
7
+ if (t === "number" || t === "bigint" || t === "string" || t === "boolean") return;
8
+ if (value instanceof Uint8Array || value instanceof ArrayBuffer) return;
9
+ if (ArrayBuffer.isView(value)) return;
10
+ throw new InvalidArgTypeError(
11
+ `Provided value cannot be bound to SQLite parameter ${paramIndex}.`
12
+ );
13
+ }
14
+ function setHolderValue(holder, value) {
15
+ if (value === null || value === void 0) {
16
+ holder.set_value(null);
17
+ return;
18
+ }
19
+ if (typeof value === "number") {
20
+ holder.set_value(value);
21
+ return;
22
+ }
23
+ if (typeof value === "bigint") {
24
+ if (value > MAX_INT64 || value < MIN_INT64) {
25
+ throw new InvalidArgValueError(
26
+ `BigInt value is too large to bind.`
27
+ );
28
+ }
29
+ holder.set_value(Number(value));
30
+ return;
31
+ }
32
+ if (typeof value === "string") {
33
+ holder.set_value(value);
34
+ return;
35
+ }
36
+ if (typeof value === "boolean") {
37
+ holder.set_value(value ? 1 : 0);
38
+ return;
39
+ }
40
+ if (value instanceof Uint8Array || ArrayBuffer.isView(value)) {
41
+ const bytes = value instanceof Uint8Array ? value : new Uint8Array(value.buffer);
42
+ holder.set_value(bytes);
43
+ return;
44
+ }
45
+ holder.set_value(value);
46
+ }
47
+ function bindParameters(paramSet, anonymousArgs, namedArgs, ctx) {
48
+ if (!paramSet) {
49
+ if (anonymousArgs.length > 0) {
50
+ throw new SqliteError("column index out of range", 25, "column index out of range");
51
+ }
52
+ return;
53
+ }
54
+ const holders = paramSet.get_holders();
55
+ if (namedArgs) {
56
+ const usedKeys = /* @__PURE__ */ new Set();
57
+ for (const holder of holders) {
58
+ const id = holder.get_id();
59
+ let value = void 0;
60
+ let found = false;
61
+ if (id in namedArgs) {
62
+ value = namedArgs[id];
63
+ usedKeys.add(id);
64
+ found = true;
65
+ }
66
+ if (!found && ctx.allowBareNamedParameters) {
67
+ const bareName = id.replace(/^[\$:@]/, "");
68
+ if (bareName in namedArgs) {
69
+ value = namedArgs[bareName];
70
+ usedKeys.add(bareName);
71
+ found = true;
72
+ }
73
+ }
74
+ if (!found && !ctx.allowBareNamedParameters) {
75
+ const bareName = id.replace(/^[\$:@]/, "");
76
+ if (bareName in namedArgs) {
77
+ throw new InvalidStateError(`Unknown named parameter '${bareName}'`);
78
+ }
79
+ }
80
+ if (found) {
81
+ const paramIdx = holders.indexOf(holder) + 1;
82
+ validateBindValue(value, paramIdx);
83
+ setHolderValue(holder, value);
84
+ } else {
85
+ setHolderValue(holder, null);
86
+ }
87
+ }
88
+ if (!ctx.allowUnknownNamedParameters) {
89
+ for (const key of Object.keys(namedArgs)) {
90
+ if (!usedKeys.has(key)) {
91
+ const matchesHolder = holders.some((h) => {
92
+ const id = h.get_id();
93
+ return id === key || id.replace(/^[\$:@]/, "") === key;
94
+ });
95
+ if (!matchesHolder) {
96
+ throw new InvalidStateError(`Unknown named parameter '${key}'`);
97
+ }
98
+ }
99
+ }
100
+ }
101
+ } else {
102
+ if (anonymousArgs.length > holders.length) {
103
+ throw new SqliteError("column index out of range", 25, "column index out of range");
104
+ }
105
+ for (let i = 0; i < holders.length; i++) {
106
+ const value = i < anonymousArgs.length ? anonymousArgs[i] : void 0;
107
+ validateBindValue(value, i + 1);
108
+ setHolderValue(holders[i], value ?? null);
109
+ }
110
+ }
111
+ }
112
+ export {
113
+ bindParameters
114
+ };
@@ -0,0 +1,292 @@
1
+ import Gda from "@girs/gda-6.0";
2
+ import { IllegalConstructorError, InvalidArgTypeError, InvalidArgValueError, SqliteError } from "./errors.js";
3
+ import { readAllRows, readFirstRow } from "./data-model-reader.js";
4
+ const MAX_INT64 = 9223372036854775807n;
5
+ const MIN_INT64 = -9223372036854775808n;
6
+ const INTERNAL = /* @__PURE__ */ Symbol("StatementSync.internal");
7
+ function validateBindValue(value, paramIndex) {
8
+ if (value === null) return;
9
+ const t = typeof value;
10
+ if (t === "number" || t === "bigint" || t === "string" || t === "boolean") return;
11
+ if (value instanceof Uint8Array || value instanceof ArrayBuffer) return;
12
+ if (ArrayBuffer.isView(value)) return;
13
+ throw new InvalidArgTypeError(
14
+ `Provided value cannot be bound to SQLite parameter ${paramIndex}.`
15
+ );
16
+ }
17
+ function sqlEscapeValue(value) {
18
+ if (value === null) return "NULL";
19
+ if (value === void 0) return "NULL";
20
+ if (typeof value === "number") return String(value);
21
+ if (typeof value === "boolean") return value ? "1" : "0";
22
+ if (typeof value === "bigint") {
23
+ if (value > MAX_INT64 || value < MIN_INT64) {
24
+ throw new InvalidArgValueError("BigInt value is too large to bind.");
25
+ }
26
+ return String(value);
27
+ }
28
+ if (typeof value === "string") return "'" + value.replace(/'/g, "''") + "'";
29
+ if (value instanceof Uint8Array) {
30
+ let hex = "";
31
+ for (let i = 0; i < value.length; i++) {
32
+ hex += value[i].toString(16).padStart(2, "0");
33
+ }
34
+ return "X'" + hex + "'";
35
+ }
36
+ if (ArrayBuffer.isView(value)) {
37
+ return sqlEscapeValue(new Uint8Array(value.buffer));
38
+ }
39
+ return "NULL";
40
+ }
41
+ class StatementSync {
42
+ #connection;
43
+ #sql;
44
+ #paramMap;
45
+ #readBigInts;
46
+ #returnArrays;
47
+ #allowBareNamedParameters;
48
+ #allowUnknownNamedParameters;
49
+ #parser;
50
+ constructor(sentinel, connection, sql, options, paramMap, parser) {
51
+ if (sentinel !== INTERNAL) {
52
+ throw new IllegalConstructorError();
53
+ }
54
+ this.#connection = connection;
55
+ this.#sql = sql;
56
+ this.#paramMap = paramMap;
57
+ this.#readBigInts = options.readBigInts ?? false;
58
+ this.#returnArrays = options.returnArrays ?? false;
59
+ this.#allowBareNamedParameters = options.allowBareNamedParameters ?? true;
60
+ this.#allowUnknownNamedParameters = options.allowUnknownNamedParameters ?? false;
61
+ this.#parser = parser;
62
+ }
63
+ /** @internal */
64
+ static _create(connection, sql, options, paramMap, parser) {
65
+ return new StatementSync(INTERNAL, connection, sql, options, paramMap, parser);
66
+ }
67
+ get sourceSQL() {
68
+ return this.#sql;
69
+ }
70
+ get expandedSQL() {
71
+ return this.#sql;
72
+ }
73
+ #getReadOptions() {
74
+ return {
75
+ readBigInts: this.#readBigInts,
76
+ returnArrays: this.#returnArrays
77
+ };
78
+ }
79
+ // Build the final SQL with parameter values substituted inline.
80
+ // Returns the SQL string ready for execution.
81
+ #buildSql(args) {
82
+ if (this.#paramMap.length === 0) {
83
+ if (args.length > 0) {
84
+ const hasNamedArg = args.length > 0 && args[0] !== null && typeof args[0] === "object" && !(args[0] instanceof Uint8Array) && !ArrayBuffer.isView(args[0]);
85
+ if (!hasNamedArg) {
86
+ throw new SqliteError("column index out of range", 25, "column index out of range");
87
+ }
88
+ }
89
+ return this.#sql;
90
+ }
91
+ let namedArgs = null;
92
+ let positionalArgs = args;
93
+ if (args.length > 0 && args[0] !== null && typeof args[0] === "object" && !(args[0] instanceof Uint8Array) && !ArrayBuffer.isView(args[0])) {
94
+ namedArgs = args[0];
95
+ positionalArgs = args.slice(1);
96
+ }
97
+ const values = /* @__PURE__ */ new Map();
98
+ const positionalValues = {};
99
+ if (namedArgs) {
100
+ for (const param of this.#paramMap) {
101
+ if (param.position >= 0) continue;
102
+ const origName = param.originalName;
103
+ let value = void 0;
104
+ let found = false;
105
+ if (origName in namedArgs) {
106
+ value = namedArgs[origName];
107
+ found = true;
108
+ }
109
+ if (!found && this.#allowBareNamedParameters) {
110
+ const bareName = origName.replace(/^[\$:@]/, "");
111
+ if (bareName in namedArgs) {
112
+ value = namedArgs[bareName];
113
+ found = true;
114
+ }
115
+ }
116
+ if (!found && !this.#allowBareNamedParameters) {
117
+ const bareName = origName.replace(/^[\$:@]/, "");
118
+ if (bareName in namedArgs) {
119
+ throw new SqliteError(`Unknown named parameter '${bareName}'`, 0, `Unknown named parameter '${bareName}'`);
120
+ }
121
+ }
122
+ if (found) {
123
+ validateBindValue(value, this.#paramMap.indexOf(param) + 1);
124
+ values.set(param.originalName, sqlEscapeValue(value));
125
+ } else {
126
+ values.set(param.originalName, "NULL");
127
+ }
128
+ }
129
+ const positionalParams = this.#paramMap.filter((p) => p.position >= 0);
130
+ for (let i = 0; i < positionalArgs.length; i++) {
131
+ if (i >= positionalParams.length) {
132
+ throw new SqliteError("column index out of range", 25, "column index out of range");
133
+ }
134
+ validateBindValue(positionalArgs[i], i + 1);
135
+ positionalValues[positionalParams[i].position] = sqlEscapeValue(positionalArgs[i]);
136
+ }
137
+ } else {
138
+ const positionalParams = this.#paramMap.filter((p) => p.position >= 0);
139
+ if (positionalArgs.length > positionalParams.length && positionalParams.length > 0) {
140
+ throw new SqliteError("column index out of range", 25, "column index out of range");
141
+ }
142
+ for (let i = 0; i < positionalParams.length; i++) {
143
+ if (i < positionalArgs.length) {
144
+ validateBindValue(positionalArgs[i], i + 1);
145
+ positionalValues[positionalParams[i].position] = sqlEscapeValue(positionalArgs[i]);
146
+ } else {
147
+ positionalValues[positionalParams[i].position] = "NULL";
148
+ }
149
+ }
150
+ }
151
+ let result = this.#sql;
152
+ const namedParams = this.#paramMap.filter((p) => p.position < 0).sort((a, b) => b.originalName.length - a.originalName.length);
153
+ for (const param of namedParams) {
154
+ const escaped = values.get(param.originalName) ?? "NULL";
155
+ result = result.split(param.originalName).join(escaped);
156
+ }
157
+ if (Object.keys(positionalValues).length > 0) {
158
+ let out = "";
159
+ let pIdx = 0;
160
+ let i = 0;
161
+ while (i < result.length) {
162
+ if (result[i] === "'") {
163
+ const start = i;
164
+ i++;
165
+ while (i < result.length && result[i] !== "'") {
166
+ if (result[i] === "'" && result[i + 1] === "'") {
167
+ i += 2;
168
+ continue;
169
+ }
170
+ i++;
171
+ }
172
+ if (i < result.length) i++;
173
+ out += result.substring(start, i);
174
+ continue;
175
+ }
176
+ if (result[i] === "?") {
177
+ i++;
178
+ let numStr = "";
179
+ while (i < result.length && result[i] >= "0" && result[i] <= "9") {
180
+ numStr += result[i];
181
+ i++;
182
+ }
183
+ const pos = numStr ? parseInt(numStr, 10) - 1 : pIdx;
184
+ pIdx = numStr ? pIdx : pIdx + 1;
185
+ out += pos in positionalValues ? positionalValues[pos] : "NULL";
186
+ continue;
187
+ }
188
+ out += result[i];
189
+ i++;
190
+ }
191
+ result = out;
192
+ }
193
+ return result;
194
+ }
195
+ #executeSql(sql) {
196
+ const [stmt] = this.#parser.parse_string(sql);
197
+ if (!stmt) {
198
+ throw new SqliteError("Failed to parse SQL statement");
199
+ }
200
+ const stmtType = stmt.get_statement_type();
201
+ if (stmtType === Gda.SqlStatementType.SELECT) {
202
+ return { model: this.#connection.statement_execute_select(stmt, null), isSelect: true };
203
+ }
204
+ try {
205
+ this.#connection.statement_execute_non_select(stmt, null);
206
+ return { model: null, isSelect: false };
207
+ } catch {
208
+ const model = this.#connection.statement_execute_select(stmt, null);
209
+ return { model, isSelect: true };
210
+ }
211
+ }
212
+ run(...args) {
213
+ const sql = this.#buildSql(args);
214
+ this.#executeSql(sql);
215
+ let changes = 0;
216
+ let lastInsertRowid = 0;
217
+ try {
218
+ const chModel = this.#connection.execute_select_command("SELECT changes()");
219
+ if (chModel && chModel.get_n_rows() > 0) {
220
+ changes = chModel.get_value_at(0, 0);
221
+ }
222
+ } catch {
223
+ }
224
+ try {
225
+ const ridModel = this.#connection.execute_select_command("SELECT last_insert_rowid()");
226
+ if (ridModel && ridModel.get_n_rows() > 0) {
227
+ lastInsertRowid = ridModel.get_value_at(0, 0);
228
+ }
229
+ } catch {
230
+ }
231
+ if (this.#readBigInts) {
232
+ changes = BigInt(changes);
233
+ lastInsertRowid = BigInt(lastInsertRowid);
234
+ }
235
+ return { changes, lastInsertRowid };
236
+ }
237
+ get(...args) {
238
+ const sql = this.#buildSql(args);
239
+ try {
240
+ const { model } = this.#executeSql(sql);
241
+ if (!model || model.get_n_rows() === 0) {
242
+ return void 0;
243
+ }
244
+ return readFirstRow(model, this.#getReadOptions());
245
+ } catch {
246
+ return void 0;
247
+ }
248
+ }
249
+ all(...args) {
250
+ const sql = this.#buildSql(args);
251
+ try {
252
+ const { model } = this.#executeSql(sql);
253
+ if (!model) {
254
+ return [];
255
+ }
256
+ return readAllRows(model, this.#getReadOptions());
257
+ } catch {
258
+ return [];
259
+ }
260
+ }
261
+ setReadBigInts(enabled) {
262
+ if (typeof enabled !== "boolean") {
263
+ throw new InvalidArgTypeError('The "readBigInts" argument must be a boolean.');
264
+ }
265
+ this.#readBigInts = enabled;
266
+ return void 0;
267
+ }
268
+ setReturnArrays(enabled) {
269
+ if (typeof enabled !== "boolean") {
270
+ throw new InvalidArgTypeError('The "returnArrays" argument must be a boolean.');
271
+ }
272
+ this.#returnArrays = enabled;
273
+ return void 0;
274
+ }
275
+ setAllowBareNamedParameters(enabled) {
276
+ if (typeof enabled !== "boolean") {
277
+ throw new InvalidArgTypeError('The "allowBareNamedParameters" argument must be a boolean.');
278
+ }
279
+ this.#allowBareNamedParameters = enabled;
280
+ return void 0;
281
+ }
282
+ setAllowUnknownNamedParameters(enabled) {
283
+ if (typeof enabled !== "boolean") {
284
+ throw new InvalidArgTypeError('The "allowUnknownNamedParameters" argument must be a boolean.');
285
+ }
286
+ this.#allowUnknownNamedParameters = enabled;
287
+ return void 0;
288
+ }
289
+ }
290
+ export {
291
+ StatementSync
292
+ };
File without changes
@@ -0,0 +1,92 @@
1
+ export declare const SQLITE_CHANGESET_OMIT = 0;
2
+ export declare const SQLITE_CHANGESET_REPLACE = 1;
3
+ export declare const SQLITE_CHANGESET_ABORT = 2;
4
+ export declare const SQLITE_CHANGESET_DATA = 1;
5
+ export declare const SQLITE_CHANGESET_NOTFOUND = 2;
6
+ export declare const SQLITE_CHANGESET_CONFLICT = 3;
7
+ export declare const SQLITE_CHANGESET_CONSTRAINT = 4;
8
+ export declare const SQLITE_CHANGESET_FOREIGN_KEY = 5;
9
+ export declare const SQLITE_OK = 0;
10
+ export declare const SQLITE_DENY = 1;
11
+ export declare const SQLITE_IGNORE = 2;
12
+ export declare const SQLITE_CREATE_INDEX = 1;
13
+ export declare const SQLITE_CREATE_TABLE = 2;
14
+ export declare const SQLITE_CREATE_TEMP_INDEX = 3;
15
+ export declare const SQLITE_CREATE_TEMP_TABLE = 4;
16
+ export declare const SQLITE_CREATE_TEMP_TRIGGER = 5;
17
+ export declare const SQLITE_CREATE_TEMP_VIEW = 6;
18
+ export declare const SQLITE_CREATE_TRIGGER = 7;
19
+ export declare const SQLITE_CREATE_VIEW = 8;
20
+ export declare const SQLITE_DELETE = 9;
21
+ export declare const SQLITE_DROP_INDEX = 10;
22
+ export declare const SQLITE_DROP_TABLE = 11;
23
+ export declare const SQLITE_DROP_TEMP_INDEX = 12;
24
+ export declare const SQLITE_DROP_TEMP_TABLE = 13;
25
+ export declare const SQLITE_DROP_TEMP_TRIGGER = 14;
26
+ export declare const SQLITE_DROP_TEMP_VIEW = 15;
27
+ export declare const SQLITE_DROP_TRIGGER = 16;
28
+ export declare const SQLITE_DROP_VIEW = 17;
29
+ export declare const SQLITE_INSERT = 18;
30
+ export declare const SQLITE_PRAGMA = 19;
31
+ export declare const SQLITE_READ = 20;
32
+ export declare const SQLITE_SELECT = 21;
33
+ export declare const SQLITE_TRANSACTION = 22;
34
+ export declare const SQLITE_UPDATE = 23;
35
+ export declare const SQLITE_ATTACH = 24;
36
+ export declare const SQLITE_DETACH = 25;
37
+ export declare const SQLITE_ALTER_TABLE = 26;
38
+ export declare const SQLITE_REINDEX = 27;
39
+ export declare const SQLITE_ANALYZE = 28;
40
+ export declare const SQLITE_CREATE_VTABLE = 29;
41
+ export declare const SQLITE_DROP_VTABLE = 30;
42
+ export declare const SQLITE_FUNCTION = 31;
43
+ export declare const SQLITE_SAVEPOINT = 32;
44
+ export declare const SQLITE_COPY = 0;
45
+ export declare const SQLITE_RECURSIVE = 33;
46
+ export declare const constants: {
47
+ SQLITE_CHANGESET_OMIT: number;
48
+ SQLITE_CHANGESET_REPLACE: number;
49
+ SQLITE_CHANGESET_ABORT: number;
50
+ SQLITE_CHANGESET_DATA: number;
51
+ SQLITE_CHANGESET_NOTFOUND: number;
52
+ SQLITE_CHANGESET_CONFLICT: number;
53
+ SQLITE_CHANGESET_CONSTRAINT: number;
54
+ SQLITE_CHANGESET_FOREIGN_KEY: number;
55
+ SQLITE_OK: number;
56
+ SQLITE_DENY: number;
57
+ SQLITE_IGNORE: number;
58
+ SQLITE_CREATE_INDEX: number;
59
+ SQLITE_CREATE_TABLE: number;
60
+ SQLITE_CREATE_TEMP_INDEX: number;
61
+ SQLITE_CREATE_TEMP_TABLE: number;
62
+ SQLITE_CREATE_TEMP_TRIGGER: number;
63
+ SQLITE_CREATE_TEMP_VIEW: number;
64
+ SQLITE_CREATE_TRIGGER: number;
65
+ SQLITE_CREATE_VIEW: number;
66
+ SQLITE_DELETE: number;
67
+ SQLITE_DROP_INDEX: number;
68
+ SQLITE_DROP_TABLE: number;
69
+ SQLITE_DROP_TEMP_INDEX: number;
70
+ SQLITE_DROP_TEMP_TABLE: number;
71
+ SQLITE_DROP_TEMP_TRIGGER: number;
72
+ SQLITE_DROP_TEMP_VIEW: number;
73
+ SQLITE_DROP_TRIGGER: number;
74
+ SQLITE_DROP_VIEW: number;
75
+ SQLITE_INSERT: number;
76
+ SQLITE_PRAGMA: number;
77
+ SQLITE_READ: number;
78
+ SQLITE_SELECT: number;
79
+ SQLITE_TRANSACTION: number;
80
+ SQLITE_UPDATE: number;
81
+ SQLITE_ATTACH: number;
82
+ SQLITE_DETACH: number;
83
+ SQLITE_ALTER_TABLE: number;
84
+ SQLITE_REINDEX: number;
85
+ SQLITE_ANALYZE: number;
86
+ SQLITE_CREATE_VTABLE: number;
87
+ SQLITE_DROP_VTABLE: number;
88
+ SQLITE_FUNCTION: number;
89
+ SQLITE_SAVEPOINT: number;
90
+ SQLITE_COPY: number;
91
+ SQLITE_RECURSIVE: number;
92
+ };
@@ -0,0 +1,8 @@
1
+ import Gda from '@girs/gda-6.0';
2
+ export interface ReadOptions {
3
+ readBigInts: boolean;
4
+ returnArrays: boolean;
5
+ }
6
+ export declare function readRow(model: Gda.DataModel, row: number, options: ReadOptions): Record<string, unknown> | unknown[] | undefined;
7
+ export declare function readAllRows(model: Gda.DataModel, options: ReadOptions): (Record<string, unknown> | unknown[])[];
8
+ export declare function readFirstRow(model: Gda.DataModel, options: ReadOptions): Record<string, unknown> | unknown[] | undefined;
@@ -0,0 +1,25 @@
1
+ import { StatementSync } from './statement-sync.ts';
2
+ declare const sqliteTypeSymbol: unique symbol;
3
+ interface ParamInfo {
4
+ gdaId: string;
5
+ originalName: string;
6
+ position: number;
7
+ }
8
+ export declare class DatabaseSync {
9
+ #private;
10
+ constructor(path: unknown, options?: unknown);
11
+ get [sqliteTypeSymbol](): string;
12
+ get isOpen(): boolean;
13
+ get isTransaction(): boolean;
14
+ open(): undefined;
15
+ close(): undefined;
16
+ /**
17
+ * Execute one or more SQL statements. Returns undefined.
18
+ * Named sqlExec to avoid security hook false positive on "exec" name.
19
+ */
20
+ sqlExec(sql: unknown): undefined;
21
+ prepare(sql: unknown, options?: unknown): StatementSync;
22
+ location(dbName?: unknown): string | null;
23
+ [Symbol.dispose](): void;
24
+ }
25
+ export type { ParamInfo };
@@ -0,0 +1,34 @@
1
+ export declare class SqliteError extends Error {
2
+ code: string;
3
+ errcode: number;
4
+ errstr: string;
5
+ constructor(message: string, errcode?: number, errstr?: string);
6
+ }
7
+ export declare class InvalidStateError extends Error {
8
+ code: string;
9
+ constructor(message: string);
10
+ }
11
+ export declare class InvalidArgTypeError extends TypeError {
12
+ code: string;
13
+ constructor(message: string);
14
+ }
15
+ export declare class InvalidArgValueError extends Error {
16
+ code: string;
17
+ constructor(message: string);
18
+ }
19
+ export declare class OutOfRangeError extends RangeError {
20
+ code: string;
21
+ constructor(message: string);
22
+ }
23
+ export declare class ConstructCallRequiredError extends TypeError {
24
+ code: string;
25
+ constructor(name: string);
26
+ }
27
+ export declare class InvalidUrlSchemeError extends TypeError {
28
+ code: string;
29
+ constructor(message?: string);
30
+ }
31
+ export declare class IllegalConstructorError extends TypeError {
32
+ code: string;
33
+ constructor();
34
+ }
@@ -0,0 +1,4 @@
1
+ export { DatabaseSync } from './database-sync.ts';
2
+ export { StatementSync } from './statement-sync.ts';
3
+ export { constants } from './constants.ts';
4
+ export type { DatabaseSyncOptions, StatementSyncOptions, RunResult, ColumnInfo, SQLiteValue } from './types.ts';
@@ -0,0 +1,6 @@
1
+ import Gda from '@girs/gda-6.0';
2
+ export interface BindingContext {
3
+ allowBareNamedParameters: boolean;
4
+ allowUnknownNamedParameters: boolean;
5
+ }
6
+ export declare function bindParameters(paramSet: Gda.Set | null, anonymousArgs: unknown[], namedArgs: Record<string, unknown> | null, ctx: BindingContext): void;
@@ -0,0 +1,18 @@
1
+ import Gda from '@girs/gda-6.0';
2
+ import type { RunResult, StatementSyncOptions } from './types.ts';
3
+ import type { ParamInfo } from './database-sync.ts';
4
+ export declare class StatementSync {
5
+ #private;
6
+ constructor(sentinel: symbol, connection: Gda.Connection, sql: string, options: StatementSyncOptions, paramMap: ParamInfo[], parser: Gda.SqlParser);
7
+ /** @internal */
8
+ static _create(connection: Gda.Connection, sql: string, options: StatementSyncOptions, paramMap: ParamInfo[], parser: Gda.SqlParser): StatementSync;
9
+ get sourceSQL(): string;
10
+ get expandedSQL(): string;
11
+ run(...args: unknown[]): RunResult;
12
+ get(...args: unknown[]): Record<string, unknown> | unknown[] | undefined;
13
+ all(...args: unknown[]): (Record<string, unknown> | unknown[])[];
14
+ setReadBigInts(enabled: unknown): undefined;
15
+ setReturnArrays(enabled: unknown): undefined;
16
+ setAllowBareNamedParameters(enabled: unknown): undefined;
17
+ setAllowUnknownNamedParameters(enabled: unknown): undefined;
18
+ }