@photostructure/sqlite 0.0.1 → 0.2.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/CHANGELOG.md +38 -2
- package/README.md +47 -483
- package/SECURITY.md +27 -83
- package/binding.gyp +69 -22
- package/dist/index.cjs +185 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +552 -100
- package/dist/index.d.mts +552 -100
- package/dist/index.d.ts +552 -100
- package/dist/index.mjs +183 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +51 -41
- package/prebuilds/darwin-arm64/@photostructure+sqlite.glibc.node +0 -0
- package/prebuilds/darwin-x64/@photostructure+sqlite.glibc.node +0 -0
- package/prebuilds/linux-arm64/@photostructure+sqlite.glibc.node +0 -0
- package/prebuilds/linux-arm64/@photostructure+sqlite.musl.node +0 -0
- package/prebuilds/linux-x64/@photostructure+sqlite.glibc.node +0 -0
- package/prebuilds/linux-x64/@photostructure+sqlite.musl.node +0 -0
- package/prebuilds/test_extension.so +0 -0
- package/prebuilds/win32-arm64/@photostructure+sqlite.glibc.node +0 -0
- package/prebuilds/win32-x64/@photostructure+sqlite.glibc.node +0 -0
- package/src/aggregate_function.cpp +503 -235
- package/src/aggregate_function.h +57 -42
- package/src/binding.cpp +117 -14
- package/src/dirname.ts +1 -1
- package/src/index.ts +122 -332
- package/src/lru-cache.ts +84 -0
- package/src/shims/env-inl.h +6 -15
- package/src/shims/node_errors.h +7 -1
- package/src/shims/sqlite_errors.h +168 -0
- package/src/shims/util.h +29 -4
- package/src/sql-tag-store.ts +140 -0
- package/src/sqlite_exception.h +49 -0
- package/src/sqlite_impl.cpp +736 -129
- package/src/sqlite_impl.h +84 -6
- package/src/{stack_path.ts → stack-path.ts} +7 -1
- package/src/types/aggregate-options.ts +22 -0
- package/src/types/changeset-apply-options.ts +18 -0
- package/src/types/database-sync-instance.ts +203 -0
- package/src/types/database-sync-options.ts +69 -0
- package/src/types/session-options.ts +10 -0
- package/src/types/sql-tag-store-instance.ts +51 -0
- package/src/types/sqlite-authorization-actions.ts +77 -0
- package/src/types/sqlite-authorization-results.ts +15 -0
- package/src/types/sqlite-changeset-conflict-types.ts +19 -0
- package/src/types/sqlite-changeset-resolution.ts +15 -0
- package/src/types/sqlite-open-flags.ts +50 -0
- package/src/types/statement-sync-instance.ts +73 -0
- package/src/types/user-functions-options.ts +14 -0
- package/src/upstream/node_sqlite.cc +960 -259
- package/src/upstream/node_sqlite.h +127 -2
- package/src/upstream/sqlite.js +1 -14
- package/src/upstream/sqlite3.c +4510 -1411
- package/src/upstream/sqlite3.h +390 -195
- package/src/upstream/sqlite3ext.h +7 -0
- package/src/user_function.cpp +88 -36
- package/src/user_function.h +2 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Changeset conflict type codes passed to `applyChangeset()` callbacks.
|
|
3
|
+
*
|
|
4
|
+
* These constants are compatible with `node:sqlite`.
|
|
5
|
+
*
|
|
6
|
+
* @see https://sqlite.org/session/c_changeset_conflict.html
|
|
7
|
+
*/
|
|
8
|
+
export interface SqliteChangesetConflictTypes {
|
|
9
|
+
/** Data conflict - row exists but values differ. */
|
|
10
|
+
SQLITE_CHANGESET_DATA: number;
|
|
11
|
+
/** Row not found in target database. */
|
|
12
|
+
SQLITE_CHANGESET_NOTFOUND: number;
|
|
13
|
+
/** Primary key conflict. */
|
|
14
|
+
SQLITE_CHANGESET_CONFLICT: number;
|
|
15
|
+
/** Constraint violation (NOT NULL, CHECK, etc.). */
|
|
16
|
+
SQLITE_CHANGESET_CONSTRAINT: number;
|
|
17
|
+
/** Foreign key constraint violation. */
|
|
18
|
+
SQLITE_CHANGESET_FOREIGN_KEY: number;
|
|
19
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Changeset conflict resolution return values for `applyChangeset()` callbacks.
|
|
3
|
+
*
|
|
4
|
+
* These constants are compatible with `node:sqlite`.
|
|
5
|
+
*
|
|
6
|
+
* @see https://sqlite.org/session/sqlite3changeset_apply.html
|
|
7
|
+
*/
|
|
8
|
+
export interface SqliteChangesetResolution {
|
|
9
|
+
/** Skip conflicting changes. */
|
|
10
|
+
SQLITE_CHANGESET_OMIT: number;
|
|
11
|
+
/** Replace conflicting changes. */
|
|
12
|
+
SQLITE_CHANGESET_REPLACE: number;
|
|
13
|
+
/** Abort on conflict. */
|
|
14
|
+
SQLITE_CHANGESET_ABORT: number;
|
|
15
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQLite database open flags.
|
|
3
|
+
*
|
|
4
|
+
* **Note:** These constants are an extension beyond `node:sqlite`.
|
|
5
|
+
* The `node:sqlite` module does not export `SQLITE_OPEN_*` constants.
|
|
6
|
+
*
|
|
7
|
+
* @see https://sqlite.org/c3ref/open.html
|
|
8
|
+
*/
|
|
9
|
+
export interface SqliteOpenFlags {
|
|
10
|
+
/** Open database for reading only. */
|
|
11
|
+
SQLITE_OPEN_READONLY: number;
|
|
12
|
+
/** Open database for reading and writing. */
|
|
13
|
+
SQLITE_OPEN_READWRITE: number;
|
|
14
|
+
/** Create database if it doesn't exist. */
|
|
15
|
+
SQLITE_OPEN_CREATE: number;
|
|
16
|
+
/** Delete database file on close. */
|
|
17
|
+
SQLITE_OPEN_DELETEONCLOSE: number;
|
|
18
|
+
/** Open with exclusive access. */
|
|
19
|
+
SQLITE_OPEN_EXCLUSIVE: number;
|
|
20
|
+
/** Use automatic proxy for locking. */
|
|
21
|
+
SQLITE_OPEN_AUTOPROXY: number;
|
|
22
|
+
/** Interpret filename as URI. */
|
|
23
|
+
SQLITE_OPEN_URI: number;
|
|
24
|
+
/** Open in-memory database. */
|
|
25
|
+
SQLITE_OPEN_MEMORY: number;
|
|
26
|
+
/** Open main database file. */
|
|
27
|
+
SQLITE_OPEN_MAIN_DB: number;
|
|
28
|
+
/** Open temporary database file. */
|
|
29
|
+
SQLITE_OPEN_TEMP_DB: number;
|
|
30
|
+
/** Open transient in-memory database. */
|
|
31
|
+
SQLITE_OPEN_TRANSIENT_DB: number;
|
|
32
|
+
/** Open main journal file. */
|
|
33
|
+
SQLITE_OPEN_MAIN_JOURNAL: number;
|
|
34
|
+
/** Open temporary journal file. */
|
|
35
|
+
SQLITE_OPEN_TEMP_JOURNAL: number;
|
|
36
|
+
/** Open subjournal file. */
|
|
37
|
+
SQLITE_OPEN_SUBJOURNAL: number;
|
|
38
|
+
/** Open super-journal file. */
|
|
39
|
+
SQLITE_OPEN_SUPER_JOURNAL: number;
|
|
40
|
+
/** Open without mutex. */
|
|
41
|
+
SQLITE_OPEN_NOMUTEX: number;
|
|
42
|
+
/** Open with full mutex. */
|
|
43
|
+
SQLITE_OPEN_FULLMUTEX: number;
|
|
44
|
+
/** Enable shared cache mode. */
|
|
45
|
+
SQLITE_OPEN_SHAREDCACHE: number;
|
|
46
|
+
/** Enable private cache mode. */
|
|
47
|
+
SQLITE_OPEN_PRIVATECACHE: number;
|
|
48
|
+
/** Open WAL file. */
|
|
49
|
+
SQLITE_OPEN_WAL: number;
|
|
50
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A prepared SQL statement that can be executed multiple times with different parameters.
|
|
3
|
+
* This interface represents an instance of the StatementSync class.
|
|
4
|
+
*/
|
|
5
|
+
export interface StatementSyncInstance {
|
|
6
|
+
/** The original SQL source string. */
|
|
7
|
+
readonly sourceSQL: string;
|
|
8
|
+
/** The expanded SQL string with bound parameters, if expandedSQL option was set. */
|
|
9
|
+
readonly expandedSQL: string | undefined;
|
|
10
|
+
/** Whether this statement has been finalized. */
|
|
11
|
+
readonly finalized: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* This method executes a prepared statement and returns an object.
|
|
14
|
+
* @param parameters Optional named and anonymous parameters to bind to the statement.
|
|
15
|
+
* @returns An object with the number of changes and the last insert rowid.
|
|
16
|
+
*/
|
|
17
|
+
run(...parameters: any[]): {
|
|
18
|
+
changes: number;
|
|
19
|
+
lastInsertRowid: number | bigint;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* This method executes a prepared statement and returns the first result row.
|
|
23
|
+
* @param parameters Optional named and anonymous parameters to bind to the statement.
|
|
24
|
+
* @returns The first row from the query results, or undefined if no rows.
|
|
25
|
+
*/
|
|
26
|
+
get(...parameters: any[]): any;
|
|
27
|
+
/**
|
|
28
|
+
* This method executes a prepared statement and returns all results as an array.
|
|
29
|
+
* @param parameters Optional named and anonymous parameters to bind to the statement.
|
|
30
|
+
* @returns An array of row objects from the query results.
|
|
31
|
+
*/
|
|
32
|
+
all(...parameters: any[]): any[];
|
|
33
|
+
/**
|
|
34
|
+
* This method executes a prepared statement and returns an iterable iterator of objects.
|
|
35
|
+
* Each object represents a row from the query results.
|
|
36
|
+
* @param parameters Optional named and anonymous parameters to bind to the statement.
|
|
37
|
+
* @returns An iterable iterator of row objects.
|
|
38
|
+
*/
|
|
39
|
+
iterate(...parameters: any[]): IterableIterator<any>;
|
|
40
|
+
/**
|
|
41
|
+
* Set whether to read integer values as JavaScript BigInt.
|
|
42
|
+
* @param readBigInts If true, read integers as BigInts. @default false
|
|
43
|
+
*/
|
|
44
|
+
setReadBigInts(readBigInts: boolean): void;
|
|
45
|
+
/**
|
|
46
|
+
* Set whether to allow bare named parameters in SQL.
|
|
47
|
+
* @param allowBareNamedParameters If true, allows bare named parameters. @default false
|
|
48
|
+
*/
|
|
49
|
+
setAllowBareNamedParameters(allowBareNamedParameters: boolean): void;
|
|
50
|
+
/**
|
|
51
|
+
* Set whether to allow unknown named parameters in SQL.
|
|
52
|
+
* @param enabled If true, unknown named parameters are ignored. If false, they throw an error. @default false
|
|
53
|
+
*/
|
|
54
|
+
setAllowUnknownNamedParameters(enabled: boolean): void;
|
|
55
|
+
/**
|
|
56
|
+
* Set whether to return results as arrays rather than objects.
|
|
57
|
+
* @param returnArrays If true, return results as arrays. @default false
|
|
58
|
+
*/
|
|
59
|
+
setReturnArrays(returnArrays: boolean): void;
|
|
60
|
+
/**
|
|
61
|
+
* Returns an array of objects, each representing a column in the statement's result set.
|
|
62
|
+
* Each object has a 'name' property for the column name and a 'type' property for the SQLite type.
|
|
63
|
+
* @returns Array of column metadata objects.
|
|
64
|
+
*/
|
|
65
|
+
columns(): Array<{ name: string; type?: string }>;
|
|
66
|
+
/**
|
|
67
|
+
* Finalizes the prepared statement and releases its resources.
|
|
68
|
+
* Called automatically by Symbol.dispose.
|
|
69
|
+
*/
|
|
70
|
+
finalize(): void;
|
|
71
|
+
/** Dispose of the statement resources using the explicit resource management protocol. */
|
|
72
|
+
[Symbol.dispose](): void;
|
|
73
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for creating SQLite user-defined functions.
|
|
3
|
+
* Used with `DatabaseSync.function()` to customize function behavior.
|
|
4
|
+
*/
|
|
5
|
+
export interface UserFunctionOptions {
|
|
6
|
+
/** If `true`, sets the `SQLITE_DETERMINISTIC` flag. @default false */
|
|
7
|
+
readonly deterministic?: boolean;
|
|
8
|
+
/** If `true`, sets the `SQLITE_DIRECTONLY` flag. @default false */
|
|
9
|
+
readonly directOnly?: boolean;
|
|
10
|
+
/** If `true`, converts integer arguments to `BigInt`s. @default false */
|
|
11
|
+
readonly useBigIntArguments?: boolean;
|
|
12
|
+
/** If `true`, allows function to be invoked with variable arguments. @default false */
|
|
13
|
+
readonly varargs?: boolean;
|
|
14
|
+
}
|