From c455b11ac2f63125809958994b671665b23a17cf Mon Sep 17 00:00:00 2001 From: Johannes Schickling Date: Tue, 25 Apr 2023 15:57:50 +0200 Subject: [PATCH 01/12] Add draft by @schickling --- index.d.ts | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 3 ++ 2 files changed, 106 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..fafb7b9 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,103 @@ +declare module '@sqlite.org/sqlite-wasm' { + export type TODO = any + + interface Window { + // eslint-disable-next-line @typescript-eslint/consistent-type-imports + sqlite3InitModule: (_?: TODO) => Promise + } + + export type Sqlite3 = { + oo1: { + DB: new (options?: OO1DBOptions) => DB + OpfsDb: new (filename: string, mode: string) => DB + } + opfs?: { + debug: TODO + deleteEntry: TODO + entryExists: TODO + metrics: TODO + mkdir: TODO + randomFilename: TODO + registerVfs: TODO + rootDirectory: TODO + } + capi: { + sqlite3_deserialize: TODO + [key: string]: TODO + } + wasm: { + allocFromTypedArray: (typedArray: Uint8Array) => number + [key: string]: TODO + } + } + + /** https://sqlite.org/wasm/doc/trunk/api-oo1.md#db-ctor */ + export type OO1DBOptions = { + /** @default ':memory:' */ + filename?: string + /** open-mode flags */ + flags?: string + /** name of the sqlite3_vfs to use */ + vfs?: string + } + + export declare const InitWasm: () => Promise + + export default InitWasm + + export class DB { + filename: string + pointer: TODO + + affirmOpen(): DB + + changes(total: boolean, sixtyFour: boolean): number + + exec(options: ExecOptions): TODO + exec(query: FlexibleString, options?: ExecOptions): TODO + close(): DB + export(): TODO + /** + * @example aDb.prepare("INSERT INTO foo(a) VALUES(?)").bind(123).stepFinalize(); + */ + prepare(query: FlexibleString): Stmt + + checkRc(db: TODO, resultCode: TODO) + + createFunction(): TODO + + dbFilename(): string + + dbName(): string + } + + export type ExecOptions = { + sql?: FlexibleString + bind?: Bindable + // saveSql?: TODO + + returnValue?: 'this' | 'resultRows' | 'saveSql' + + rowMode?: 'array' | 'object' | 'stmt' + + resultRows?: TODO[] + } + + export type FlexibleString = string | Uint8Array | Int8Array | string[] + + /** https://sqlite.org/wasm/doc/trunk/api-oo1.md#stmt-properties */ + export interface Stmt { + columnCount: number + parameterCount: number + pointer: TODO + + bind(bindable: Bindable): Stmt + bind(indexOrParameterName: number | string, bindable: Bindable): Stmt + + stepFinalize(): boolean + } + + export type Bindable = BindableValue[] | Record + + export type BindableValue = null | undefined | number | boolean | string | Uint8Array | Int8Array +} diff --git a/package.json b/package.json index 53f8109..14360ef 100644 --- a/package.json +++ b/package.json @@ -16,12 +16,14 @@ "main": "index.mjs", "type": "module", "files": [ + "index.d.ts", "index.mjs", "sqlite-wasm/", "src/" ], "exports": { ".": { + "types": "./index.d.ts", "import": "./index.mjs", "main": "./index.mjs", "browser": "./index.mjs" @@ -29,6 +31,7 @@ "./src/comlink.mjs": "./src/comlink.mjs", "./package.json": "./package.json" }, + "types": "./index.d.ts", "bin": { "sqlite-wasm": "bin/index.js" }, From d6a1f02dcef8832461f8a0df893a4756116703b6 Mon Sep 17 00:00:00 2001 From: mizchi Date: Thu, 4 May 2023 09:53:18 -0500 Subject: [PATCH 02/12] Base types on https://gist.github.com/mizchi/cb572eae55154ec781ced5c111621939 --- index.d.ts | 947 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 867 insertions(+), 80 deletions(-) diff --git a/index.d.ts b/index.d.ts index fafb7b9..38c88f4 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,103 +1,890 @@ -declare module '@sqlite.org/sqlite-wasm' { - export type TODO = any +declare module "@sqlite.org/sqlite-wasm" { + type InitOptions = { + print: (...msg: any[]) => void; + printErr: (...msg: any[]) => void; + }; - interface Window { - // eslint-disable-next-line @typescript-eslint/consistent-type-imports - sqlite3InitModule: (_?: TODO) => Promise - } + declare type PreparedStatement = { + db: DatabaseApi; + bind(value: any): PreparedStatement; + bind(idx: number, value: any): PreparedStatement; + bindAsBlob(value: any): any; + bindAsBlob(idx: number, value: any): any; + get(ndx: number, asType?: any): any; - export type Sqlite3 = { - oo1: { - DB: new (options?: OO1DBOptions) => DB - OpfsDb: new (filename: string, mode: string) => DB - } - opfs?: { - debug: TODO - deleteEntry: TODO - entryExists: TODO - metrics: TODO - mkdir: TODO - randomFilename: TODO - registerVfs: TODO - rootDirectory: TODO - } - capi: { - sqlite3_deserialize: TODO - [key: string]: TODO - } - wasm: { - allocFromTypedArray: (typedArray: Uint8Array) => number - [key: string]: TODO - } - } + finalize(): any; + stepFinalize(): boolean; - /** https://sqlite.org/wasm/doc/trunk/api-oo1.md#db-ctor */ - export type OO1DBOptions = { - /** @default ':memory:' */ - filename?: string - /** open-mode flags */ - flags?: string - /** name of the sqlite3_vfs to use */ - vfs?: string + // TODO + columnCount: any; + parameterCount: any; + clearBindings: any; + reset: any; + step: any; + stepReset: any; + getInt: any; + getFloat: any; + getString: any; + getBlob: any; + getJSON: any; + getColumnName: any; + getColumnNames: any; + getParamIndex: any; + pointer: number; } - export declare const InitWasm: () => Promise - - export default InitWasm + declare type ExecOptions = { + sql?: string, + bind?: Array + saveSql?: Array; + returnValue?: "this" | "resultRows"; + callback?: (result: any, stmt: PreparedStatement) => void + } - export class DB { - filename: string - pointer: TODO + type ExecThisOptions = ExecOptions & { + returnValue?: "this" | undefined; + } - affirmOpen(): DB + type ExecResultRowsOptions = ExecOptions & { + returnValue: "resultRows"; + rowMode?: 'array' | 'object' | 'stmt' + } - changes(total: boolean, sixtyFour: boolean): number + declare type DatabaseApi = { + filename: string; + pointer: number; + exec(input: string, opts?: ExecThisOptions): DatabaseApi; + exec(input: string, opts?: ExecResultRowsOptions): any; - exec(options: ExecOptions): TODO - exec(query: FlexibleString, options?: ExecOptions): TODO - close(): DB - export(): TODO - /** - * @example aDb.prepare("INSERT INTO foo(a) VALUES(?)").bind(123).stepFinalize(); - */ - prepare(query: FlexibleString): Stmt + exec(opts: ExecThisOptions): DatabaseApi; + exec(opts: ExecResultRowsOptions): any; - checkRc(db: TODO, resultCode: TODO) + // exec(opts: ExecOptions & {returnValue: "resultRows"}): any; + prepare(sql: string): PreparedStatement; - createFunction(): TODO + isOpen: () => boolean; + affirmOpen: () => DatabaseApi; + close: () => void; + changes: (total?: boolean, sixtyFour?: boolean) => number; + dbFilename: () => string; + dbName: () => string; + dbVfsName: (dbName: any) => string; + createFunction: Function; - dbFilename(): string + selectValue: Function; + selectValues: Function; + selectArray: Function; + selectObject: Function; + selectArrays: Function; + selectObjects: Function; - dbName(): string - } + openStatementCount: Function; + transaction: Function; + savepoint: Function; + checkRc: Function; + }; - export type ExecOptions = { - sql?: FlexibleString - bind?: Bindable - // saveSql?: TODO + export declare class JsStorageDb implements DatabaseApi { + constructor(mode: 'local' | 'session'); + storageSize(): number; + clearStorage(): void; + }; - returnValue?: 'this' | 'resultRows' | 'saveSql' + export declare class OpfsDatabase implements DatabaseApi { + constructor(filename: string); + }; - rowMode?: 'array' | 'object' | 'stmt' + export type Flags = "c" | "w" | "r" | "t"; + export declare class Database implements DatabaseApi { + constructor(options: { + filename: string, flags: string, vfs?: any + }); + constructor(filename: string, flags: string, vfs?: any); + }; - resultRows?: TODO[] + declare class WasmAllocError extends Error { + constructor(message: string); + toss: any; } - export type FlexibleString = string | Uint8Array | Int8Array | string[] - - /** https://sqlite.org/wasm/doc/trunk/api-oo1.md#stmt-properties */ - export interface Stmt { - columnCount: number - parameterCount: number - pointer: TODO + declare class SQLite3Error extends Error { + constructor(message: string); + } - bind(bindable: Bindable): Stmt - bind(indexOrParameterName: number | string, bindable: Bindable): Stmt + type Sqlite3Static = { + capi: CAPI; + wasm: WASM_API; + // Object Oriented API https://sqlite.org/wasm/doc/trunk/api-oo1.md + oo1: { + OpfsDb: typeof OpfsDatabase; + JsStorageDb: typeof JsStorageDb; + DB: typeof Database; + }; + opfs?: { + metrics: any; + debug: any; + getResolvedPath: any; + getDirForFilename: any; + mkdir: any; + entryExists: any; + randomFilename: any; + registerVfs: any; + treeList: any; + rmfr: any; + unlink: any; + traverse: any; + rootDirectory: any; + }; + WasmAllocError: WasmAllocError; + SQLite3Error: SQLite3Error; + config: { + exports: any; + memory: any; + bigIntEnabled: any; + debug: any; + warn: any; + error: any; + log: any; + wasmfsOpfsDir: any; + useStdAlloc: any; + allocExportName: any; + deallocExportName: any; + reallocExportName: any; + wasmOpfsDir: any; + }; + version: { + libVersion: string; + libVersionNumber: any; + sourceId: any; + downloadVersion: any; + }; + client: any; + scriptInfo: { + moduleScript: any; + isWorker: any; + location: any; + urlParams: any; + debugModule: any; + }; + initWorker1API: Function; + vfs: { + installVfs: any; + }; + vtab: { + xVtab: any; + xCursor: any; + xIndexInfo: any; + xError: any; + xRowid: any; + setupModule: any; + }; + }; - stepFinalize(): boolean - } + export default function sqlite3InitModule(opts: InitOptions): Promise; - export type Bindable = BindableValue[] | Record + // generated by Object.keys(sqlite3.capi).map(k => `${k}: any;`).join('\n') + declare type CAPI = { + sqlite3_bind_blob: any; + sqlite3_bind_text: any; + sqlite3_create_function_v2: any; + sqlite3_create_function: any; + sqlite3_create_window_function: any; + sqlite3_prepare_v3: any; + sqlite3_prepare_v2: any; + sqlite3_exec: any; + sqlite3_randomness: any; + sqlite3_wasmfs_opfs_dir: any; + sqlite3_wasmfs_filename_is_persistent: any; + sqlite3_js_db_uses_vfs: any; + sqlite3_js_vfs_list: any; + sqlite3_js_db_export: any; + sqlite3_js_db_vfs: any; + sqlite3_js_aggregate_context: any; + sqlite3_js_vfs_create_file: any; + sqlite3_db_config: any; + sqlite3_value_to_js: any; + sqlite3_values_to_js: any; + sqlite3_result_error_js: any; + sqlite3_result_js: any; + sqlite3_column_js: any; + sqlite3_preupdate_new_js: any; + sqlite3_preupdate_old_js: any; + sqlite3changeset_new_js: any; + sqlite3changeset_old_js: any; + sqlite3_aggregate_context: any; + sqlite3_bind_double: any; + sqlite3_bind_int: any; + sqlite3_bind_null: any; + sqlite3_bind_parameter_count: any; + sqlite3_bind_parameter_index: any; + sqlite3_bind_pointer: any; + sqlite3_busy_handler: any; + sqlite3_busy_timeout: any; + sqlite3_changes: any; + sqlite3_clear_bindings: any; + sqlite3_collation_needed: any; + sqlite3_column_blob: any; + sqlite3_column_bytes: any; + sqlite3_column_count: any; + sqlite3_column_double: any; + sqlite3_column_int: any; + sqlite3_column_name: any; + sqlite3_column_text: any; + sqlite3_column_type: any; + sqlite3_column_value: any; + sqlite3_commit_hook: any; + sqlite3_compileoption_get: any; + sqlite3_compileoption_used: any; + sqlite3_complete: any; + sqlite3_context_db_handle: any; + sqlite3_data_count: any; + sqlite3_db_filename: any; + sqlite3_db_handle: any; + sqlite3_db_name: any; + sqlite3_db_status: any; + sqlite3_errcode: any; + sqlite3_errmsg: any; + sqlite3_error_offset: any; + sqlite3_errstr: any; + sqlite3_expanded_sql: any; + sqlite3_extended_errcode: any; + sqlite3_extended_result_codes: any; + sqlite3_file_control: any; + sqlite3_finalize: any; + sqlite3_free: any; + sqlite3_get_auxdata: any; + sqlite3_initialize: any; + sqlite3_keyword_count: any; + sqlite3_keyword_name: any; + sqlite3_keyword_check: any; + sqlite3_libversion: any; + sqlite3_libversion_number: any; + sqlite3_limit: any; + sqlite3_malloc: any; + sqlite3_open: any; + sqlite3_open_v2: any; + sqlite3_progress_handler: any; + sqlite3_realloc: any; + sqlite3_reset: any; + sqlite3_result_blob: any; + sqlite3_result_double: any; + sqlite3_result_error: any; + sqlite3_result_error_code: any; + sqlite3_result_error_nomem: any; + sqlite3_result_error_toobig: any; + sqlite3_result_int: any; + sqlite3_result_null: any; + sqlite3_result_pointer: any; + sqlite3_result_subtype: any; + sqlite3_result_text: any; + sqlite3_result_zeroblob: any; + sqlite3_rollback_hook: any; + sqlite3_set_authorizer: any; + sqlite3_set_auxdata: any; + sqlite3_shutdown: any; + sqlite3_sourceid: any; + sqlite3_sql: any; + sqlite3_status: any; + sqlite3_step: any; + sqlite3_stmt_isexplain: any; + sqlite3_stmt_readonly: any; + sqlite3_stmt_status: any; + sqlite3_strglob: any; + sqlite3_stricmp: any; + sqlite3_strlike: any; + sqlite3_strnicmp: any; + sqlite3_table_column_metadata: any; + sqlite3_total_changes: any; + sqlite3_trace_v2: any; + sqlite3_txn_state: any; + sqlite3_uri_boolean: any; + sqlite3_uri_key: any; + sqlite3_uri_parameter: any; + sqlite3_user_data: any; + sqlite3_value_blob: any; + sqlite3_value_bytes: any; + sqlite3_value_double: any; + sqlite3_value_dup: any; + sqlite3_value_free: any; + sqlite3_value_frombind: any; + sqlite3_value_int: any; + sqlite3_value_nochange: any; + sqlite3_value_numeric_type: any; + sqlite3_value_pointer: any; + sqlite3_value_subtype: any; + sqlite3_value_text: any; + sqlite3_value_type: any; + sqlite3_vfs_find: any; + sqlite3_vfs_register: any; + sqlite3_vfs_unregister: any; + sqlite3_bind_int64: any; + sqlite3_changes64: any; + sqlite3_column_int64: any; + sqlite3_create_module: any; + sqlite3_create_module_v2: any; + sqlite3_declare_vtab: any; + sqlite3_deserialize: any; + sqlite3_drop_modules: any; + sqlite3_last_insert_rowid: any; + sqlite3_malloc64: any; + sqlite3_msize: any; + sqlite3_overload_function: any; + sqlite3_preupdate_blobwrite: any; + sqlite3_preupdate_count: any; + sqlite3_preupdate_depth: any; + sqlite3_preupdate_hook: any; + sqlite3_preupdate_new: any; + sqlite3_preupdate_old: any; + sqlite3_realloc64: any; + sqlite3_result_int64: any; + sqlite3_result_zeroblob64: any; + sqlite3_serialize: any; + sqlite3_set_last_insert_rowid: any; + sqlite3_status64: any; + sqlite3_total_changes64: any; + sqlite3_update_hook: any; + sqlite3_uri_int64: any; + sqlite3_value_int64: any; + sqlite3_vtab_collation: any; + sqlite3_vtab_distinct: any; + sqlite3_vtab_in: any; + sqlite3_vtab_in_first: any; + sqlite3_vtab_in_next: any; + sqlite3_vtab_nochange: any; + sqlite3_vtab_on_conflict: any; + sqlite3_vtab_rhs_value: any; + sqlite3changegroup_add: any; + sqlite3changegroup_add_strm: any; + sqlite3changegroup_delete: any; + sqlite3changegroup_new: any; + sqlite3changegroup_output: any; + sqlite3changegroup_output_strm: any; + sqlite3changeset_apply: any; + sqlite3changeset_apply_strm: any; + sqlite3changeset_apply_v2: any; + sqlite3changeset_apply_v2_strm: any; + sqlite3changeset_concat: any; + sqlite3changeset_concat_strm: any; + sqlite3changeset_conflict: any; + sqlite3changeset_finalize: any; + sqlite3changeset_fk_conflicts: any; + sqlite3changeset_invert: any; + sqlite3changeset_invert_strm: any; + sqlite3changeset_new: any; + sqlite3changeset_next: any; + sqlite3changeset_old: any; + sqlite3changeset_op: any; + sqlite3changeset_pk: any; + sqlite3changeset_start: any; + sqlite3changeset_start_strm: any; + sqlite3changeset_start_v2: any; + sqlite3changeset_start_v2_strm: any; + sqlite3session_attach: any; + sqlite3session_changeset: any; + sqlite3session_changeset_size: any; + sqlite3session_changeset_strm: any; + sqlite3session_config: any; + sqlite3session_create: any; + sqlite3session_diff: any; + sqlite3session_enable: any; + sqlite3session_indirect: any; + sqlite3session_isempty: any; + sqlite3session_memory_used: any; + sqlite3session_object_config: any; + sqlite3session_patchset: any; + sqlite3session_patchset_strm: any; + sqlite3session_table_filter: any; + SQLITE_ACCESS_EXISTS: any; + SQLITE_ACCESS_READWRITE: any; + SQLITE_ACCESS_READ: any; + SQLITE_DENY: any; + SQLITE_IGNORE: any; + SQLITE_CREATE_INDEX: any; + SQLITE_CREATE_TABLE: any; + SQLITE_CREATE_TEMP_INDEX: any; + SQLITE_CREATE_TEMP_TABLE: any; + SQLITE_CREATE_TEMP_TRIGGER: any; + SQLITE_CREATE_TEMP_VIEW: any; + SQLITE_CREATE_TRIGGER: any; + SQLITE_CREATE_VIEW: any; + SQLITE_DELETE: any; + SQLITE_DROP_INDEX: any; + SQLITE_DROP_TABLE: any; + SQLITE_DROP_TEMP_INDEX: any; + SQLITE_DROP_TEMP_TABLE: any; + SQLITE_DROP_TEMP_TRIGGER: any; + SQLITE_DROP_TEMP_VIEW: any; + SQLITE_DROP_TRIGGER: any; + SQLITE_DROP_VIEW: any; + SQLITE_INSERT: any; + SQLITE_PRAGMA: any; + SQLITE_READ: any; + SQLITE_SELECT: any; + SQLITE_TRANSACTION: any; + SQLITE_UPDATE: any; + SQLITE_ATTACH: any; + SQLITE_DETACH: any; + SQLITE_ALTER_TABLE: any; + SQLITE_REINDEX: any; + SQLITE_ANALYZE: any; + SQLITE_CREATE_VTABLE: any; + SQLITE_DROP_VTABLE: any; + SQLITE_FUNCTION: any; + SQLITE_SAVEPOINT: any; + SQLITE_RECURSIVE: any; + SQLITE_STATIC: any; + SQLITE_TRANSIENT: any; + SQLITE_WASM_DEALLOC: any; + SQLITE_CHANGESETSTART_INVERT: any; + SQLITE_CHANGESETAPPLY_NOSAVEPOINT: any; + SQLITE_CHANGESETAPPLY_INVERT: any; + SQLITE_CHANGESET_DATA: any; + SQLITE_CHANGESET_NOTFOUND: any; + SQLITE_CHANGESET_CONFLICT: any; + SQLITE_CHANGESET_CONSTRAINT: any; + SQLITE_CHANGESET_FOREIGN_KEY: any; + SQLITE_CHANGESET_OMIT: any; + SQLITE_CHANGESET_REPLACE: any; + SQLITE_CHANGESET_ABORT: any; + SQLITE_CONFIG_SINGLETHREAD: any; + SQLITE_CONFIG_MULTITHREAD: any; + SQLITE_CONFIG_SERIALIZED: any; + SQLITE_CONFIG_MALLOC: any; + SQLITE_CONFIG_GETMALLOC: any; + SQLITE_CONFIG_SCRATCH: any; + SQLITE_CONFIG_PAGECACHE: any; + SQLITE_CONFIG_HEAP: any; + SQLITE_CONFIG_MEMSTATUS: any; + SQLITE_CONFIG_MUTEX: any; + SQLITE_CONFIG_GETMUTEX: any; + SQLITE_CONFIG_LOOKASIDE: any; + SQLITE_CONFIG_PCACHE: any; + SQLITE_CONFIG_GETPCACHE: any; + SQLITE_CONFIG_LOG: any; + SQLITE_CONFIG_URI: any; + SQLITE_CONFIG_PCACHE2: any; + SQLITE_CONFIG_GETPCACHE2: any; + SQLITE_CONFIG_COVERING_INDEX_SCAN: any; + SQLITE_CONFIG_SQLLOG: any; + SQLITE_CONFIG_MMAP_SIZE: any; + SQLITE_CONFIG_WIN32_HEAPSIZE: any; + SQLITE_CONFIG_PCACHE_HDRSZ: any; + SQLITE_CONFIG_PMASZ: any; + SQLITE_CONFIG_STMTJRNL_SPILL: any; + SQLITE_CONFIG_SMALL_MALLOC: any; + SQLITE_CONFIG_SORTERREF_SIZE: any; + SQLITE_CONFIG_MEMDB_MAXSIZE: any; + SQLITE_INTEGER: any; + SQLITE_FLOAT: any; + SQLITE_TEXT: any; + SQLITE_BLOB: any; + SQLITE_NULL: any; + SQLITE_DBCONFIG_MAINDBNAME: any; + SQLITE_DBCONFIG_LOOKASIDE: any; + SQLITE_DBCONFIG_ENABLE_FKEY: any; + SQLITE_DBCONFIG_ENABLE_TRIGGER: any; + SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER: any; + SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION: any; + SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE: any; + SQLITE_DBCONFIG_ENABLE_QPSG: any; + SQLITE_DBCONFIG_TRIGGER_EQP: any; + SQLITE_DBCONFIG_RESET_DATABASE: any; + SQLITE_DBCONFIG_DEFENSIVE: any; + SQLITE_DBCONFIG_WRITABLE_SCHEMA: any; + SQLITE_DBCONFIG_LEGACY_ALTER_TABLE: any; + SQLITE_DBCONFIG_DQS_DML: any; + SQLITE_DBCONFIG_DQS_DDL: any; + SQLITE_DBCONFIG_ENABLE_VIEW: any; + SQLITE_DBCONFIG_LEGACY_FILE_FORMAT: any; + SQLITE_DBCONFIG_TRUSTED_SCHEMA: any; + SQLITE_DBCONFIG_MAX: any; + SQLITE_DBSTATUS_LOOKASIDE_USED: any; + SQLITE_DBSTATUS_CACHE_USED: any; + SQLITE_DBSTATUS_SCHEMA_USED: any; + SQLITE_DBSTATUS_STMT_USED: any; + SQLITE_DBSTATUS_LOOKASIDE_HIT: any; + SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE: any; + SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL: any; + SQLITE_DBSTATUS_CACHE_HIT: any; + SQLITE_DBSTATUS_CACHE_MISS: any; + SQLITE_DBSTATUS_CACHE_WRITE: any; + SQLITE_DBSTATUS_DEFERRED_FKS: any; + SQLITE_DBSTATUS_CACHE_USED_SHARED: any; + SQLITE_DBSTATUS_CACHE_SPILL: any; + SQLITE_DBSTATUS_MAX: any; + SQLITE_UTF8: any; + SQLITE_UTF16LE: any; + SQLITE_UTF16BE: any; + SQLITE_UTF16: any; + SQLITE_UTF16_ALIGNED: any; + SQLITE_FCNTL_LOCKSTATE: any; + SQLITE_FCNTL_GET_LOCKPROXYFILE: any; + SQLITE_FCNTL_SET_LOCKPROXYFILE: any; + SQLITE_FCNTL_LAST_ERRNO: any; + SQLITE_FCNTL_SIZE_HINT: any; + SQLITE_FCNTL_CHUNK_SIZE: any; + SQLITE_FCNTL_FILE_POINTER: any; + SQLITE_FCNTL_SYNC_OMITTED: any; + SQLITE_FCNTL_WIN32_AV_RETRY: any; + SQLITE_FCNTL_PERSIST_WAL: any; + SQLITE_FCNTL_OVERWRITE: any; + SQLITE_FCNTL_VFSNAME: any; + SQLITE_FCNTL_POWERSAFE_OVERWRITE: any; + SQLITE_FCNTL_PRAGMA: any; + SQLITE_FCNTL_BUSYHANDLER: any; + SQLITE_FCNTL_TEMPFILENAME: any; + SQLITE_FCNTL_MMAP_SIZE: any; + SQLITE_FCNTL_TRACE: any; + SQLITE_FCNTL_HAS_MOVED: any; + SQLITE_FCNTL_SYNC: any; + SQLITE_FCNTL_COMMIT_PHASETWO: any; + SQLITE_FCNTL_WIN32_SET_HANDLE: any; + SQLITE_FCNTL_WAL_BLOCK: any; + SQLITE_FCNTL_ZIPVFS: any; + SQLITE_FCNTL_RBU: any; + SQLITE_FCNTL_VFS_POINTER: any; + SQLITE_FCNTL_JOURNAL_POINTER: any; + SQLITE_FCNTL_WIN32_GET_HANDLE: any; + SQLITE_FCNTL_PDB: any; + SQLITE_FCNTL_BEGIN_ATOMIC_WRITE: any; + SQLITE_FCNTL_COMMIT_ATOMIC_WRITE: any; + SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE: any; + SQLITE_FCNTL_LOCK_TIMEOUT: any; + SQLITE_FCNTL_DATA_VERSION: any; + SQLITE_FCNTL_SIZE_LIMIT: any; + SQLITE_FCNTL_CKPT_DONE: any; + SQLITE_FCNTL_RESERVE_BYTES: any; + SQLITE_FCNTL_CKPT_START: any; + SQLITE_FCNTL_EXTERNAL_READER: any; + SQLITE_FCNTL_CKSM_FILE: any; + SQLITE_LOCK_NONE: any; + SQLITE_LOCK_SHARED: any; + SQLITE_LOCK_RESERVED: any; + SQLITE_LOCK_PENDING: any; + SQLITE_LOCK_EXCLUSIVE: any; + SQLITE_IOCAP_ATOMIC: any; + SQLITE_IOCAP_ATOMIC512: any; + SQLITE_IOCAP_ATOMIC1K: any; + SQLITE_IOCAP_ATOMIC2K: any; + SQLITE_IOCAP_ATOMIC4K: any; + SQLITE_IOCAP_ATOMIC8K: any; + SQLITE_IOCAP_ATOMIC16K: any; + SQLITE_IOCAP_ATOMIC32K: any; + SQLITE_IOCAP_ATOMIC64K: any; + SQLITE_IOCAP_SAFE_APPEND: any; + SQLITE_IOCAP_SEQUENTIAL: any; + SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN: any; + SQLITE_IOCAP_POWERSAFE_OVERWRITE: any; + SQLITE_IOCAP_IMMUTABLE: any; + SQLITE_IOCAP_BATCH_ATOMIC: any; + SQLITE_MAX_ALLOCATION_SIZE: any; + SQLITE_LIMIT_LENGTH: any; + SQLITE_MAX_LENGTH: any; + SQLITE_LIMIT_SQL_LENGTH: any; + SQLITE_MAX_SQL_LENGTH: any; + SQLITE_LIMIT_COLUMN: any; + SQLITE_MAX_COLUMN: any; + SQLITE_LIMIT_EXPR_DEPTH: any; + SQLITE_MAX_EXPR_DEPTH: any; + SQLITE_LIMIT_COMPOUND_SELECT: any; + SQLITE_MAX_COMPOUND_SELECT: any; + SQLITE_LIMIT_VDBE_OP: any; + SQLITE_MAX_VDBE_OP: any; + SQLITE_LIMIT_FUNCTION_ARG: any; + SQLITE_MAX_FUNCTION_ARG: any; + SQLITE_LIMIT_ATTACHED: any; + SQLITE_MAX_ATTACHED: any; + SQLITE_LIMIT_LIKE_PATTERN_LENGTH: any; + SQLITE_MAX_LIKE_PATTERN_LENGTH: any; + SQLITE_LIMIT_VARIABLE_NUMBER: any; + SQLITE_MAX_VARIABLE_NUMBER: any; + SQLITE_LIMIT_TRIGGER_DEPTH: any; + SQLITE_MAX_TRIGGER_DEPTH: any; + SQLITE_LIMIT_WORKER_THREADS: any; + SQLITE_MAX_WORKER_THREADS: any; + SQLITE_OPEN_READONLY: any; + SQLITE_OPEN_READWRITE: any; + SQLITE_OPEN_CREATE: any; + SQLITE_OPEN_URI: any; + SQLITE_OPEN_MEMORY: any; + SQLITE_OPEN_NOMUTEX: any; + SQLITE_OPEN_FULLMUTEX: any; + SQLITE_OPEN_SHAREDCACHE: any; + SQLITE_OPEN_PRIVATECACHE: any; + SQLITE_OPEN_EXRESCODE: any; + SQLITE_OPEN_NOFOLLOW: any; + SQLITE_OPEN_MAIN_DB: any; + SQLITE_OPEN_MAIN_JOURNAL: any; + SQLITE_OPEN_TEMP_DB: any; + SQLITE_OPEN_TEMP_JOURNAL: any; + SQLITE_OPEN_TRANSIENT_DB: any; + SQLITE_OPEN_SUBJOURNAL: any; + SQLITE_OPEN_SUPER_JOURNAL: any; + SQLITE_OPEN_WAL: any; + SQLITE_OPEN_DELETEONCLOSE: any; + SQLITE_OPEN_EXCLUSIVE: any; + SQLITE_PREPARE_PERSISTENT: any; + SQLITE_PREPARE_NORMALIZE: any; + SQLITE_PREPARE_NO_VTAB: any; + SQLITE_OK: any; + SQLITE_ERROR: any; + SQLITE_INTERNAL: any; + SQLITE_PERM: any; + SQLITE_ABORT: any; + SQLITE_BUSY: any; + SQLITE_LOCKED: any; + SQLITE_NOMEM: any; + SQLITE_READONLY: any; + SQLITE_INTERRUPT: any; + SQLITE_IOERR: any; + SQLITE_CORRUPT: any; + SQLITE_NOTFOUND: any; + SQLITE_FULL: any; + SQLITE_CANTOPEN: any; + SQLITE_PROTOCOL: any; + SQLITE_EMPTY: any; + SQLITE_SCHEMA: any; + SQLITE_TOOBIG: any; + SQLITE_CONSTRAINT: any; + SQLITE_MISMATCH: any; + SQLITE_MISUSE: any; + SQLITE_NOLFS: any; + SQLITE_AUTH: any; + SQLITE_FORMAT: any; + SQLITE_RANGE: any; + SQLITE_NOTADB: any; + SQLITE_NOTICE: any; + SQLITE_WARNING: any; + SQLITE_ROW: any; + SQLITE_DONE: any; + SQLITE_ERROR_MISSING_COLLSEQ: any; + SQLITE_ERROR_RETRY: any; + SQLITE_ERROR_SNAPSHOT: any; + SQLITE_IOERR_READ: any; + SQLITE_IOERR_SHORT_READ: any; + SQLITE_IOERR_WRITE: any; + SQLITE_IOERR_FSYNC: any; + SQLITE_IOERR_DIR_FSYNC: any; + SQLITE_IOERR_TRUNCATE: any; + SQLITE_IOERR_FSTAT: any; + SQLITE_IOERR_UNLOCK: any; + SQLITE_IOERR_RDLOCK: any; + SQLITE_IOERR_DELETE: any; + SQLITE_IOERR_BLOCKED: any; + SQLITE_IOERR_NOMEM: any; + SQLITE_IOERR_ACCESS: any; + SQLITE_IOERR_CHECKRESERVEDLOCK: any; + SQLITE_IOERR_LOCK: any; + SQLITE_IOERR_CLOSE: any; + SQLITE_IOERR_DIR_CLOSE: any; + SQLITE_IOERR_SHMOPEN: any; + SQLITE_IOERR_SHMSIZE: any; + SQLITE_IOERR_SHMLOCK: any; + SQLITE_IOERR_SHMMAP: any; + SQLITE_IOERR_SEEK: any; + SQLITE_IOERR_DELETE_NOENT: any; + SQLITE_IOERR_MMAP: any; + SQLITE_IOERR_GETTEMPPATH: any; + SQLITE_IOERR_CONVPATH: any; + SQLITE_IOERR_VNODE: any; + SQLITE_IOERR_AUTH: any; + SQLITE_IOERR_BEGIN_ATOMIC: any; + SQLITE_IOERR_COMMIT_ATOMIC: any; + SQLITE_IOERR_ROLLBACK_ATOMIC: any; + SQLITE_IOERR_DATA: any; + SQLITE_IOERR_CORRUPTFS: any; + SQLITE_LOCKED_SHAREDCACHE: any; + SQLITE_LOCKED_VTAB: any; + SQLITE_BUSY_RECOVERY: any; + SQLITE_BUSY_SNAPSHOT: any; + SQLITE_BUSY_TIMEOUT: any; + SQLITE_CANTOPEN_NOTEMPDIR: any; + SQLITE_CANTOPEN_ISDIR: any; + SQLITE_CANTOPEN_FULLPATH: any; + SQLITE_CANTOPEN_CONVPATH: any; + SQLITE_CANTOPEN_SYMLINK: any; + SQLITE_CORRUPT_VTAB: any; + SQLITE_CORRUPT_SEQUENCE: any; + SQLITE_CORRUPT_INDEX: any; + SQLITE_READONLY_RECOVERY: any; + SQLITE_READONLY_CANTLOCK: any; + SQLITE_READONLY_ROLLBACK: any; + SQLITE_READONLY_DBMOVED: any; + SQLITE_READONLY_CANTINIT: any; + SQLITE_READONLY_DIRECTORY: any; + SQLITE_ABORT_ROLLBACK: any; + SQLITE_CONSTRAINT_CHECK: any; + SQLITE_CONSTRAINT_COMMITHOOK: any; + SQLITE_CONSTRAINT_FOREIGNKEY: any; + SQLITE_CONSTRAINT_FUNCTION: any; + SQLITE_CONSTRAINT_NOTNULL: any; + SQLITE_CONSTRAINT_PRIMARYKEY: any; + SQLITE_CONSTRAINT_TRIGGER: any; + SQLITE_CONSTRAINT_UNIQUE: any; + SQLITE_CONSTRAINT_VTAB: any; + SQLITE_CONSTRAINT_ROWID: any; + SQLITE_CONSTRAINT_PINNED: any; + SQLITE_CONSTRAINT_DATATYPE: any; + SQLITE_NOTICE_RECOVER_WAL: any; + SQLITE_NOTICE_RECOVER_ROLLBACK: any; + SQLITE_WARNING_AUTOINDEX: any; + SQLITE_AUTH_USER: any; + SQLITE_OK_LOAD_PERMANENTLY: any; + SQLITE_STATUS_MEMORY_USED: any; + SQLITE_STATUS_PAGECACHE_USED: any; + SQLITE_STATUS_PAGECACHE_OVERFLOW: any; + SQLITE_STATUS_MALLOC_SIZE: any; + SQLITE_STATUS_PARSER_STACK: any; + SQLITE_STATUS_PAGECACHE_SIZE: any; + SQLITE_STATUS_MALLOC_COUNT: any; + SQLITE_STMTSTATUS_FULLSCAN_STEP: any; + SQLITE_STMTSTATUS_SORT: any; + SQLITE_STMTSTATUS_AUTOINDEX: any; + SQLITE_STMTSTATUS_VM_STEP: any; + SQLITE_STMTSTATUS_REPREPARE: any; + SQLITE_STMTSTATUS_RUN: any; + SQLITE_STMTSTATUS_FILTER_MISS: any; + SQLITE_STMTSTATUS_FILTER_HIT: any; + SQLITE_STMTSTATUS_MEMUSED: any; + SQLITE_SYNC_NORMAL: any; + SQLITE_SYNC_FULL: any; + SQLITE_SYNC_DATAONLY: any; + SQLITE_TRACE_STMT: any; + SQLITE_TRACE_PROFILE: any; + SQLITE_TRACE_ROW: any; + SQLITE_TRACE_CLOSE: any; + SQLITE_TXN_NONE: any; + SQLITE_TXN_READ: any; + SQLITE_TXN_WRITE: any; + SQLITE_DETERMINISTIC: any; + SQLITE_DIRECTONLY: any; + SQLITE_INNOCUOUS: any; + SQLITE_VERSION_NUMBER: any; + SQLITE_VERSION: any; + SQLITE_SOURCE_ID: any; + SQLITE_SERIALIZE_NOCOPY: any; + SQLITE_DESERIALIZE_FREEONCLOSE: any; + SQLITE_DESERIALIZE_READONLY: any; + SQLITE_DESERIALIZE_RESIZEABLE: any; + SQLITE_SESSION_CONFIG_STRMSIZE: any; + SQLITE_SESSION_OBJCONFIG_SIZE: any; + SQLITE_INDEX_SCAN_UNIQUE: any; + SQLITE_INDEX_CONSTRAINT_EQ: any; + SQLITE_INDEX_CONSTRAINT_GT: any; + SQLITE_INDEX_CONSTRAINT_LE: any; + SQLITE_INDEX_CONSTRAINT_LT: any; + SQLITE_INDEX_CONSTRAINT_GE: any; + SQLITE_INDEX_CONSTRAINT_MATCH: any; + SQLITE_INDEX_CONSTRAINT_LIKE: any; + SQLITE_INDEX_CONSTRAINT_GLOB: any; + SQLITE_INDEX_CONSTRAINT_REGEXP: any; + SQLITE_INDEX_CONSTRAINT_NE: any; + SQLITE_INDEX_CONSTRAINT_ISNOT: any; + SQLITE_INDEX_CONSTRAINT_ISNOTNULL: any; + SQLITE_INDEX_CONSTRAINT_ISNULL: any; + SQLITE_INDEX_CONSTRAINT_IS: any; + SQLITE_INDEX_CONSTRAINT_LIMIT: any; + SQLITE_INDEX_CONSTRAINT_OFFSET: any; + SQLITE_INDEX_CONSTRAINT_FUNCTION: any; + SQLITE_VTAB_CONSTRAINT_SUPPORT: any; + SQLITE_VTAB_INNOCUOUS: any; + SQLITE_VTAB_DIRECTONLY: any; + SQLITE_ROLLBACK: any; + SQLITE_FAIL: any; + SQLITE_REPLACE: any; + sqlite3_js_rc_str: any; + sqlite3_vfs: any; + sqlite3_io_methods: any; + sqlite3_file: any; + sqlite3_vtab: any; + sqlite3_vtab_cursor: any; + sqlite3_module: any; + sqlite3_index_info: any; + sqlite3_vtab_config: any; + sqlite3_close_v2: any; + sqlite3session_delete: any; + sqlite3_create_collation_v2: any; + sqlite3_create_collation: any; + sqlite3_config: any; + sqlite3_auto_extension: any; + sqlite3_cancel_auto_extension: any; + sqlite3_reset_auto_extension: any; + }; - export type BindableValue = null | undefined | number | boolean | string | Uint8Array | Int8Array -} + // generated by console.log(Object.keys(sqlite3.wasm).map(t => ` ${t}: any;`).join('\n')) + declare type WASM_API = { + ptrSizeof: any; + ptrIR: any; + bigIntEnabled: any; + exports: any; + memory: any; + alloc: any; + realloc: any; + dealloc: any; + allocFromTypedArray: any; + compileOptionUsed: any; + pstack: any; + sizeofIR: any; + heap8: any; + heap8u: any; + heap16: any; + heap16u: any; + heap32: any; + heap32u: any; + heapForSize: any; + functionTable: any; + functionEntry: any; + jsFuncToWasm: any; + installFunction: any; + scopedInstallFunction: any; + uninstallFunction: any; + peek: any; + poke: any; + peekPtr: any; + pokePtr: any; + peek8: any; + poke8: any; + peek16: any; + poke16: any; + peek32: any; + poke32: any; + peek64: any; + poke64: any; + peek32f: any; + poke32f: any; + peek64f: any; + poke64f: any; + getMemValue: any; + getPtrValue: any; + setMemValue: any; + setPtrValue: any; + isPtr32: any; + isPtr: any; + cstrlen: any; + cstrToJs: any; + jstrlen: any; + jstrcpy: any; + cstrncpy: any; + jstrToUintArray: any; + allocCString: any; + scopedAllocPush: any; + scopedAllocPop: any; + scopedAlloc: any; + scopedAllocCString: any; + scopedAllocMainArgv: any; + allocMainArgv: any; + cArgvToJs: any; + scopedAllocCall: any; + allocPtr: any; + scopedAllocPtr: any; + xGet: any; + xCall: any; + xWrap: any; + xCallWrapped: any; + sqlite3_wasm_db_reset: any; + sqlite3_wasm_db_vfs: any; + sqlite3_wasm_vfs_create_file: any; + sqlite3_wasm_vfs_unlink: any; + ctype: any; + }; +}; \ No newline at end of file From 5ef82ee886591f825e168301c2c902411dcfb410 Mon Sep 17 00:00:00 2001 From: Matt <1009003+tantaman@users.noreply.github.com> Date: Tue, 20 Jun 2023 11:04:33 -0400 Subject: [PATCH 03/12] fix index.d.ts to actually compile --- index.d.ts | 89 +++++++++++++++++++++++++++--------------------------- 1 file changed, 45 insertions(+), 44 deletions(-) diff --git a/index.d.ts b/index.d.ts index 38c88f4..85c25f0 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,10 +1,10 @@ -declare module "@sqlite.org/sqlite-wasm" { +declare module '@sqlite.org/sqlite-wasm' { type InitOptions = { print: (...msg: any[]) => void; printErr: (...msg: any[]) => void; }; - declare type PreparedStatement = { + type PreparedStatement = { db: DatabaseApi; bind(value: any): PreparedStatement; bind(idx: number, value: any): PreparedStatement; @@ -16,41 +16,41 @@ declare module "@sqlite.org/sqlite-wasm" { stepFinalize(): boolean; // TODO - columnCount: any; - parameterCount: any; - clearBindings: any; - reset: any; - step: any; - stepReset: any; - getInt: any; - getFloat: any; - getString: any; - getBlob: any; + columnCount(): number; + parameterCount(): number; + clearBindings(): any; + reset(): any; + step(): any; + stepReset(): any; + getInt(c: number): number; + getFloat(c: number): number; + getString(c: number): string; + getBlob(c: number): Uint8Array; getJSON: any; - getColumnName: any; - getColumnNames: any; + getColumnName(c: number): string; + getColumnNames(): string[]; getParamIndex: any; pointer: number; - } + }; - declare type ExecOptions = { - sql?: string, - bind?: Array + type ExecOptions = { + sql?: string; + bind?: Array; saveSql?: Array; - returnValue?: "this" | "resultRows"; - callback?: (result: any, stmt: PreparedStatement) => void - } + returnValue?: 'this' | 'resultRows'; + callback?: (result: any, stmt: PreparedStatement) => void; + }; type ExecThisOptions = ExecOptions & { - returnValue?: "this" | undefined; - } + returnValue?: 'this' | undefined; + }; type ExecResultRowsOptions = ExecOptions & { - returnValue: "resultRows"; - rowMode?: 'array' | 'object' | 'stmt' - } + returnValue: 'resultRows'; + rowMode?: 'array' | 'object' | 'stmt'; + }; - declare type DatabaseApi = { + class DatabaseApi { filename: string; pointer: number; exec(input: string, opts?: ExecThisOptions): DatabaseApi; @@ -82,32 +82,31 @@ declare module "@sqlite.org/sqlite-wasm" { transaction: Function; savepoint: Function; checkRc: Function; - }; + } - export declare class JsStorageDb implements DatabaseApi { + export class JsStorageDb extends DatabaseApi { constructor(mode: 'local' | 'session'); storageSize(): number; clearStorage(): void; - }; + } - export declare class OpfsDatabase implements DatabaseApi { + export class OpfsDatabase extends DatabaseApi { constructor(filename: string); - }; + } + + export type Flags = 'c' | 'w' | 'r' | 't'; - export type Flags = "c" | "w" | "r" | "t"; - export declare class Database implements DatabaseApi { - constructor(options: { - filename: string, flags: string, vfs?: any - }); + export class Database extends DatabaseApi { + constructor(options: { filename: string; flags: string; vfs?: any }); constructor(filename: string, flags: string, vfs?: any); - }; + } - declare class WasmAllocError extends Error { + class WasmAllocError extends Error { constructor(message: string); toss: any; } - declare class SQLite3Error extends Error { + class SQLite3Error extends Error { constructor(message: string); } @@ -180,10 +179,12 @@ declare module "@sqlite.org/sqlite-wasm" { }; }; - export default function sqlite3InitModule(opts: InitOptions): Promise; + export default function sqlite3InitModule( + opts: InitOptions, + ): Promise; // generated by Object.keys(sqlite3.capi).map(k => `${k}: any;`).join('\n') - declare type CAPI = { + type CAPI = { sqlite3_bind_blob: any; sqlite3_bind_text: any; sqlite3_create_function_v2: any; @@ -812,7 +813,7 @@ declare module "@sqlite.org/sqlite-wasm" { }; // generated by console.log(Object.keys(sqlite3.wasm).map(t => ` ${t}: any;`).join('\n')) - declare type WASM_API = { + type WASM_API = { ptrSizeof: any; ptrIR: any; bigIntEnabled: any; @@ -887,4 +888,4 @@ declare module "@sqlite.org/sqlite-wasm" { sqlite3_wasm_vfs_unlink: any; ctype: any; }; -}; \ No newline at end of file +} From bad8da70a7343e9de1846158bd2c91d190c8b0f9 Mon Sep 17 00:00:00 2001 From: Thomas Steiner Date: Sat, 1 Jul 2023 14:36:55 +0200 Subject: [PATCH 04/12] Update index.d.ts --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 85c25f0..8088f2e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -180,7 +180,7 @@ declare module '@sqlite.org/sqlite-wasm' { }; export default function sqlite3InitModule( - opts: InitOptions, + opts?: InitOptions, ): Promise; // generated by Object.keys(sqlite3.capi).map(k => `${k}: any;`).join('\n') From d1025a45045e43a665d2e895c36f8de110a35617 Mon Sep 17 00:00:00 2001 From: Johannes Baiter Date: Tue, 22 Aug 2023 13:53:40 +0200 Subject: [PATCH 05/12] Update type hints with docstrings and more API coverage. --- .prettierrc | 5 +- index.d.ts | 4599 ++++++++++++++++++++++++++++++++++++++++---------- package.json | 1 + 3 files changed, 3729 insertions(+), 876 deletions(-) diff --git a/.prettierrc b/.prettierrc index 4aa82d0..39ed235 100644 --- a/.prettierrc +++ b/.prettierrc @@ -15,5 +15,8 @@ "tabWidth": 2, "trailingComma": "all", "useTabs": false, - "vueIndentScriptAndStyle": false + "vueIndentScriptAndStyle": false, + "plugins": [ + "prettier-plugin-jsdoc" + ] } diff --git a/index.d.ts b/index.d.ts index 8088f2e..6ec7a5c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,891 +1,3740 @@ -declare module '@sqlite.org/sqlite-wasm' { - type InitOptions = { - print: (...msg: any[]) => void; - printErr: (...msg: any[]) => void; - }; +/** Types of values that can be passed to/retrieved from SQLite. */ +declare type SqlValue = + | string + | number + | null + | Uint8Array + | Int8Array + | ArrayBuffer; + +/** Internal data types supported by SQLite3. */ +declare enum SQLiteDataType { + SQLITE_INTEGER = 1, + SQLITE_FLOAT, + SQLITE_TEXT, + SQLITE_BLOB, + SQLITE_NULL, +} + +/** Specifies parameter bindings. */ +declare type BindingSpec = + | SqlValue[] + | { [paramName: string]: SqlValue } + /** Assumed to have binding index `1` */ + | SqlValue; + +/** + * Certain WASM-bound APIs, where explicitly noted, have additional string-type + * argument conversions colloquially known as "flexible strings." This support + * is generally reserved for arguments which expect SQL strings, as such strings + * are often large and frequently come from external sources, e.g. byte arrays + * loaded from local files, over XHR requests, or using `fetch()`. Functions + * which take filename strings, and simlilar "small" strings, do not use this + * feature. + */ +declare type FlexibleString = + | string + /** WASM C-string pointer, passed on to WASM as-is. */ + | WasmPointer + /** Assumed to hold UTF-8 encoded text, converted to `string` */ + | Uint8Array + | Int8Array + | ArrayBuffer + /** + * Gets converted to a string using `theArray.join('')` (i.e. concatenated + * as-is, with no space between each entry). Though JS supports multi-line + * string literals with the backtick syntax, it is frequently convenient to + * write out longer SQL constructs as arrays. + */ + | string[]; + +/** + * Prepared statements are created solely through the {@link Database#prepare} + * method. Calling the constructor directly will trigger an exception. + * + * It is important that statements be finalized in a timely manner, else clients + * risk introducing locking errors later on in their apps. + * + * By and large, clients can avoid statement lifetime issues by using the + * {@link Database#exec} method. For cases when more control or flexibility is + * needed, however, clients will need to {@link Database#prepare} statements and + * then ensure that their lifetimes are properly managed. The simplest way to do + * this is with a `try`/`finally` block, as in this example: + * + * @example + * const stmt = myDb.prepare("..."); + * try { + * ... use the stmt object ... + * } finally { + * stmt.finalize(); + * } + */ +declare class PreparedStatement { + /** Binds one more values to its bindable parameters. */ + bind(binding: BindingSpec): this; + + /** + * Binds a value to a bindable parameter. + * + * @param idx The index of the bindable parameter to bind to, **ACHTUNG**: + * 1-based! + */ + bind(idx: number, binding: SqlValue): this; + + /** + * Special case of {@link PreparedStatement#bind} which binds the given value + * using the `BLOB` binding mechanism instead of the default selected one for + * the value. Index can be the index number (**ACHTUNG**: 1-based!) or the + * string corresponding to a named parameter. + */ + bindAsBlob( + value: string | null | undefined | Uint8Array | Int8Array | ArrayBuffer, + ): this; + bindAsBlob( + idx: number | string, + value: string | null | undefined | Uint8Array | Int8Array | ArrayBuffer, + ): this; - type PreparedStatement = { - db: DatabaseApi; - bind(value: any): PreparedStatement; - bind(idx: number, value: any): PreparedStatement; - bindAsBlob(value: any): any; - bindAsBlob(idx: number, value: any): any; - get(ndx: number, asType?: any): any; - - finalize(): any; - stepFinalize(): boolean; - - // TODO - columnCount(): number; - parameterCount(): number; - clearBindings(): any; - reset(): any; - step(): any; - stepReset(): any; - getInt(c: number): number; - getFloat(c: number): number; - getString(c: number): string; - getBlob(c: number): Uint8Array; - getJSON: any; - getColumnName(c: number): string; - getColumnNames(): string[]; - getParamIndex: any; - pointer: number; + /** Clears all bound values. */ + clearBindings(): this; + + /** + * "Finalizes" this statement. This is a no-op if the statement has already + * been finalized. Returns the value of the underlying `sqlite3_finalize()` + * call (0 on success, non-0 on error) or `undefined` if the statement has + * already been finalized. It does not throw if `sqlite3_finalize()` returns + * non-0 because this function is effectively a destructor and "destructors do + * not throw." This function will throw if it is called while the statement is + * in active use via a {@link Database#exec} callback. + */ + finalize(): number | undefined; + + /** + * Fetches the value from the given 0-based column index of the current data + * row, throwing if index is out of range. + * + * Requires that {@link PreparedStatement#step} has just returned a truthy + * value, else an exception is thrown. + * + * By default it will determine the data type of the result automatically. If + * passed a second arugment, it must be one of the enumeration values for + * sqlite3 types, which are defined as members of the sqlite3 namespace: + * `SQLITE_INTEGER`, `SQLITE_FLOAT`, `SQLITE_TEXT`, `SQLITE_BLOB`. Any other + * value, except for `undefined`, will trigger an exception. Passing + * `undefined` is the same as not passing a value. It is legal to, e.g., fetch + * an integer value as a string, in which case sqlite3 will convert the value + * to a string. + * + * If the index is an array, this function behaves a differently: it assigns + * the indexes of the array, from 0 to the number of result columns, to the + * values of the corresponding result column, and returns that array: + * + * const values = stmt.get([]); + * + * This will return an array which contains one entry for each result column + * of the statement's current row.. + * + * If the index is a plain object, this function behaves even differentlier: + * it assigns the properties of the object to the values of their + * corresponding result columns: + * + * const values = stmt.get({}); + * + * This returns an object with properties named after the columns of the + * result set. Be aware that the ordering of the properties is undefined. If + * their order is important, use the array form instead. + * + * Blobs are returned as `Uint8Array` instances. + * + * Special case handling of 64-bit integers: the `Number` type is used for + * both floating point numbers and integers which are small enough to fit into + * it without loss of precision. If a larger integer is fetched, it is + * returned as a `BigInt` if that support is enabled, else it will throw an + * exception. The range of integers supported by the Number class is defined + * as: + * + * - `Number.MIN_SAFE_INTEGER = -9007199254740991` + * - `Number.MAX_SAFE_INTEGER = 9007199254740991` + */ + get(ndx: number, asType?: SQLiteDataType): SqlValue; + get(ndx: SqlValue[]): SqlValue[]; + get(ndx: { [columnName: string]: SqlValue }): { + [columnName: string]: SqlValue; }; - type ExecOptions = { - sql?: string; - bind?: Array; - saveSql?: Array; - returnValue?: 'this' | 'resultRows'; - callback?: (result: any, stmt: PreparedStatement) => void; + /** + * Equivalent to {@link PreparedStatement#get(ndx)} but coerces the result to a + * `Uint8Array`. + */ + getBlob(ndx: number): Uint8Array | null; + + /** + * Returns the result column name of the given index, or throws if index is + * out of bounds or this statement has been finalized. This may be used + * without having run {@link PreparedStatement#step()} first. + */ + getColumnName(ndx: number): string; + + /** + * If this statement potentially has result columns, this function returns an + * array of all such names. If passed an array, it is used as the target and + * all names are appended to it. Returns the target array. Throws if this + * statement cannot have result columns. `this.columnCount`, set with the + * statement is prepared, holds the number of columns. + */ + getColumnNames(target?: string[]): string[]; + + /** + * Equivalent to {@link PreparedStatement#get(ndx)} but coerces the result to a + * number. + */ + getFloat(ndx: number): number | null; + + /** + * Equivalent to {@link PreparedStatement#get(ndx)} but coerces the result to + * an integral number. + */ + getInt(ndx: number): number | null; + + /** + * Equivalent to {@link PreparedStatement#getString(ndx)} but returns passes + * the result of passing the fetched string string through `JSON.parse()`. If + * JSON parsing throws, that exception is propagated. + */ + getJSON(ndx: number): any; + + /** + * If this statement has named bindable parameters and the given name matches + * one, its 1-based bind index is returned. If no match is found, 0 is + * returned. If it has no bindable parameters, the undefined value is + * returned. + */ + getParamIndex(name: string): number | undefined; + + /** + * Equivalent to {@link PreparedStatement#get(ndx)} but coerces the result to a + * string. + */ + getString(ndx: number): string | null; + + /** + * Resets this statement so that it may be `step()`ed again from the + * beginning. Returns `this`. Throws if this statement has been finalized, if + * it may not legally be reset because it is currently being used from a + * {@link Database#exec} callback, or (as of versions 3.42.1 and 3.43) if the + * underlying call to `sqlite3_reset()` returns non-0. + * + * If passed a truthy argument then {@link PreparedStatement#clearBindings} is + * also called, otherwise any existing bindings, along with any memory + * allocated for them, are retained. + * + * In versions 3.42.0 and earlier, this function did not throw if + * `sqlite3_reset()` returns non-0, but it was discovered that throwing (or + * significant extra client-side code) is necessary in order to avoid certain + * silent failure scenarios + */ + reset(alsoClearBinds?: boolean): this; + + /** + * Steps the statement one time. If the result indicates that a row of data is + * available, a truthy value is returned. If no row of data is available, a + * falsy value is returned. Throws on error. + */ + step(): boolean; + + /** + * Functions like {@link PreparedStatement#step} except that it calls + * {@link PreparedStatement#finalize} on this statement immediately after + * stepping unless the `step()` throws. + * + * On success, it returns true if the step indicated that a row of data was + * available, else it returns false. + * + * This is intended to simplify use cases such as: + * + * ADb.prepare('INSERT INTO foo(a) VALUES(?)').bind(123).stepFinalize(); + */ + stepFinalize(): boolean; + + /** + * Functions exactly like {@link PreparedStatement#step} except that... + * + * On success, it calls {@link PreparedStatement#reset} and returns this + * object. On error, it throws and does not call reset(). + * + * This is intended to simplify constructs like: + * + * For(...) { stmt.bind(...).stepReset(); } + * + * Note that the {@link PreparedStatement#reset} call makes it illegal to call + * {@link PreparedStatement#get} after the step. + */ + stepReset(): this; + + /** + * The number of result columns this statement has, or 0 for statements which + * do not have result columns. + * + * _Minor achtung:_ for all releases > 3.42.0 this is a property interceptor + * which invokes `sqlite3_column_count`, so its use should be avoided in loops + * because of the call overhead. In versions <= 3.42.0 this value is collected + * and cached when the statement is created, but that can lead to misbehavior + * if changes are made to the database schema while this statement is active. + */ + columnCount: number; + + /** The number of bindable parameters this statement has. */ + parameterCount: number; + + /** + * WASM pointer rwhich resolves to the `sqlite3_stmt*` which this object + * wraps. This value may be passed to any WASM-bound functions which accept an + * `sqlite3_stmt*` argument. It resolves to `undefined` after this statement + * is {@link PreparedStatement#finalize}d. + */ + pointer: WasmPointer | undefined; +} + +declare type ExecOptions = { + /** + * The SQL to run (unless it's provided as the first argument). The SQL may + * contain any number of statements. + */ + sql?: FlexibleString; + + /** + * A single value valid as an argument for {@link PreparedStatement#bind}. This + * is only applied to the first non-empty statement in the SQL which has any + * bindable parameters. (Empty statements are skipped entirely.) + */ + bind?: BindingSpec; + + /** + * If set, the SQL of each executed statement is appended to this array before + * the statement is executed (but after it is prepared - we don't have the + * string until after that). Empty SQL statements are elided. + */ + saveSql?: string[]; + + /** + * A string specifying what this function should return: The default value is + * (usually) `"this"`. The exceptions is if the caller passes neither of + * `callback` nor `returnValue` but does pass an explicit `rowMode` then the + * default returnValue is `"resultRows"`, described below. The options are: + * + * - `"this"` menas that the DB object itself should be returned. + * - `"resultRows"` means to return the value of the `resultRows` option. If + * `resultRows` is not set, this function behaves as if it were set to an + * empty array. + * - `"saveSql"` means to return the value of the `saveSql` option. If `saveSql` + * is not set, this function behaves as if it were set to an empty array. + */ + returnValue?: 'this' | 'resultRows' | 'saveSql'; + + /** + * A function which gets called for each row of the result set (see `rowMode`, + * below), but only if that statement has any result rows. The callback's + * `this` is the `options` object, noting that this function will synthesize + * one if the caller does not provide one. The second argument passed to the + * callback is always the current {@link PreparedStatement} object, as it's + * needed if the caller wants to fetch the column names or some such (noting + * that they could also be fetched via `this.columnNames`, if the client + * provides the `columnNames` option). If the callback returns a literal + * `false` (as opposed to any other falsy value, e.g. an implicit undefined + * return), any ongoing statement-`step()` iteration stops without an error. + * The return value of the callback is otherwise ignored. + * + * Applies only to the first statement which has a non-zero result column + * count, regardless of whether the statement actually produces any result + * rows. + * + * **ACHTUNG:** the callback **MUST NOT** modify the {@link PreparedStatement} + * object. Calling any of the {@link PreparedStatement#get} variants, + * {@link PreparedStatement#getColumnName}, or similar, is legal, but calling + * {@link PreparedStatement#step} or {@link PreparedStatement#finalize} is not. + * Member methods which are illegal in this context will trigger an exception, + * but clients must also refrain from using any lower-level (C-style) APIs + * which might modify the statement. + */ + callback?: ( + row: + | SqlValue[] + | { [columnName: string]: SqlValue } + | PreparedStatement + | SqlValue, + stmt: PreparedStatement, + ) => void | false; + + /** + * If this is an array, the column names of the result set are stored in this + * array before the `callback` (if any) is triggered (regardless of whether + * the query produces any result rows). If no statement has result columns, + * this value is unchanged. + * + * Applies only to the first statement which has a non-zero result column + * count, regardless of whether the statement actually produces any result + * rows. + * + * **Achtung:** an SQL result may have multiple columns with identical names. + */ + columnNames?: string[]; + + /** + * If this is an array, it functions similarly to the `callback` option: each + * row of the result set (if any), with the exception that the `rowMode` + * `'stmt'` is not legal. It is legal to use both `resultRows` and callback, + * but `resultRows` is likely much simpler to use for small data sets and can + * be used over a WebWorker-style message interface. `exec()` throws if + * `resultRows` is set and rowMode is `'stmt'`. + * + * Applies only to the first statement which has a non-zero result column + * count, regardless of whether the statement actually produces any result + * rows. + */ + resultRows?: (SqlValue[] | { [columnName: string]: SqlValue } | SqlValue)[]; + + /** + * Specifies the type of he `callback`'s first argument and the type of the + * `resultRows` array entries. + */ + rowMode?: 'array' | 'object' | 'stmt' | number | string; +}; + +/** + * Derivate type of ExecOptions to be used as base mixin for method overloads on + * `exec` + */ +declare type ExecBaseOptions = Omit< + ExecOptions, + 'callback' | 'resultRows' | 'rowMode' | 'returnValue' | 'sql' +>; + +declare type ExecReturnThisOptions = { + returnValue?: 'this'; +}; + +declare type ExecReturnResultRowsOptions = { + returnValue: 'resultRows'; +}; + +declare type ExecReturnSaveSqlOptions = { + returnValue: 'saveSql'; +}; + +declare type ExecRowModeArrayOptions = { + callback?: (row: SqlValue[]) => void | false; + resultRows?: SqlValue[][]; + rowMode?: 'array'; +}; + +declare type ExecRowModeObjectOptions = { + callback?: (row: { [columnName: string]: SqlValue }) => void | false; + resultRows?: { [columnName: string]: SqlValue }[]; + rowMode: 'object'; +}; + +declare type ExecRowModeStmtOptions = { + callback?: (row: PreparedStatement) => void | false; + resultRows?: undefined; + rowMode: 'stmt'; +}; + +declare type ExecRowModeScalarOptions = { + callback?: (row: SqlValue) => void | false; + resultRows?: SqlValue[]; + + /** + * For number values: indicates a zero-based column in the result row. Only + * that one single value will be passed on. If string. For string values: A + * string with a minimum length of 2 and leading character of `$` will fetch + * the row as an object, extract that one field, and pass that field's value + * to the `callback`. Note that these keys are case-sensitive so must match + * the case used in the SQL. e.g. `"select a A from t"` with a `rowMode` of + * `'$A'` would work but `'$a'` would not. A reference to a column not in the + * result set will trigger an exception on the first row (as the check is not + * performed until rows are fetched). + */ + rowMode: number | Exclude; +}; + +/** Options for creating a user-defined function that can be called from SQL. */ +declare type FunctionOptions = { + /** + * Number of arguments which SQL calls to this function expect or require. The + * default value is `X.length` MINUS 1, where X is either `xFunc` or `xStep`, + * depending on the type of function being created. As a special case, if + * `X.length` is 0, its arity is also 0 instead of -1. A negative arity value + * means that the function is variadic and may accept any number of arguments, + * up to sqlite3's compile-time limits. sqlite3 will enforce the argument + * count if is zero or greater. The callback always receives a pointer to an + * `sqlite3_context` object as its first argument. Any arguments after that + * are from SQL code. The leading context argument does not count towards the + * function's arity. See the docs for `sqlite3_create_function()` for why that + * argument is required in the interface. + */ + arity?: number; + + /** + * Corresponds to the `SQLITE_DETERMINISTIC` flag. Setting it means that the + * new function always gives the same output when the input parameters are the + * same. The `abs()` function is deterministic, for example, but + * `randomblob()` is not. Functions must be deterministic in order to be used + * in certain contexts such as with the `WHERE` clause of partial indexes or + * in generated columns. SQLite might also optimize deterministic functions by + * factoring them out of inner loops. + */ + deterministic?: boolean; + + /** + * Corresponds to the `SQLITE_DIRECTONLY` flag. + * + * Setting it means that the function may only be invoked from top-level SQL, + * and cannot be used in `VIEW`s or `TRIGGER`s nor in schema structures such + * as `CHECK` constraints, `DEFAULT` clauses, expression indexes, partial + * indexes, or generated columns. + * + * The flag is recommended for any application-defined SQL function that has + * side-effects or that could potentially leak sensitive information. This + * will prevent attacks in which an application is tricked into using a + * database file that has had its schema surreptiously modified to invoke the + * application-defined function in ways that are harmful. + * + * Some people say it is good practice to set the flag on all + * application-defined SQL functions, regardless of whether or not they are + * security sensitive, as doing so prevents those functions from being used + * inside of the database schema, and thus ensures that the database can be + * inspected and modified using generic tools (such as the CLI) that do not + * have access to the application-defined functions. + */ + directOnly?: boolean; + + /** + * Corresponds to the `SQLITE_INNOCUOUS` flag. + * + * Setting it means that the function is unlikely to cause problems even if + * misused. An innocuous function should have no side effects and should not + * depend on any values other than its input parameters. The `abs()` function + * is an example of an innocuous function. The `load_extension()` SQL function + * is not innocuous because of its side effects. The flag is similar to + * {@link FunctionOptions#directOnly}, but is not exactly the same. The + * `random()` function is an example of a function that is innocuous but not + * deterministic. + * + * Some heightened security settings (`SQLITE_DBCONFIG_TRUSTED_SCHEMA` and + * `PRAGMA trusted_schema=OFF`) disable the use of SQL functions inside views + * and triggers and in schema structures such as `CHECK` constraints, + * `DEFAULT` clauses, expression indexes, partial indexes, and generated + * columns unless the function is tagged with `SQLITE_INNOCUOUS`. Most + * built-in functions are innocuous. Developers are advised to avoid using the + * `SQLITE_INNOCUOUS` flag for application-defined functions unless the + * function has been carefully audited and found to be free of potentially + * security-adverse side-effects and information-leaks. + */ + innocuous?: boolean; + + /** Name of the user-defined function. */ + name?: string; + + /** + * The options object may optionally have an xDestroy function-type property, + * as per `sqlite3_create_function_v2()`. Its argument will be the + * WASM-pointer-type value of the pApp property, and this function will throw + * if pApp is defined but is not null, undefined, or a numeric (WASM pointer) + * value. i.e. pApp, if set, must be value suitable for use as a WASM pointer + * argument, noting that null or undefined will translate to 0 for that + * purpose. + */ + xDestroy?: (pAppPtr: WasmPointer) => void; +}; + +declare type ScalarFunctionOptions = FunctionOptions & { + /** Scalar function to be defined. */ + xFunc: (ctxPtr: number, ...args: any[]) => any; +}; + +declare type AggregateFunctionOptions = FunctionOptions & { + /** + * 'Step' callback for an aggregate function. + * + * It is invoked to add a row to the current aggregate value. The function + * arguments, if any, corresponding to the row being added are passed to the + * implementation of {@link AggregateFunctionOptions#xStep}. + */ + xStep: (ctxPtr: number, ...rowValues: SqlValue[]) => void; + + /** + * 'Final' callback for an aggregate function. + * + * It is invoked to return the current value of the aggregate, and to free any + * resources allocated by earlier calls to + * {@link AggregateFunctionOptions#xStep}. + */ + xFinal: (ctxPtr: number) => SqlValue; +}; + +declare type WindowFunctionOptions = FunctionOptions & { + /** + * 'Step' callback for a window function. + * + * It is invoked to add a row to the current window. The function arguments, + * if any, corresponding to the row being added are passed to the + * implementation of {@link WindowFunctionOptions#xStep}. + */ + xStep: (ctxPtr: number, ...args: any[]) => void; + + /** + * 'Final' callback for a window function. + * + * It is invoked to return the current value of the aggregate (determined by + * the contents of the current window), and to free any resources allocated by + * earlier calls to {@link WindowFunctionOptions#xStep}. + */ + xFinal: (ctxPtr: number) => SqlValue; + + /** + * 'Value' callback for a window function. This method is invoked to return + * the current value of the aggregate. Unlike + * {@link WindowFunctionOptions#xFinal}, the implementation should not delete + * any context. + */ + xValue: (ctxPtr: number) => SqlValue; + + /** + * 'Inverse' callback for a window function. + * + * It is invoked to remove the oldest presently aggregated result of + * {@link WindowFunctionOptions#xStep} from the current window. The function + * arguments, if any, are those passed to {@link WindowFunctionOptions#xStep} + * for the row being removed. + */ + xInverse: (ctxPtr: number, ...args: any[]) => void; +}; + +/** + * An instance of an implementing class corresponds to one `sqlite3*` created + * using `sqlite3_open` or equivalent. + * + * @example + * ```typescript + * const db = new sqlite3.DB(); + * try { + * db.exec([ + * "create table t(a);", + * "insert into t(a) values(10),(20),(30)" + * ]); + * } finally { + * db.close(); + * } + * ```; + */ +declare class Database { + /** + * Creates a connection to the given file, optionally creating it if needed. + * + * @param options The options to use when opening the database file. + * @param options.filename The filename to open. Must be resolvable using + * whatever filesystem layer (virtual or otherwise) is set up for the + * default sqlite3 VFS. Note that the special sqlite3 db names `":memory:"` + * and `""` (temporary db) have their normal special meanings here. + * @param options.flags The flags to use when opening the file. It must be a + * string containing a sequence of letters (in any order, but case + * sensitive) specifying the mode: + * + * - `c`: create if it does not exist, else fail if it does not exist. Implies + * the `w` flag. + * - `w`: write. Implies `r`: a db cannot be write-only. + * - `r`: read-only if neither `w` nor `c` are provided, else it is ignored. + * - `t`: enable tracing of SQL executed on this database handle, sending it to + * `console.log()`. To disable it later, call + * `sqlite3.capi.sqlite3_trace_v2(thisDb.pointer, 0, 0, 0)`. If `w` is + * not provided, the db is implicitly read-only, noting that `rc` is + * meaningless. Any other letters are currently ignored. The default is + * `c`. These modes are ignored for the special `":memory:"` and `""` + * names and may be ignored by specific VFSes. + */ + constructor(options?: { filename?: string; flags?: string; vfs?: string }); // ✓ + + /** + * Creates a connection to the given file, optionally creating it if needed. + * + * @param filename The filename to open. Must be resolvable using whatever + * filesystem layer (virtual or otherwise) is set up for the default sqlite3 + * VFS. Note that the special sqlite3 db names `":memory:"` and `""` + * (temporary db) have their normal special meanings here. + * @param flags The flags to use when opening the file. It must be a string + * containing a sequence of letters (in any order, but case sensitive) + * specifying the mode: + * + * - `c`: create if it does not exist, else fail if it does not exist. Implies + * the `w` flag. + * - `w`: write. Implies `r`: a db cannot be write-only. + * - `r`: read-only if neither `w` nor `c` are provided, else it is ignored. + * - `t`: enable tracing of SQL executed on this database handle, sending it to + * `console.log()`. To disable it later, call + * `sqlite3.capi.sqlite3_trace_v2(thisDb.pointer, 0, 0, 0)`. If `w` is + * not provided, the db is implicitly read-only, noting that `rc` is + * meaningless. Any other letters are currently ignored. The default is + * `c`. These modes are ignored for the special `":memory:"` and `""` + * names and may be ignored by specific VFSes. + */ + constructor(filename?: string, flags?: string, vfs?: string); // ✓ + + /** Filename which was passed to the constructor. */ + filename: string; // ✓ + + /** + * Resolves to the `sqlite3*` which this object wraps. This value may be + * passed to any WASM-bound functions which accept an `sqlite3*` argument. It + * resolves to `undefined` after this object is `close()`d. + */ + pointer?: WasmPointer; // ✓ + + /** Callbacks called immediately before/after database is closed. */ + onclose?: { + before?: (db: Database) => void; + after?: (db: Database) => void; + }; // ✓ + + /** + * Executes SQL statements and optionally collects query results and/or calls + * a callback for each result row. + * + * _LOTS_ of overloads on this one one, depending on: + * + * - `sql` as parameter or as option + * - `returnValue`: + * + * - `"this"`: default, return database instance, use for fluent calls + * - `"resultRows"`: return values of `resultRows` array (set to empty array if + * not set by user) + * - `"saveSql"`: return values of `saveSql` option (set to empty array if not + * set by user) + * - `resultRows`: + * + * - `"array"`: Array of column values for every result row + * - `"object"`: Object mapping column names to values for every result row + * - `"stmt"`: Only for use with `callback` option, pass + * {@link PreparedStatement} object for every row. + * - `number`: Extract column with (zero-based) index from every result row + * - `string`: Extract column with name from every result row, must have format + * `$`, with `column` having at least two characters. + * + * ⚠️**ACHTUNG**⚠️: The combination of `returnValue: "resultRows"` and + * `rowMode: "stmt"` type checks fine, but will lead to a runtime error. This + * is due to a limitation in TypeScript's type system which does not allow + * restrictions on `string` types. + */ + exec( + sql: FlexibleString, + opts?: (ExecBaseOptions & + ExecRowModeArrayOptions & + ExecReturnThisOptions) & { + sql?: undefined; + }, + ): this; + exec( + opts: (ExecBaseOptions & + ExecRowModeArrayOptions & + ExecReturnThisOptions) & { sql: FlexibleString }, + ): this; + exec( + sql: FlexibleString, + opts: ExecBaseOptions & + ExecRowModeObjectOptions & + ExecReturnThisOptions & { + sql?: undefined; + }, + ): this; + exec( + opts: ExecBaseOptions & + ExecRowModeObjectOptions & + ExecReturnThisOptions & { + sql: FlexibleString; + }, + ): this; + exec( + sql: FlexibleString, + opts: ExecBaseOptions & + ExecRowModeStmtOptions & + ExecReturnThisOptions & { + sql?: undefined; + }, + ): this; + exec( + opts: ExecBaseOptions & + ExecRowModeStmtOptions & + ExecReturnThisOptions & { + sql: FlexibleString; + }, + ): this; + exec( + sql: FlexibleString, + opts: ExecBaseOptions & + ExecRowModeScalarOptions & + ExecReturnThisOptions & { + sql?: undefined; + }, + ): this; + exec( + opts: ExecBaseOptions & + ExecRowModeScalarOptions & + ExecReturnThisOptions & { + sql: FlexibleString; + }, + ): this; + exec( + sql: FlexibleString, + opts: ExecBaseOptions & + ExecRowModeArrayOptions & + ExecReturnResultRowsOptions & { + sql?: undefined; + }, + ): SqlValue[][]; + exec( + opts: ExecBaseOptions & + ExecRowModeArrayOptions & + ExecReturnResultRowsOptions & { + sql: FlexibleString; + }, + ): SqlValue[][]; + exec( + sql: FlexibleString, + opts: ExecBaseOptions & + ExecRowModeObjectOptions & + ExecReturnResultRowsOptions & { + sql?: undefined; + }, + ): { [columnName: string]: SqlValue }[]; + exec( + opts: ExecBaseOptions & + ExecRowModeObjectOptions & + ExecReturnResultRowsOptions & { + sql: FlexibleString; + }, + ): { [columnName: string]: SqlValue }[]; + exec( + sql: FlexibleString, + opts: ExecBaseOptions & + ExecRowModeScalarOptions & + ExecReturnResultRowsOptions & { + sql?: undefined; + }, + ): SqlValue[]; + exec( + opts: ExecBaseOptions & + ExecRowModeScalarOptions & + ExecReturnResultRowsOptions & { + sql: FlexibleString; + }, + ): SqlValue[]; + exec( + sql: FlexibleString, + opts: ExecBaseOptions & + ExecRowModeArrayOptions & + ExecReturnSaveSqlOptions & { + sql?: undefined; + }, + ): string[]; + exec( + opts: ExecBaseOptions & + ExecRowModeArrayOptions & + ExecReturnSaveSqlOptions & { + sql: FlexibleString; + }, + ): string[]; + exec( + sql: FlexibleString, + opts: ExecBaseOptions & + ExecRowModeObjectOptions & + ExecReturnSaveSqlOptions & { + sql?: undefined; + }, + ): string[]; + exec( + opts: ExecBaseOptions & + ExecRowModeObjectOptions & + ExecReturnSaveSqlOptions & { + sql: FlexibleString; + }, + ): string[]; + exec( + sql: FlexibleString, + opts: ExecBaseOptions & + ExecRowModeStmtOptions & + ExecReturnSaveSqlOptions & { + sql?: undefined; + }, + ): string[]; + exec( + opts: ExecBaseOptions & + ExecRowModeStmtOptions & + ExecReturnSaveSqlOptions & { + sql: FlexibleString; + }, + ): string[]; + exec( + sql: FlexibleString, + opts: ExecBaseOptions & + ExecRowModeScalarOptions & + ExecReturnSaveSqlOptions & { + sql?: undefined; + }, + ): string[]; + exec( + opts: ExecBaseOptions & + ExecRowModeScalarOptions & + ExecReturnSaveSqlOptions & { + sql: FlexibleString; + }, + ): string[]; + + /** + * Compiles the given SQL and returns a {@link PreparedStatement}. This is the + * only way to create new {@link PreparedStatement} objects. Throws on error. + */ + prepare(sql: FlexibleString): PreparedStatement; + + /** Returns true if the database handle is open, else false. */ + isOpen(): boolean; + + /** Throws if the given DB has been closed. */ + affirmOpen(): this; + + /** + * Finalizes all still-open statements which were opened by this object and + * closes this database connection. This is a no-op if the db has already been + * closed. After calling `close()`, {@link pointer} will resolve to + * `undefined`, so that can be used to check whether the db instance is still + * opened. + * + * If {@link onclose.before} is a function then it is called before any + * close-related cleanup. If {@link onclose.after} is a function then it is + * called after the db is closed but before auxiliary state like this.filename + * is cleared. + * + * Both onclose handlers are passed this object as their only argument. If + * this db is not opened, neither of the handlers are called. Any exceptions + * the handlers throw are ignored because "destructors must not throw." + * + * Note that garbage collection of a db handle, if it happens at all, will + * never trigger `close()`, so {@link onclose} handlers are not a reliable way + * to implement close-time cleanup or maintenance of a db. + */ + close(): void; // ✓ + + /** + * Returns the number of changes, as per `sqlite3_changes()` (if the first + * argument is `false`) or `sqlite3_total_changes()` (if it's `true`). If the + * 2nd argument is `true`, it uses `sqlite3_changes64()` or + * `sqlite3_total_changes64()`, which will trigger an exception if this build + * does not have `BigInt` support enabled. + */ + changes(total?: boolean, sixtyFour?: boolean): number; + + /** + * Returns the filename associated with the given database name. Defaults to + * `main`. Throws if this database is `close()`d. + */ + dbFilename(dbName?: string): string | null; + + /** + * Returns the name of the given 0-based db number. Defaults to `0`. Throws if + * this database is `close()`d. + */ + dbName(dbIndex?: number): string | null; + + /** + * Returns the name of the sqlite_vfs for the given database. Defaults to + * `main`. Throws if this database is `close()`d. + */ + dbVfsName(dbName?: string | number): string | undefined; + + /** + * Creates a new scalar, aggregate, or window function which is accessible via + * SQL code. + * + * When called from SQL, arguments to the UDF, and its result, will be + * converted between JS and SQL with as much fidelity as is feasible, + * triggering an exception if a type conversion cannot be determined. Some + * freedom is afforded to numeric conversions due to friction between the JS + * and C worlds: integers which are larger than 32 bits will be treated as + * doubles or `BigInt` values. + * + * UDFs cannot currently be removed from a DB handle after they're added. More + * correctly, they can be removed as documented for + * `sqlite3_create_function_v2()`, but doing so will "leak" the JS-created + * WASM binding of those functions. + * + * The first two call forms can only be used for creating scalar functions. + * Creating an aggregate or window function requires the options-object form, + * as described below. + */ + createFunction( + name: string, + func: (ctxPtr: number, ...args: any[]) => SqlValue, + ): this; + createFunction( + name: string, + func: (ctxPtr: number, ...args: any[]) => void, + options: FunctionOptions, + ): this; + createFunction( + name: string, + options: + | ScalarFunctionOptions + | AggregateFunctionOptions + | WindowFunctionOptions, + ): this; + createFunction( + options: ( + | ScalarFunctionOptions + | AggregateFunctionOptions + | WindowFunctionOptions + ) & { name: string }, + ): this; + + /** + * Prepares the given SQL, `step()`s it one time, and returns an array + * containing the values of the first result row. If it has no results, + * `undefined` is returned. If passed a second argument other than + * `undefined`, it is treated like an argument to + * {@link PreparedStatement#bind}, so may be any type supported by that + * function. Throws on error. + */ + selectArray(sql: FlexibleString, bind?: BindingSpec): SqlValue[] | undefined; + + /** + * Runs the given SQL and returns an array of all results, with each row + * represented as an array, as per the `'array'` `rowMode` option to + * {@link Database#exec}. An empty result set resolves to an empty array. The + * second argument, if any, is treated as the `bind` option to a call to + * `exec()`. Throws on error. + */ + selectArrays(sql: FlexibleString, bind?: BindingSpec): SqlValue[][]; + + /** + * Prepares the given SQL, `step()`s it one time, and returns an object + * containing the key/value pairs of the first result row. If it has no + * results, `undefined` is returned. Note that the order of returned object's + * keys is not guaranteed to be the same as the order of the fields in the + * query string. If passed a second argument other than undefined, it is + * treated like an argument to Stmt.bind(), so may be any type supported by + * that function. Throws on error. + */ + selectObject( + sql: FlexibleString, + bind?: BindingSpec, + ): { [columnName: string]: SqlValue } | undefined; + + /** + * Works identically to {@link Database#selectArrays} except that each value in + * the returned array is an object, as per the `"object"` rowMode option to + * {@link Database#exec}. + */ + selectObjects( + sql: FlexibleString, + bind?: BindingSpec, + ): { [columnName: string]: SqlValue }[]; + + /** + * Prepares the given SQL, `step()`s the resulting {@link PreparedStatement} + * one time, and returns the value of the first result column. If it has no + * results, `undefined` is returned. If passed a second argument, it is + * treated like an argument to {@link PreparedStatement#bind}, so may be any + * type supported by that function. Passing the `undefined` value is the same + * as passing no value, which is useful when... If passed a 3rd argument, it + * is expected to be one of the `SQLITE_{typename}` constants. Passing the + * `undefined` value is the same as not passing a value. Throws on error (e.g. + * malformed SQL). + */ + selectValue( + sql: FlexibleString, + bind?: BindingSpec, + asType?: SQLiteDataType, + ): SqlValue | undefined; + + /** + * Runs the given query and returns an array of the values from the first + * result column of each row of the result set. The 2nd argument is an + * optional value for use in a single-argument call to + * {@link PreparedStatement#bind}. The 3rd argument may be any value suitable + * for use as the 2nd argument to {@link PreparedStatement#get}. If a 3rd + * argument is desired but no bind data are needed, pass `undefined` for the + * 2nd argument. If there are no result rows, an empty array is returned. + */ + selectValues( + sql: FlexibleString, + bind?: BindingSpec, + asType?: SQLiteDataType, + ): SqlValue[]; + + /** + * Returns the number of currently-opened {@link PreparedStatement} handles for + * this db handle, or 0 if this object is `close()`d. Note that only handles + * prepared via {@link Database#prepare} are counted, and not handles prepared + * using `capi.sqlite3_prepare_v3()` (or equivalent). + */ + openStatementCount(): number; + + /** + * Starts a transaction, calls the given `callback`, and then either rolls + * back or commits the transaction, depending on whether the `callback` + * throws. The `callback` is passed this object as its only argument. On + * success, returns the result of the callback. Throws on error. + * + * Note that transactions may not be nested, so this will throw if it is + * called recursively. For nested transactions, use the + * {@link Database#savepoint} method or manually manage `SAVEPOINT`s using + * {@link Database#exec}. + * + * If called with 2 arguments, the first must be a keyword which is legal + * immediately after a `BEGIN` statement, e.g. one of `"DEFERRED"`, + * `"IMMEDIATE"`, or `"EXCLUSIVE"`. Though the exact list of supported + * keywords is not hard-coded here, in order to be future-compatible, if the + * argument does not look like a single keyword then an exception is triggered + * with a description of the problem. + */ + transaction(callback: (db: this) => T): T; + transaction( + beginQualifier: 'DEFERRED' | 'IMMEDIATE' | 'EXCLUSIVE', + callback: (db: this) => T, + ): T; + + /** + * This works similarly to {@link Database#transaction} but uses sqlite3's + * `SAVEPOINT` feature. This function starts a savepoint (with an unspecified + * name) and calls the given callback function, passing it this db object. If + * the callback returns, the savepoint is released (committed). If the + * callback throws, the savepoint is rolled back. If it does not throw, it + * returns the result of the callback. + */ + savepoint(callback: (db: this) => T): T; + + /** + * Expects to be given a `DatabaseApi` instance or an `sqlite3*` pointer (may + * be `null`) and an sqlite3 API result code. If the result code is not falsy, + * this function throws an `SQLite3Error` with an error message from + * `sqlite3_errmsg()`, using the given db handle, or `sqlite3_errstr()` if the + * db handle is falsy or is a `close()`ed DB instance. Note that if it's + * passed a non-error code like `SQLITE_ROW` or `SQLITE_DONE`, it will still + * throw but the error string might be `"Not an error."` The various non-0 + * non-error codes need to be checked for in client code where they are + * expected. If it does not throw, it returns its `db` argument (`this`, if + * called as a member function). + */ + static checkRc: ( + db: Database | number | null, + resultCode: number, + ) => Database; + + /** Instance method version of {@link checkRc()}. */ + checkRc: (resultCode: number) => this; +} + +/** + * SQLite3 database backed by `localStorage` or `sessionStorage`. + * + * When the sqlite3 API is installed in the main thread, the this class is + * added, which simplifies usage of the kvvfs. + */ +declare class JsStorageDb extends Database { + /** Create a new kvvfs-backed database in local or session storage. */ + constructor(mode: 'local' | 'session'); + + /** Returns an _estimate_ of how many bytes of storage are used by the kvvfs. */ + storageSize(): number; + + /** + * Clears all kvvfs-owned state and returns the number of records it deleted + * (one record per database page). + */ + clearStorage(): number; +} + +/** + * SQLite3 database backed by the Origin Private File System API. + * + * Installed in the namespace only if OPFS VFS support is active. + * + * This support is only available when sqlite3.js is loaded from a Worker + * thread, whether it's loaded in its own dedicated worker or in a worker + * together with client code. This OPFS wrapper implements an `sqlite3_vfs` + * wrapper entirely in JavaScript. + * + * This feature is activated automatically if the browser appears to have the + * necessary APIs to support it. It can be tested for in JS code using one of: + * + * If(sqlite3.capi.sqlite3_vfs_find("opfs")){ ... OPFS VFS is available ... } + * // Alternately: if(sqlite3.oo1.OpfsDb){ ... OPFS VFS is available ... } + * + * If it is available, the VFS named `"opfs"` can be used with any sqlite3 APIs + * which accept a VFS name, such as `sqlite3_vfs_find()`, + * `sqlite3_db_open_v2()`, and the `sqlite3.oo1.DB` constructor, noting that + * {@link OpfsDb} is a convenience subclass of {@link Database} which + * automatically uses this VFS. For URI-style names, use `file:my.db?vfs=opfs`. + * + * ## ⚠️Achtung: Safari versions < 17: + * + * Safari versions less than version 17 are incompatible with the current OPFS + * VFS implementation because of a bug in storage handling from sub-workers. + * There is no workaround for that - supporting it will require a separate VFS + * implementation and we do not, as of July 2023, have an expected time frame + * for its release. Both the `SharedAccessHandle` pool VFS and the WASMFS + * support offers alternatives which should work with Safari versions 16.4 or + * higher. + * + * ## ⚠️Achtung: COOP and COEP HTTP Headers + * + * In order to offer some level of transparent concurrent-db-access support, + * JavaScript's SharedArrayBuffer type is required for the OPFS VFS, and that + * class is only available if the web server includes the so-called COOP and + * COEP response headers when delivering scripts: + * + * Cross-Origin-Embedder-Policy: require-corp + * Cross-Origin-Opener-Policy: same-origin + * + * Without these headers, the `SharedArrayBuffer` will not be available, so the + * OPFS VFS will not load. That class is required in order to coordinate + * communication between the synchronous and asynchronous parts of the + * `sqlite3_vfs` OPFS proxy. + * + * The COEP header may also have a value of `credentialless`, but whether or not + * that will work in the context of any given application depends on how it uses + * other remote assets. + * + * How to emit those headers depends on the underlying web server. + */ +declare class OpfsDatabase extends Database { + /** + * Creates a connection to the given file, optionally creating it if needed. + * + * @param filename The filename to open. Must be resolvable using whatever + * filesystem layer (virtual or otherwise) is set up for the default sqlite3 + * VFS. Note that the special sqlite3 db names `":memory:"` and `""` + * (temporary db) have their normal special meanings here. + * @param flags The flags to use when opening the file. It must be a string + * containing a sequence of letters (in any order, but case sensitive) + * specifying the mode: + * + * - `c`: create if it does not exist, else fail if it does not exist. Implies + * the `w` flag. Will create all directorries leading up to the file. + * - `w`: write. Implies `r`: a db cannot be write-only. + * - `r`: read-only if neither `w` nor `c` are provided, else it is ignored. + * - `t`: enable tracing of SQL executed on this database handle, sending it to + * `console.log()`. To disable it later, call + * `sqlite3.capi.sqlite3_trace_v2(thisDb.pointer, 0, 0, 0)`. If `w` is + * not provided, the db is implicitly read-only, noting that `rc` is + * meaningless. Any other letters are currently ignored. The default is + * `c`. These modes are ignored for the special `":memory:"` and `""` + * names and may be ignored by specific VFSes. + */ + constructor(filename: string, flags: string); + + /** + * Import a database into OPFS storage. It only works with database files and + * will throw if passed a different file type. + */ + static importDb( + filename: string, + data: Uint8Array | ArrayBuffer, + ): Promise; +} + +/** Exception class for reporting WASM-side allocation errors. */ +declare class WasmAllocError extends Error { + constructor(message: string); + toss: any; +} + +/** Exception class used primarily by the oo1 API. */ +declare class SQLite3Error extends Error { + constructor(message: string); +} + +/** A pointer to a location in WASM heap memory. */ +declare type WasmPointer = number; + +declare type StructPtrMapper = { + StructType: T; + /** + * Creates a new StructType object, writes its `pointer` value to the given + * output pointer, and returns that object. Its intended usage depends on + * StructType: + * + * - `sqlite3_vtab`: to be called from `sqlite3_module::xConnect()` or + * `xCreate()` implementations. + * - `sqlite3_vtab_cursor`: to be called from 1xOpen()`. + * + * This will throw if allocation of the `StructType` instance fails or if + * `ppOut` is not a pointer-type value. + */ + create: (ptr: WasmPointer) => T; + + /** + * Returns the StructType object previously mapped to the given pointer using + * `create()`. Its intended usage depends on `StructType`: + * + * - `sqlite3_vtab`: to be called from sqlite3_module methods which take a + * `(sqlite3_vtab*)` pointer _except_ for `xDestroy()`/`xDisconnect()`, in + * which case `unget()` or `dispose()`. + * - `sqlite3_vtab_cursor`: to be called from any `sqlite3_module` methods which + * take a `sqlite3_vtab_cursor*` argument except `xClose()`, in which case + * use `unget()` or `dispose()`. + * + * Rule to remember: _never_ call `dispose()` on an instance returned by this + * function. + */ + get: (ptr: WasmPointer) => T; + + /** + * Identical to get() but also disconnects the mapping between the given + * pointer and the returned StructType object, such that future calls to this + * function or get() with the same pointer will return the undefined value. + * Its intended usage depends on StructType: + * + * - `sqlite3_vtab`: to be called from `sqlite3_module::xDisconnect()` or + * `xDestroy()` implementations or in error handling of a failed `xCreate()` + * or `xConnect()`. + * - `sqlite3_vtab_cursor`: to be called from `xClose()` or during cleanup in a + * failed `xOpen()`. + * + * Calling this method obligates the caller to call `dispose()` on the + * returned object when they're done with it. + */ + unget: (ptr: WasmPointer, val: T) => void; + + /** Works like `unget()` plus it calls `dispose()` on the `StructType` object. */ + dispose: (ptr: WasmPointer) => void; +}; + +declare class SQLiteStruct { + /** + * Calling a constructor with no arguments creates a new instance in the WASM + * heap in order to connect it to C. In this case, client JavaScript code owns + * the memory for the instance unless some API explicitly takes it over. + * + * Passing a WASM pointer to the constructor creates a JS-level wrapper for an + * existing instance of the struct (whether it comes from C or JS) without + * taking over ownership of that memory. This permits JS to manipulate + * instances created in C without taking over their memory. + * + * Both uses are fairly common, and they differ only in how they manage (or + * not) the struct's memory. + * + * So long as a struct instance is active, its pointer property resolves to + * its WASM heap memory address. That value can be passed to any C routines + * which take pointers of that type. For example: + * + * const m = new MyStruct(); + * functionTakingMyStructPointers(m.pointer); + */ + constructor(pointer?: WasmPointer); + + /** The WASM pointer to the struct. */ + pointer: WasmPointer; + + /** + * When client code is finished with an instance, and no C-level code is using + * its memory, the struct instance must be cleaned up by calling + * theStruct.dispose(). Calling dispose() multiple times is harmless - calls + * after the first are no-ops. Calling dipose() is not strictly required for + * wrapped instances, as their WASM heap memory is owned elsewhere, but it is + * good practice to call it because each instance may own memory other than + * the struct memory. + */ + dispose(): void; + + /** + * If a given JS-side struct instance has a property named `ondispose`, that + * property is used when `dispose()` is called in order to free up any + * additional resources which may be associated with the struct (e.g. + * C-allocated strings or other struct instances). + * + * `ondispose` is not set by default but may be set by the client to one of + * the following: + * + * - If it's a function, it is called with no arguments and the being-disposed + * object as its this. It may perform arbitrary cleanup. + * - If it's an array, each entry of the array may be any of: + * + * - A function is called as described above. + * - Any JS-bound struct instance has its dispose() method called. + * - A number is assumed to be a WASM pointer, which gets freed using + * sqlite3.wasm.dealloc(). + * - Any other value type is ignored. It is sometimes convenient to annotate the + * array with string entries to assist in understanding the code. For + * example: + * + * X.ondispose = ['Wrapper for this.$next:', y]; + * + * Any exceptions thrown by ondispose callbacks are ignored but may induce a + * warning in the console. + */ + ondispose?: + | (() => void) + | ((() => void) | SQLiteStruct | WasmPointer | string)[]; + + /** + * Client code may call `aStructInstance.addOnDispose()` to push one or more + * arguments onto the disposal list. That function will create an `ondispose` + * array if needed, or move a non-array `ondispose` value into a newly-created + * `ondispose` array. It returns its `this`. + */ + addOnDispose(val: (() => void) | SQLiteStruct | WasmPointer | string): this; + + /** + * Overwrites (without freeing) any existing value in that member, replaces it + * with a newly-allocated C-string, and stores that C-string in the instance's + * ondispose state for cleanup when `dispose()` is called. The struct cannot + * know whether it is safe to free such strings when overwriting them, so + * instead adds each string set this way to the ondispose list. + */ + setMemberCString(memberName: string, jsString: string): void; + + /** + * Fetches the member's value. If it's `NULL`, `null` is returned, else it is + * assumed to be a valid C-style string and a copy of it is returned as a JS + * string. + */ + memberToJsString(memberName: string): string | null; + + /** Returns true if the given member name is specifically tagged as a string. */ + memberIsString(memberName: string): boolean; + + /** + * Installs a StructBinder-bound function pointer member of the given name and + * function in this object. + * + * It creates a WASM proxy for the given function and arranges for that proxy + * to be cleaned up when `this.dispose()` is called. Throws on the slightest + * hint of error, e.g., the given name does not map to a struct-bound member. + * + * As a special case, if the given function is a pointer, then + * `wasm.functionEntry()` is used to validate that it is a known function. If + * so, it is used as-is with no extra level of proxying or cleanup, else an + * exception is thrown. It is legal to pass a value of 0, indicating a `NULL` + * pointer, with the caveat that 0 is a legal function pointer in WASM but it + * will not be accepted as such here. (Justification: the function at address + * zero must be one which initially came from the WASM module, not a method we + * want to bind to client-level extension code.) + * + * This function returns a proxy for itself which is bound to `this` and takes + * 2 args `(name,func)`. That function returns the same thing as this one, + * permitting calls to be chained. + * + * If called with only 1 arg, it has no side effects but returns a func with + * the same signature as described above. + * + * **⚠ACHTUNG:⚠** because we cannot generically know how to transform JS + * exceptions into result codes, the installed functions do no automatic + * catching of exceptions. It is critical, to avoid undefined behavior in the + * C layer, that methods mapped via this function do not throw. The exception, + * as it were, to that rule is... + * + * If `applyArgcCheck` is true then each JS function (as opposed to function + * pointers) gets wrapped in a proxy which asserts that it is passed the + * expected number of arguments, throwing if the argument count does not match + * expectations. That is only intended for dev-time usage for sanity checking, + * as exceptions passing through such methods will leave the C environment in + * an undefined state. + */ + installMethod( + name: string, + func: Function | WasmPointer, + applyArgcCheck?: boolean, + ): (name: string, func: Function | WasmPointer) => this; + + /** Behaves exactly like {@link SQLiteStruct#installMethods}. */ + installMethod( + methodsObject: { [methodName: string]: Function }, + applyArgcCheck?: boolean, + ): this; + + /** + * Installs methods into this StructType-type instance. Each entry in the + * given methods object must map to a known member of the given StructType, + * else an exception will be triggered. See `installMethod()` for more + * details, including the semantics of the second argument. + * + * As an exception to the above, if any two or more methods in the methods + * object are the exact same function, `installMethod()` is not called for the + * 2nd and subsequent instances, and instead those instances get assigned the + * same method pointer which is created for the first instance. This + * optimization is primarily to accommodate special handling of + * `sqlite3_module::xConnect` and `xCreate` methods. + * + * On success, returns this object. Throws on error. + */ + installMethods( + methodsObject: { [methodName: string]: Function }, + applyArgcCheck?: boolean, + ): this; +} + +declare class sqlite3_vfs extends SQLiteStruct { + iVersion: number; + szOsFile: number; + mxPathname: number; + pNext: WasmPointer; + zName: WasmPointer; + pAppData: WasmPointer; + xOpen: ( + vfsPtr: WasmPointer, + zName: WasmPointer, + file: WasmPointer, + flags: number, + pOutputFlags: WasmPointer, + ) => number; + xDelete: (vfsPtr: WasmPointer, zName: WasmPointer, syncDir: number) => number; + xAccess: ( + vfsPtr: WasmPointer, + zName: WasmPointer, + flags: number, + pResOut: WasmPointer, + ) => number; + xFullPathname: ( + vfsPtr: WasmPointer, + zName: WasmPointer, + nOut: number, + zOut: WasmPointer, + ) => number; + xDlOpen: (vfsPtr: WasmPointer, zFilename: WasmPointer) => WasmPointer; + xDlError: (vfsPtr: WasmPointer, nByte: number, zErrMsg: WasmPointer) => void; + xDlSym: ( + vfsPtr: WasmPointer, + pHandle: WasmPointer, + zSymbol: WasmPointer, + ) => WasmPointer; + xDlClose: (vfsPtr: WasmPointer, pHandle: WasmPointer) => void; + xRandomness: ( + vfsPtr: WasmPointer, + nByte: number, + zOut: WasmPointer, + ) => number; + xSleep: (vfsPtr: WasmPointer, microseconds: number) => number; + xCurrentTime: (vfsPtr: WasmPointer, pTimeOut: WasmPointer) => number; + xGetLastError: (vfsPtr: WasmPointer, nBuf: number, zBuf: WasmPointer) => void; + xCurrentTimeInt64: (vfsPtr: WasmPointer, pTimeOut: WasmPointer) => number; + xSetSystemCall: ( + vfsPtr: WasmPointer, + zName: WasmPointer, + pCall: WasmPointer, + ) => number; + xGetSystemCall: ( + vfsPtr: WasmPointer, + zName: WasmPointer, + pCall: WasmPointer, + ) => WasmPointer; + xNextSystemCall: (vfsPtr: WasmPointer, zName: WasmPointer) => WasmPointer; +} + +declare class sqlite3_io_methods extends SQLiteStruct { + iVersion: number; + xClose: (file: WasmPointer) => number; + xRead: ( + file: WasmPointer, + buf: WasmPointer, + iAmt: number, + iOfst: number, + ) => number; + xWrite: ( + file: WasmPointer, + buf: WasmPointer, + iAmt: number, + iOfst: number, + ) => number; + xTruncate: (file: WasmPointer, size: number) => number; + xSync: (file: WasmPointer, flags: number) => number; + xFileSize: (file: WasmPointer, pSize: WasmPointer) => number; + xLock: (file: WasmPointer, lockType: number) => number; + xUnlock: (file: WasmPointer, lockType: number) => number; + xCheckReservedLock: (file: WasmPointer, pResOut: WasmPointer) => number; + xFileControl: (file: WasmPointer, op: number, pArg: WasmPointer) => number; + xSectorSize: (file: WasmPointer) => number; + xDeviceCharacteristics: (file: WasmPointer) => number; + xShmMap: ( + file: WasmPointer, + iPg: number, + pgsz: number, + bExtend: number, + pp: WasmPointer, + ) => number; + xShmLock: ( + file: WasmPointer, + offset: number, + n: number, + flags: number, + ) => number; + xShmBarrier: (file: WasmPointer) => void; + xShmUnmap: (file: WasmPointer, deleteFlag: number) => number; + xFetch: ( + file: WasmPointer, + iOfst: number, + iAmt: number, + pp: WasmPointer, + ) => number; + xUnfetch: (file: WasmPointer, iOfst: number, p: WasmPointer) => number; +} + +declare class sqlite3_file extends SQLiteStruct { + pMethods: WasmPointer; +} + +declare class sqlite3_vtab extends SQLiteStruct { + pModule: WasmPointer; + nRef: number; + zErrMsg: WasmPointer; +} + +declare class sqlite3_vtab_cursor extends SQLiteStruct { + pVtab: WasmPointer; +} + +declare class sqlite3_module extends SQLiteStruct { + iVersion: number; + xCreate: ( + db: WasmPointer, + pAux: WasmPointer, + argc: number, + argv: WasmPointer, + ppVtab: WasmPointer, + pzErr: WasmPointer, + ) => number; + xConnect: ( + db: WasmPointer, + pAux: WasmPointer, + argc: number, + argv: WasmPointer, + ppVtab: WasmPointer, + pzErr: WasmPointer, + ) => number; + xBestIndex: ( + pVtab: WasmPointer, + pIndexInfo: WasmPointer, + pp: WasmPointer, + pCost: WasmPointer, + ) => number; + xDisconnect: (pVtab: WasmPointer) => number; + xDestroy: (pVtab: WasmPointer) => number; + xOpen: (pVtab: WasmPointer, ppCursor: WasmPointer) => number; + xClose: (pCursor: WasmPointer) => number; + xFilter: ( + pCursor: WasmPointer, + idxNum: number, + idxStr: WasmPointer, + argc: number, + argv: WasmPointer, + ) => number; + xNext: (pCursor: WasmPointer) => number; + xEof: (pCursor: WasmPointer) => number; + xColumn: (pCursor: WasmPointer, pContext: WasmPointer, i: number) => number; + xRowid: (pCursor: WasmPointer, pRowid: WasmPointer) => number; + xUpdate: ( + pVtab: WasmPointer, + argc: number, + argv: WasmPointer, + pRowid: WasmPointer, + ) => number; + xBegin: (pVtab: WasmPointer) => number; + xSync: (pVtab: WasmPointer) => number; + xCommit: (pVtab: WasmPointer) => number; + xRollback: (pVtab: WasmPointer) => number; + xFindFunction: ( + pVtab: WasmPointer, + nArg: number, + zName: WasmPointer, + pxFunc: WasmPointer, + ppArg: WasmPointer, + ) => number; + xRename: (pVtab: WasmPointer, zNew: WasmPointer) => number; + xSavepoint: (pVtab: WasmPointer, iSavepoint: number) => number; + xRelease: (pVtab: WasmPointer, iSavepoint: number) => number; + xRollbackTo: (pVtab: WasmPointer, iSavepoint: number) => number; + xShadowName: (tableName: WasmPointer) => number; +} + +declare class sqlite3_index_constraint extends SQLiteStruct { + iColumn: number; + op: number; + usable: number; + iTermOffset: number; +} + +declare class sqlite3_index_constraint_usage extends SQLiteStruct { + argvIndex: number; + omit: number; +} + +declare class sqlite3_index_orderby extends SQLiteStruct { + iColumn: number; + desc: number; +} + +declare class sqlite3_index_info extends SQLiteStruct { + nConstraint: number; + aConstraint: WasmPointer; + nOrderBy: number; + aOrderBy: WasmPointer; + aConstraintUsage: WasmPointer; + idxNum: number; + idxStr: WasmPointer; + needToFreeIdxStr: number; + orderByConsumed: number; + estimatedCost: number; + estimatedRows: BigInt; + idxFlags: number; + colUsed: BigInt; + sqlite3_index_constraint: sqlite3_index_constraint; + sqlite3_index_orderby: sqlite3_index_orderby; + sqlite3_index_constraint_usage: sqlite3_index_constraint_usage; +} + +declare type Sqlite3Static = { + /** The namespace for the C-style APIs. */ + capi: CAPI; + + /** + * WASM-specific utilities, abstracted to be independent of, and configurable + * for use with, arbitrary WASM runtime environments. + */ + wasm: WASM_API; + + /** The OO API #1. */ + oo1: { + OpfsDb: typeof OpfsDatabase; + JsStorageDb: typeof JsStorageDb; + DB: typeof Database; }; - type ExecThisOptions = ExecOptions & { - returnValue?: 'this' | undefined; + /** + * Initializes the Worker API. + * + * Required to to permit this API to be loaded in Worker threads without + * automatically registering onmessage handlers + * + * If this function is called from a non-worker thread then it throws an + * exception. It must only be called once per Worker. + */ + initWorker1API(): void; + + WasmAllocError: WasmAllocError; + + SQLite3Error: SQLite3Error; + + /** + * The options with which the API was configured. Whether or not modifying + * them after the bootstrapping process will have any useful effect is + * unspecified and may change with any given version. Clients must not rely on + * that capability. + */ + config: { + exports: any; + memory: WebAssembly.Memory; + bigIntEnabled: boolean; + debug: typeof console.debug; + warn: typeof console.warn; + error: typeof console.error; + log: typeof console.log; + wasmOpfsDir: string; + useStdAlloc: boolean; + allocExportName: string; + deallocExportName: string; + reallocExportName: string; }; - type ExecResultRowsOptions = ExecOptions & { - returnValue: 'resultRows'; - rowMode?: 'array' | 'object' | 'stmt'; + /** + * The library reserves this property for client-side use and promises to + * never define a property with this name nor to ever rely on specific + * contents of it. It makes no such guarantees for other properties. + */ + client: any; + + /* Utility code for creating sqlite3_vfs's. */ + vfs: { + /** + * A wrapper for installMethods() or registerVfs() to reduce installation of + * a VFS and/or its I/O methods to a single call. + * + * Accepts an object which contains the properties `"io"` and/or `"vfs"`, + * each of which is itself an object with following properties: + * + * - `struct`: an `sqlite3.StructType`-type struct. This must be a populated + * (except for the methods) object of type `sqlite3_io_methods` (for the + * `"io"` entry) or `sqlite3_vfs` (for the `"vfs"` entry). + * - `methods`: an object mapping `sqlite3_io_methods` method names (e.g. + * `'xClose'`) to JS implementations of those methods. The JS + * implementations must be call-compatible with their native + * counterparts. + * + * For each of those object, this function passes its (`struct`, `methods`, + * (optional) `applyArgcCheck`) properties to `installMethods()`. + * + * If the `vfs` entry is set then: + * + * - Its `struct` property's `registerVfs()` is called. The `vfs` entry may + * optionally have an `asDefault` property, which gets passed as the + * argument to `registerVfs()`. + * - If `struct.$zName` is falsy and the entry has a string-type `name` + * property, `struct.$zName` is set to the C-string form of that `name` + * value before `registerVfs()` is called. That string gets added to the + * on-dispose state of the struct. + * + * On success returns this object. Throws on error. + */ + installVfs: (obj: { + io?: { + struct: sqlite3_io_methods; + methods: Omit; + }; + }) => Sqlite3Static['vfs']; }; - class DatabaseApi { - filename: string; - pointer: number; - exec(input: string, opts?: ExecThisOptions): DatabaseApi; - exec(input: string, opts?: ExecResultRowsOptions): any; - - exec(opts: ExecThisOptions): DatabaseApi; - exec(opts: ExecResultRowsOptions): any; - - // exec(opts: ExecOptions & {returnValue: "resultRows"}): any; - prepare(sql: string): PreparedStatement; - - isOpen: () => boolean; - affirmOpen: () => DatabaseApi; - close: () => void; - changes: (total?: boolean, sixtyFour?: boolean) => number; - dbFilename: () => string; - dbName: () => string; - dbVfsName: (dbName: any) => string; - createFunction: Function; - - selectValue: Function; - selectValues: Function; - selectArray: Function; - selectObject: Function; - selectArrays: Function; - selectObjects: Function; - - openStatementCount: Function; - transaction: Function; - savepoint: Function; - checkRc: Function; - } - - export class JsStorageDb extends DatabaseApi { - constructor(mode: 'local' | 'session'); - storageSize(): number; - clearStorage(): void; - } - - export class OpfsDatabase extends DatabaseApi { - constructor(filename: string); - } - - export type Flags = 'c' | 'w' | 'r' | 't'; - - export class Database extends DatabaseApi { - constructor(options: { filename: string; flags: string; vfs?: any }); - constructor(filename: string, flags: string, vfs?: any); - } - - class WasmAllocError extends Error { - constructor(message: string); - toss: any; - } - - class SQLite3Error extends Error { - constructor(message: string); - } - - type Sqlite3Static = { - capi: CAPI; - wasm: WASM_API; - // Object Oriented API https://sqlite.org/wasm/doc/trunk/api-oo1.md - oo1: { - OpfsDb: typeof OpfsDatabase; - JsStorageDb: typeof JsStorageDb; - DB: typeof Database; - }; - opfs?: { - metrics: any; - debug: any; - getResolvedPath: any; - getDirForFilename: any; - mkdir: any; - entryExists: any; - randomFilename: any; - registerVfs: any; - treeList: any; - rmfr: any; - unlink: any; - traverse: any; - rootDirectory: any; - }; - WasmAllocError: WasmAllocError; - SQLite3Error: SQLite3Error; - config: { - exports: any; - memory: any; - bigIntEnabled: any; - debug: any; - warn: any; - error: any; - log: any; - wasmfsOpfsDir: any; - useStdAlloc: any; - allocExportName: any; - deallocExportName: any; - reallocExportName: any; - wasmOpfsDir: any; - }; - version: { - libVersion: string; - libVersionNumber: any; - sourceId: any; - downloadVersion: any; - }; - client: any; - scriptInfo: { - moduleScript: any; - isWorker: any; - location: any; - urlParams: any; - debugModule: any; - }; - initWorker1API: Function; - vfs: { - installVfs: any; + /** Utility code for creating virtual table implementations. */ + vtab: { + /** + * A lifetime-management object for mapping `sqlite3_vtab*` instances in + * `sqlite3_module` methods to `capi.sqlite3_vtab` objects. + */ + xVtab: StructPtrMapper; + + /** + * A lifetime-management object for mapping `sqlite3_vtab_cursor*` instances + * in sqlite3_module methods to `capi.sqlite3_vtab_cursor` objects. + */ + xCursor: StructPtrMapper; + + /** + * Convenience form of creating an `sqlite3_index_info` wrapper, intended + * for use in `xBestIndex` implementations. Note that the caller is expected + * to call `dispose()` on the returned object before returning. Though not + * _strictly_ required, as that object does not own the `pIdxInfo` memory, + * it is nonetheless good form. + */ + xIndexInfo: (pIdxInfo: WasmPointer) => sqlite3_index_info; + + /** + * Given an `sqlite3_module` method name and error object, this function + * returns `sqlite3.capi.SQLITE_NOMEM` if `(e instanceof + * sqlite3.WasmAllocError)`, else it returns its second argument. Its + * intended usage is in the methods of a `sqlite3_vfs` or `sqlite3_module`: + * + * try{ + * let rc = ... + * return rc; + * }catch(e){ + * return sqlite3.vtab.xError( + * 'xColumn', e, sqlite3.capi.SQLITE_XYZ); + * // where SQLITE_XYZ is some call-appropriate result code. + * } + * + * If no 3rd argument is provided, its default depends on the error type: + * + * - An `sqlite3.WasmAllocError` always resolves to `capi.SQLITE_NOMEM`. + * - If `err` is an SQLite3Error then its `resultCode` property is used. + * - If all else fails, `capi.SQLITE_ERROR` is used. + * + * If `xError.errorReporter` is a function, it is called in order to report + * the error, else the error is not reported. If that function throws, that + * exception is ignored. + */ + xError: ((methodName: string, err: Error, defaultRc: number) => number) & { + errorReporter?: (errorStr: string) => void; }; - vtab: { - xVtab: any; - xCursor: any; - xIndexInfo: any; - xError: any; - xRowid: any; - setupModule: any; + + /** + * A helper for `sqlite3_vtab::xRowid()` and `xUpdate()` implementations. It + * must be passed the final argument to one of those methods (an output + * pointer to an int64 row ID) and the value to store at the output + * pointer's address. Returns the same as `wasm.poke()` and will throw if + * the 1st or 2nd arguments are invalid for that function. + * + * Example `xRowid` impl: + * + * const xRowid = (pCursor, ppRowid64) => { + * const c = vtab.xCursor(pCursor); + * vtab.xRowid(ppRowid64, c.myRowId); + * return 0; + * }; + */ + xRowid: (ppRowId64: WasmPointer, value: number) => WASM_API; + + /** + * A helper to initialize and set up an `sqlite3_module` object for later + * installation into individual databases using `sqlite3_create_module()`. + * + * If `catchExceptions` is false, it is up to the client to ensure that no + * exceptions escape the methods, as doing so would move them through the C + * API, leading to undefined behavior. (vtab.xError() is intended to assist + * in reporting such exceptions.) + * + * This is to facilitate creation of those methods inline in the passed-in + * object without requiring the client to explicitly get a reference to one + * of them in order to assign it to the other one. + * + * The `catchExceptions`-installed handlers will account for identical + * references to the above functions and will install the same wrapper + * function for both. + * + * The given methods are expected to return integer values, as expected by + * the C API. If `catchExceptions` is truthy, the return value of the + * wrapped function will be used as-is and will be translated to 0 if the + * function returns a falsy value (e.g. if it does not have an explicit + * return). If `catchExceptions` is _not_ active, the method implementations + * must explicitly return integer values. + * + * Throws on error. On success, returns the sqlite3_module object (`this` or + * `opt.struct` or a new sqlite3_module instance, depending on how it's + * called). + */ + setupModule: { + /** + * An object containing a mapping of properties with the C-side names of + * the sqlite3_module methods, e.g. `xCreate`, `xBestIndex`, etc., to JS + * implementations for those functions. + * + * Certain methods may refer to the same implementation. To simplify the + * definition of such methods: + * + * - If `methods.xConnect` is `true` then the value of `methods.xCreate` is + * used in its place, and vice versa. sqlite treats xConnect/xCreate + * functions specially if they are exactly the same function (same + * pointer value). + * - If `methods.xDisconnect` is true then the value of `methods.xDestroy` + * is used in its place, and vice versa. + */ + methods: Omit & + ( + | { + xConnect: undefined; + } + | { xCreate: undefined } + ) & + ( + | { + xDisconnect: undefined; + } + | { xDestroy: undefined } + ); + + /** + * (default=false): if truthy, the given methods are not mapped as-is, but + * are instead wrapped inside wrappers which translate exceptions into + * result codes of SQLITE_ERROR or SQLITE_NOMEM, depending on whether the + * exception is an sqlite3.WasmAllocError. In the case of the xConnect and + * xCreate methods, the exception handler also sets the output error + * string to the exception's error string. + */ + catchExceptions?: boolean; + + /** + * A `sqlite3.capi.sqlite3_module()` instance. If not set, one will be + * created automatically. If the current `"this"` is-a `sqlite3_module` + * then it is unconditionally used in place of `struct`. + */ + struct?: sqlite3_module; + + /** + * If set, it must be an integer value and it gets assigned to the + * `$iVersion` member of the struct object. If it's _not_ set, and the + * passed-in `struct` object's `$iVersion` is 0 (the default) then this + * function attempts to define a value for that property based on the list + * of methods it has. + */ + iVersion?: number; }; }; +}; + +declare type InitOptions = { + print?: (msg: string) => void; + printErr?: (msg: string) => void; +}; + +/** + * A function installed by Emscripten to load and initialize the module. It + * accepts an optional object to act as the so-called Emscripten Module, with + * which the client may be notified of loading progress an errors. + * + * See the [Emscripten docs on the topic][1] for full details. + * + * Note that this project has no influence over those options and the Emscripten + * project may change them at any time, so we neither document nor support them. + * Note, also, that this project may attempt to internally override any specific + * option, potentially leading to undesired side effects if client code does the + * same. + * + * [1] https://emscripten.org/docs/api_reference/module.html + */ +export default function init(opts?: InitOptions): Promise; + +declare type ListLike = { + length: number; + forEach: (cb: (val: T) => void) => void; +}; + +declare type WASM_API = { + /** + * The `sqlite3.wasm.exports` namespace object is a WASM-standard part of the + * WASM module file and contains all "exported" C functions which are built + * into the WASM module, as well as certain non-function values which are part + * of the WASM module. The functions which live in this object are as + * low-level as it gets, in terms of JS/C bindings. They perform no automatic + * type conversions on their arguments or result values and many, perhaps + * most, are cumbersome to use from JS because of that. This level of the API + * is not generally recommended for client use but is available for those who + * want to make use of it. The functions in this object which are intended for + * client-side use are re-exported into the {@link CAPI} namespace and have + * automatic type conversions applied to them (where applicable). Some small + * handful of the functions get re-exported into the {@link WASM_API} + * namespace. + */ + exports: any; + + /* ========================================================================== + * Memory Management + * ========================================================================== + * Just like in C, WASM offers a memory "heap," and transfering values + * between JS and WASM often requires manipulation of that memory, including + * low-level allocation and deallocation of it. The following subsections + * describe the various memory management APIs. + */ + + /* -------------------------------------------------------------------------- + * Low-level Management + * -------------------------------------------------------------------------- + * The lowest-level memory management works like C's standard `malloc()`, + * `realloc()`, and `free()`, the one difference being that exceptions are used + * for reporting out-of-memory conditions. In order to avoid certain API + * misuses caused by mixing different allocators, the canonical sqlite3.js + * builds wrap `sqlite3_malloc()`, `sqlite3_realloc()`, and `sqlite3_free()` + * instead of `malloc()`, `realloc()`, and `free()`, but the semantics of both + * pairs are effectively identical. + */ - export default function sqlite3InitModule( - opts?: InitOptions, - ): Promise; - - // generated by Object.keys(sqlite3.capi).map(k => `${k}: any;`).join('\n') - type CAPI = { - sqlite3_bind_blob: any; - sqlite3_bind_text: any; - sqlite3_create_function_v2: any; - sqlite3_create_function: any; - sqlite3_create_window_function: any; - sqlite3_prepare_v3: any; - sqlite3_prepare_v2: any; - sqlite3_exec: any; - sqlite3_randomness: any; - sqlite3_wasmfs_opfs_dir: any; - sqlite3_wasmfs_filename_is_persistent: any; - sqlite3_js_db_uses_vfs: any; - sqlite3_js_vfs_list: any; - sqlite3_js_db_export: any; - sqlite3_js_db_vfs: any; - sqlite3_js_aggregate_context: any; - sqlite3_js_vfs_create_file: any; - sqlite3_db_config: any; - sqlite3_value_to_js: any; - sqlite3_values_to_js: any; - sqlite3_result_error_js: any; - sqlite3_result_js: any; - sqlite3_column_js: any; - sqlite3_preupdate_new_js: any; - sqlite3_preupdate_old_js: any; - sqlite3changeset_new_js: any; - sqlite3changeset_old_js: any; - sqlite3_aggregate_context: any; - sqlite3_bind_double: any; - sqlite3_bind_int: any; - sqlite3_bind_null: any; - sqlite3_bind_parameter_count: any; - sqlite3_bind_parameter_index: any; - sqlite3_bind_pointer: any; - sqlite3_busy_handler: any; - sqlite3_busy_timeout: any; - sqlite3_changes: any; - sqlite3_clear_bindings: any; - sqlite3_collation_needed: any; - sqlite3_column_blob: any; - sqlite3_column_bytes: any; - sqlite3_column_count: any; - sqlite3_column_double: any; - sqlite3_column_int: any; - sqlite3_column_name: any; - sqlite3_column_text: any; - sqlite3_column_type: any; - sqlite3_column_value: any; - sqlite3_commit_hook: any; - sqlite3_compileoption_get: any; - sqlite3_compileoption_used: any; - sqlite3_complete: any; - sqlite3_context_db_handle: any; - sqlite3_data_count: any; - sqlite3_db_filename: any; - sqlite3_db_handle: any; - sqlite3_db_name: any; - sqlite3_db_status: any; - sqlite3_errcode: any; - sqlite3_errmsg: any; - sqlite3_error_offset: any; - sqlite3_errstr: any; - sqlite3_expanded_sql: any; - sqlite3_extended_errcode: any; - sqlite3_extended_result_codes: any; - sqlite3_file_control: any; - sqlite3_finalize: any; - sqlite3_free: any; - sqlite3_get_auxdata: any; - sqlite3_initialize: any; - sqlite3_keyword_count: any; - sqlite3_keyword_name: any; - sqlite3_keyword_check: any; - sqlite3_libversion: any; - sqlite3_libversion_number: any; - sqlite3_limit: any; - sqlite3_malloc: any; - sqlite3_open: any; - sqlite3_open_v2: any; - sqlite3_progress_handler: any; - sqlite3_realloc: any; - sqlite3_reset: any; - sqlite3_result_blob: any; - sqlite3_result_double: any; - sqlite3_result_error: any; - sqlite3_result_error_code: any; - sqlite3_result_error_nomem: any; - sqlite3_result_error_toobig: any; - sqlite3_result_int: any; - sqlite3_result_null: any; - sqlite3_result_pointer: any; - sqlite3_result_subtype: any; - sqlite3_result_text: any; - sqlite3_result_zeroblob: any; - sqlite3_rollback_hook: any; - sqlite3_set_authorizer: any; - sqlite3_set_auxdata: any; - sqlite3_shutdown: any; - sqlite3_sourceid: any; - sqlite3_sql: any; - sqlite3_status: any; - sqlite3_step: any; - sqlite3_stmt_isexplain: any; - sqlite3_stmt_readonly: any; - sqlite3_stmt_status: any; - sqlite3_strglob: any; - sqlite3_stricmp: any; - sqlite3_strlike: any; - sqlite3_strnicmp: any; - sqlite3_table_column_metadata: any; - sqlite3_total_changes: any; - sqlite3_trace_v2: any; - sqlite3_txn_state: any; - sqlite3_uri_boolean: any; - sqlite3_uri_key: any; - sqlite3_uri_parameter: any; - sqlite3_user_data: any; - sqlite3_value_blob: any; - sqlite3_value_bytes: any; - sqlite3_value_double: any; - sqlite3_value_dup: any; - sqlite3_value_free: any; - sqlite3_value_frombind: any; - sqlite3_value_int: any; - sqlite3_value_nochange: any; - sqlite3_value_numeric_type: any; - sqlite3_value_pointer: any; - sqlite3_value_subtype: any; - sqlite3_value_text: any; - sqlite3_value_type: any; - sqlite3_vfs_find: any; - sqlite3_vfs_register: any; - sqlite3_vfs_unregister: any; - sqlite3_bind_int64: any; - sqlite3_changes64: any; - sqlite3_column_int64: any; - sqlite3_create_module: any; - sqlite3_create_module_v2: any; - sqlite3_declare_vtab: any; - sqlite3_deserialize: any; - sqlite3_drop_modules: any; - sqlite3_last_insert_rowid: any; - sqlite3_malloc64: any; - sqlite3_msize: any; - sqlite3_overload_function: any; - sqlite3_preupdate_blobwrite: any; - sqlite3_preupdate_count: any; - sqlite3_preupdate_depth: any; - sqlite3_preupdate_hook: any; - sqlite3_preupdate_new: any; - sqlite3_preupdate_old: any; - sqlite3_realloc64: any; - sqlite3_result_int64: any; - sqlite3_result_zeroblob64: any; - sqlite3_serialize: any; - sqlite3_set_last_insert_rowid: any; - sqlite3_status64: any; - sqlite3_total_changes64: any; - sqlite3_update_hook: any; - sqlite3_uri_int64: any; - sqlite3_value_int64: any; - sqlite3_vtab_collation: any; - sqlite3_vtab_distinct: any; - sqlite3_vtab_in: any; - sqlite3_vtab_in_first: any; - sqlite3_vtab_in_next: any; - sqlite3_vtab_nochange: any; - sqlite3_vtab_on_conflict: any; - sqlite3_vtab_rhs_value: any; - sqlite3changegroup_add: any; - sqlite3changegroup_add_strm: any; - sqlite3changegroup_delete: any; - sqlite3changegroup_new: any; - sqlite3changegroup_output: any; - sqlite3changegroup_output_strm: any; - sqlite3changeset_apply: any; - sqlite3changeset_apply_strm: any; - sqlite3changeset_apply_v2: any; - sqlite3changeset_apply_v2_strm: any; - sqlite3changeset_concat: any; - sqlite3changeset_concat_strm: any; - sqlite3changeset_conflict: any; - sqlite3changeset_finalize: any; - sqlite3changeset_fk_conflicts: any; - sqlite3changeset_invert: any; - sqlite3changeset_invert_strm: any; - sqlite3changeset_new: any; - sqlite3changeset_next: any; - sqlite3changeset_old: any; - sqlite3changeset_op: any; - sqlite3changeset_pk: any; - sqlite3changeset_start: any; - sqlite3changeset_start_strm: any; - sqlite3changeset_start_v2: any; - sqlite3changeset_start_v2_strm: any; - sqlite3session_attach: any; - sqlite3session_changeset: any; - sqlite3session_changeset_size: any; - sqlite3session_changeset_strm: any; - sqlite3session_config: any; - sqlite3session_create: any; - sqlite3session_diff: any; - sqlite3session_enable: any; - sqlite3session_indirect: any; - sqlite3session_isempty: any; - sqlite3session_memory_used: any; - sqlite3session_object_config: any; - sqlite3session_patchset: any; - sqlite3session_patchset_strm: any; - sqlite3session_table_filter: any; - SQLITE_ACCESS_EXISTS: any; - SQLITE_ACCESS_READWRITE: any; - SQLITE_ACCESS_READ: any; - SQLITE_DENY: any; - SQLITE_IGNORE: any; - SQLITE_CREATE_INDEX: any; - SQLITE_CREATE_TABLE: any; - SQLITE_CREATE_TEMP_INDEX: any; - SQLITE_CREATE_TEMP_TABLE: any; - SQLITE_CREATE_TEMP_TRIGGER: any; - SQLITE_CREATE_TEMP_VIEW: any; - SQLITE_CREATE_TRIGGER: any; - SQLITE_CREATE_VIEW: any; - SQLITE_DELETE: any; - SQLITE_DROP_INDEX: any; - SQLITE_DROP_TABLE: any; - SQLITE_DROP_TEMP_INDEX: any; - SQLITE_DROP_TEMP_TABLE: any; - SQLITE_DROP_TEMP_TRIGGER: any; - SQLITE_DROP_TEMP_VIEW: any; - SQLITE_DROP_TRIGGER: any; - SQLITE_DROP_VIEW: any; - SQLITE_INSERT: any; - SQLITE_PRAGMA: any; - SQLITE_READ: any; - SQLITE_SELECT: any; - SQLITE_TRANSACTION: any; - SQLITE_UPDATE: any; - SQLITE_ATTACH: any; - SQLITE_DETACH: any; - SQLITE_ALTER_TABLE: any; - SQLITE_REINDEX: any; - SQLITE_ANALYZE: any; - SQLITE_CREATE_VTABLE: any; - SQLITE_DROP_VTABLE: any; - SQLITE_FUNCTION: any; - SQLITE_SAVEPOINT: any; - SQLITE_RECURSIVE: any; - SQLITE_STATIC: any; - SQLITE_TRANSIENT: any; - SQLITE_WASM_DEALLOC: any; - SQLITE_CHANGESETSTART_INVERT: any; - SQLITE_CHANGESETAPPLY_NOSAVEPOINT: any; - SQLITE_CHANGESETAPPLY_INVERT: any; - SQLITE_CHANGESET_DATA: any; - SQLITE_CHANGESET_NOTFOUND: any; - SQLITE_CHANGESET_CONFLICT: any; - SQLITE_CHANGESET_CONSTRAINT: any; - SQLITE_CHANGESET_FOREIGN_KEY: any; - SQLITE_CHANGESET_OMIT: any; - SQLITE_CHANGESET_REPLACE: any; - SQLITE_CHANGESET_ABORT: any; - SQLITE_CONFIG_SINGLETHREAD: any; - SQLITE_CONFIG_MULTITHREAD: any; - SQLITE_CONFIG_SERIALIZED: any; - SQLITE_CONFIG_MALLOC: any; - SQLITE_CONFIG_GETMALLOC: any; - SQLITE_CONFIG_SCRATCH: any; - SQLITE_CONFIG_PAGECACHE: any; - SQLITE_CONFIG_HEAP: any; - SQLITE_CONFIG_MEMSTATUS: any; - SQLITE_CONFIG_MUTEX: any; - SQLITE_CONFIG_GETMUTEX: any; - SQLITE_CONFIG_LOOKASIDE: any; - SQLITE_CONFIG_PCACHE: any; - SQLITE_CONFIG_GETPCACHE: any; - SQLITE_CONFIG_LOG: any; - SQLITE_CONFIG_URI: any; - SQLITE_CONFIG_PCACHE2: any; - SQLITE_CONFIG_GETPCACHE2: any; - SQLITE_CONFIG_COVERING_INDEX_SCAN: any; - SQLITE_CONFIG_SQLLOG: any; - SQLITE_CONFIG_MMAP_SIZE: any; - SQLITE_CONFIG_WIN32_HEAPSIZE: any; - SQLITE_CONFIG_PCACHE_HDRSZ: any; - SQLITE_CONFIG_PMASZ: any; - SQLITE_CONFIG_STMTJRNL_SPILL: any; - SQLITE_CONFIG_SMALL_MALLOC: any; - SQLITE_CONFIG_SORTERREF_SIZE: any; - SQLITE_CONFIG_MEMDB_MAXSIZE: any; - SQLITE_INTEGER: any; - SQLITE_FLOAT: any; - SQLITE_TEXT: any; - SQLITE_BLOB: any; - SQLITE_NULL: any; - SQLITE_DBCONFIG_MAINDBNAME: any; - SQLITE_DBCONFIG_LOOKASIDE: any; - SQLITE_DBCONFIG_ENABLE_FKEY: any; - SQLITE_DBCONFIG_ENABLE_TRIGGER: any; - SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER: any; - SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION: any; - SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE: any; - SQLITE_DBCONFIG_ENABLE_QPSG: any; - SQLITE_DBCONFIG_TRIGGER_EQP: any; - SQLITE_DBCONFIG_RESET_DATABASE: any; - SQLITE_DBCONFIG_DEFENSIVE: any; - SQLITE_DBCONFIG_WRITABLE_SCHEMA: any; - SQLITE_DBCONFIG_LEGACY_ALTER_TABLE: any; - SQLITE_DBCONFIG_DQS_DML: any; - SQLITE_DBCONFIG_DQS_DDL: any; - SQLITE_DBCONFIG_ENABLE_VIEW: any; - SQLITE_DBCONFIG_LEGACY_FILE_FORMAT: any; - SQLITE_DBCONFIG_TRUSTED_SCHEMA: any; - SQLITE_DBCONFIG_MAX: any; - SQLITE_DBSTATUS_LOOKASIDE_USED: any; - SQLITE_DBSTATUS_CACHE_USED: any; - SQLITE_DBSTATUS_SCHEMA_USED: any; - SQLITE_DBSTATUS_STMT_USED: any; - SQLITE_DBSTATUS_LOOKASIDE_HIT: any; - SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE: any; - SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL: any; - SQLITE_DBSTATUS_CACHE_HIT: any; - SQLITE_DBSTATUS_CACHE_MISS: any; - SQLITE_DBSTATUS_CACHE_WRITE: any; - SQLITE_DBSTATUS_DEFERRED_FKS: any; - SQLITE_DBSTATUS_CACHE_USED_SHARED: any; - SQLITE_DBSTATUS_CACHE_SPILL: any; - SQLITE_DBSTATUS_MAX: any; - SQLITE_UTF8: any; - SQLITE_UTF16LE: any; - SQLITE_UTF16BE: any; - SQLITE_UTF16: any; - SQLITE_UTF16_ALIGNED: any; - SQLITE_FCNTL_LOCKSTATE: any; - SQLITE_FCNTL_GET_LOCKPROXYFILE: any; - SQLITE_FCNTL_SET_LOCKPROXYFILE: any; - SQLITE_FCNTL_LAST_ERRNO: any; - SQLITE_FCNTL_SIZE_HINT: any; - SQLITE_FCNTL_CHUNK_SIZE: any; - SQLITE_FCNTL_FILE_POINTER: any; - SQLITE_FCNTL_SYNC_OMITTED: any; - SQLITE_FCNTL_WIN32_AV_RETRY: any; - SQLITE_FCNTL_PERSIST_WAL: any; - SQLITE_FCNTL_OVERWRITE: any; - SQLITE_FCNTL_VFSNAME: any; - SQLITE_FCNTL_POWERSAFE_OVERWRITE: any; - SQLITE_FCNTL_PRAGMA: any; - SQLITE_FCNTL_BUSYHANDLER: any; - SQLITE_FCNTL_TEMPFILENAME: any; - SQLITE_FCNTL_MMAP_SIZE: any; - SQLITE_FCNTL_TRACE: any; - SQLITE_FCNTL_HAS_MOVED: any; - SQLITE_FCNTL_SYNC: any; - SQLITE_FCNTL_COMMIT_PHASETWO: any; - SQLITE_FCNTL_WIN32_SET_HANDLE: any; - SQLITE_FCNTL_WAL_BLOCK: any; - SQLITE_FCNTL_ZIPVFS: any; - SQLITE_FCNTL_RBU: any; - SQLITE_FCNTL_VFS_POINTER: any; - SQLITE_FCNTL_JOURNAL_POINTER: any; - SQLITE_FCNTL_WIN32_GET_HANDLE: any; - SQLITE_FCNTL_PDB: any; - SQLITE_FCNTL_BEGIN_ATOMIC_WRITE: any; - SQLITE_FCNTL_COMMIT_ATOMIC_WRITE: any; - SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE: any; - SQLITE_FCNTL_LOCK_TIMEOUT: any; - SQLITE_FCNTL_DATA_VERSION: any; - SQLITE_FCNTL_SIZE_LIMIT: any; - SQLITE_FCNTL_CKPT_DONE: any; - SQLITE_FCNTL_RESERVE_BYTES: any; - SQLITE_FCNTL_CKPT_START: any; - SQLITE_FCNTL_EXTERNAL_READER: any; - SQLITE_FCNTL_CKSM_FILE: any; - SQLITE_LOCK_NONE: any; - SQLITE_LOCK_SHARED: any; - SQLITE_LOCK_RESERVED: any; - SQLITE_LOCK_PENDING: any; - SQLITE_LOCK_EXCLUSIVE: any; - SQLITE_IOCAP_ATOMIC: any; - SQLITE_IOCAP_ATOMIC512: any; - SQLITE_IOCAP_ATOMIC1K: any; - SQLITE_IOCAP_ATOMIC2K: any; - SQLITE_IOCAP_ATOMIC4K: any; - SQLITE_IOCAP_ATOMIC8K: any; - SQLITE_IOCAP_ATOMIC16K: any; - SQLITE_IOCAP_ATOMIC32K: any; - SQLITE_IOCAP_ATOMIC64K: any; - SQLITE_IOCAP_SAFE_APPEND: any; - SQLITE_IOCAP_SEQUENTIAL: any; - SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN: any; - SQLITE_IOCAP_POWERSAFE_OVERWRITE: any; - SQLITE_IOCAP_IMMUTABLE: any; - SQLITE_IOCAP_BATCH_ATOMIC: any; - SQLITE_MAX_ALLOCATION_SIZE: any; - SQLITE_LIMIT_LENGTH: any; - SQLITE_MAX_LENGTH: any; - SQLITE_LIMIT_SQL_LENGTH: any; - SQLITE_MAX_SQL_LENGTH: any; - SQLITE_LIMIT_COLUMN: any; - SQLITE_MAX_COLUMN: any; - SQLITE_LIMIT_EXPR_DEPTH: any; - SQLITE_MAX_EXPR_DEPTH: any; - SQLITE_LIMIT_COMPOUND_SELECT: any; - SQLITE_MAX_COMPOUND_SELECT: any; - SQLITE_LIMIT_VDBE_OP: any; - SQLITE_MAX_VDBE_OP: any; - SQLITE_LIMIT_FUNCTION_ARG: any; - SQLITE_MAX_FUNCTION_ARG: any; - SQLITE_LIMIT_ATTACHED: any; - SQLITE_MAX_ATTACHED: any; - SQLITE_LIMIT_LIKE_PATTERN_LENGTH: any; - SQLITE_MAX_LIKE_PATTERN_LENGTH: any; - SQLITE_LIMIT_VARIABLE_NUMBER: any; - SQLITE_MAX_VARIABLE_NUMBER: any; - SQLITE_LIMIT_TRIGGER_DEPTH: any; - SQLITE_MAX_TRIGGER_DEPTH: any; - SQLITE_LIMIT_WORKER_THREADS: any; - SQLITE_MAX_WORKER_THREADS: any; - SQLITE_OPEN_READONLY: any; - SQLITE_OPEN_READWRITE: any; - SQLITE_OPEN_CREATE: any; - SQLITE_OPEN_URI: any; - SQLITE_OPEN_MEMORY: any; - SQLITE_OPEN_NOMUTEX: any; - SQLITE_OPEN_FULLMUTEX: any; - SQLITE_OPEN_SHAREDCACHE: any; - SQLITE_OPEN_PRIVATECACHE: any; - SQLITE_OPEN_EXRESCODE: any; - SQLITE_OPEN_NOFOLLOW: any; - SQLITE_OPEN_MAIN_DB: any; - SQLITE_OPEN_MAIN_JOURNAL: any; - SQLITE_OPEN_TEMP_DB: any; - SQLITE_OPEN_TEMP_JOURNAL: any; - SQLITE_OPEN_TRANSIENT_DB: any; - SQLITE_OPEN_SUBJOURNAL: any; - SQLITE_OPEN_SUPER_JOURNAL: any; - SQLITE_OPEN_WAL: any; - SQLITE_OPEN_DELETEONCLOSE: any; - SQLITE_OPEN_EXCLUSIVE: any; - SQLITE_PREPARE_PERSISTENT: any; - SQLITE_PREPARE_NORMALIZE: any; - SQLITE_PREPARE_NO_VTAB: any; - SQLITE_OK: any; - SQLITE_ERROR: any; - SQLITE_INTERNAL: any; - SQLITE_PERM: any; - SQLITE_ABORT: any; - SQLITE_BUSY: any; - SQLITE_LOCKED: any; - SQLITE_NOMEM: any; - SQLITE_READONLY: any; - SQLITE_INTERRUPT: any; - SQLITE_IOERR: any; - SQLITE_CORRUPT: any; - SQLITE_NOTFOUND: any; - SQLITE_FULL: any; - SQLITE_CANTOPEN: any; - SQLITE_PROTOCOL: any; - SQLITE_EMPTY: any; - SQLITE_SCHEMA: any; - SQLITE_TOOBIG: any; - SQLITE_CONSTRAINT: any; - SQLITE_MISMATCH: any; - SQLITE_MISUSE: any; - SQLITE_NOLFS: any; - SQLITE_AUTH: any; - SQLITE_FORMAT: any; - SQLITE_RANGE: any; - SQLITE_NOTADB: any; - SQLITE_NOTICE: any; - SQLITE_WARNING: any; - SQLITE_ROW: any; - SQLITE_DONE: any; - SQLITE_ERROR_MISSING_COLLSEQ: any; - SQLITE_ERROR_RETRY: any; - SQLITE_ERROR_SNAPSHOT: any; - SQLITE_IOERR_READ: any; - SQLITE_IOERR_SHORT_READ: any; - SQLITE_IOERR_WRITE: any; - SQLITE_IOERR_FSYNC: any; - SQLITE_IOERR_DIR_FSYNC: any; - SQLITE_IOERR_TRUNCATE: any; - SQLITE_IOERR_FSTAT: any; - SQLITE_IOERR_UNLOCK: any; - SQLITE_IOERR_RDLOCK: any; - SQLITE_IOERR_DELETE: any; - SQLITE_IOERR_BLOCKED: any; - SQLITE_IOERR_NOMEM: any; - SQLITE_IOERR_ACCESS: any; - SQLITE_IOERR_CHECKRESERVEDLOCK: any; - SQLITE_IOERR_LOCK: any; - SQLITE_IOERR_CLOSE: any; - SQLITE_IOERR_DIR_CLOSE: any; - SQLITE_IOERR_SHMOPEN: any; - SQLITE_IOERR_SHMSIZE: any; - SQLITE_IOERR_SHMLOCK: any; - SQLITE_IOERR_SHMMAP: any; - SQLITE_IOERR_SEEK: any; - SQLITE_IOERR_DELETE_NOENT: any; - SQLITE_IOERR_MMAP: any; - SQLITE_IOERR_GETTEMPPATH: any; - SQLITE_IOERR_CONVPATH: any; - SQLITE_IOERR_VNODE: any; - SQLITE_IOERR_AUTH: any; - SQLITE_IOERR_BEGIN_ATOMIC: any; - SQLITE_IOERR_COMMIT_ATOMIC: any; - SQLITE_IOERR_ROLLBACK_ATOMIC: any; - SQLITE_IOERR_DATA: any; - SQLITE_IOERR_CORRUPTFS: any; - SQLITE_LOCKED_SHAREDCACHE: any; - SQLITE_LOCKED_VTAB: any; - SQLITE_BUSY_RECOVERY: any; - SQLITE_BUSY_SNAPSHOT: any; - SQLITE_BUSY_TIMEOUT: any; - SQLITE_CANTOPEN_NOTEMPDIR: any; - SQLITE_CANTOPEN_ISDIR: any; - SQLITE_CANTOPEN_FULLPATH: any; - SQLITE_CANTOPEN_CONVPATH: any; - SQLITE_CANTOPEN_SYMLINK: any; - SQLITE_CORRUPT_VTAB: any; - SQLITE_CORRUPT_SEQUENCE: any; - SQLITE_CORRUPT_INDEX: any; - SQLITE_READONLY_RECOVERY: any; - SQLITE_READONLY_CANTLOCK: any; - SQLITE_READONLY_ROLLBACK: any; - SQLITE_READONLY_DBMOVED: any; - SQLITE_READONLY_CANTINIT: any; - SQLITE_READONLY_DIRECTORY: any; - SQLITE_ABORT_ROLLBACK: any; - SQLITE_CONSTRAINT_CHECK: any; - SQLITE_CONSTRAINT_COMMITHOOK: any; - SQLITE_CONSTRAINT_FOREIGNKEY: any; - SQLITE_CONSTRAINT_FUNCTION: any; - SQLITE_CONSTRAINT_NOTNULL: any; - SQLITE_CONSTRAINT_PRIMARYKEY: any; - SQLITE_CONSTRAINT_TRIGGER: any; - SQLITE_CONSTRAINT_UNIQUE: any; - SQLITE_CONSTRAINT_VTAB: any; - SQLITE_CONSTRAINT_ROWID: any; - SQLITE_CONSTRAINT_PINNED: any; - SQLITE_CONSTRAINT_DATATYPE: any; - SQLITE_NOTICE_RECOVER_WAL: any; - SQLITE_NOTICE_RECOVER_ROLLBACK: any; - SQLITE_WARNING_AUTOINDEX: any; - SQLITE_AUTH_USER: any; - SQLITE_OK_LOAD_PERMANENTLY: any; - SQLITE_STATUS_MEMORY_USED: any; - SQLITE_STATUS_PAGECACHE_USED: any; - SQLITE_STATUS_PAGECACHE_OVERFLOW: any; - SQLITE_STATUS_MALLOC_SIZE: any; - SQLITE_STATUS_PARSER_STACK: any; - SQLITE_STATUS_PAGECACHE_SIZE: any; - SQLITE_STATUS_MALLOC_COUNT: any; - SQLITE_STMTSTATUS_FULLSCAN_STEP: any; - SQLITE_STMTSTATUS_SORT: any; - SQLITE_STMTSTATUS_AUTOINDEX: any; - SQLITE_STMTSTATUS_VM_STEP: any; - SQLITE_STMTSTATUS_REPREPARE: any; - SQLITE_STMTSTATUS_RUN: any; - SQLITE_STMTSTATUS_FILTER_MISS: any; - SQLITE_STMTSTATUS_FILTER_HIT: any; - SQLITE_STMTSTATUS_MEMUSED: any; - SQLITE_SYNC_NORMAL: any; - SQLITE_SYNC_FULL: any; - SQLITE_SYNC_DATAONLY: any; - SQLITE_TRACE_STMT: any; - SQLITE_TRACE_PROFILE: any; - SQLITE_TRACE_ROW: any; - SQLITE_TRACE_CLOSE: any; - SQLITE_TXN_NONE: any; - SQLITE_TXN_READ: any; - SQLITE_TXN_WRITE: any; - SQLITE_DETERMINISTIC: any; - SQLITE_DIRECTONLY: any; - SQLITE_INNOCUOUS: any; - SQLITE_VERSION_NUMBER: any; - SQLITE_VERSION: any; - SQLITE_SOURCE_ID: any; - SQLITE_SERIALIZE_NOCOPY: any; - SQLITE_DESERIALIZE_FREEONCLOSE: any; - SQLITE_DESERIALIZE_READONLY: any; - SQLITE_DESERIALIZE_RESIZEABLE: any; - SQLITE_SESSION_CONFIG_STRMSIZE: any; - SQLITE_SESSION_OBJCONFIG_SIZE: any; - SQLITE_INDEX_SCAN_UNIQUE: any; - SQLITE_INDEX_CONSTRAINT_EQ: any; - SQLITE_INDEX_CONSTRAINT_GT: any; - SQLITE_INDEX_CONSTRAINT_LE: any; - SQLITE_INDEX_CONSTRAINT_LT: any; - SQLITE_INDEX_CONSTRAINT_GE: any; - SQLITE_INDEX_CONSTRAINT_MATCH: any; - SQLITE_INDEX_CONSTRAINT_LIKE: any; - SQLITE_INDEX_CONSTRAINT_GLOB: any; - SQLITE_INDEX_CONSTRAINT_REGEXP: any; - SQLITE_INDEX_CONSTRAINT_NE: any; - SQLITE_INDEX_CONSTRAINT_ISNOT: any; - SQLITE_INDEX_CONSTRAINT_ISNOTNULL: any; - SQLITE_INDEX_CONSTRAINT_ISNULL: any; - SQLITE_INDEX_CONSTRAINT_IS: any; - SQLITE_INDEX_CONSTRAINT_LIMIT: any; - SQLITE_INDEX_CONSTRAINT_OFFSET: any; - SQLITE_INDEX_CONSTRAINT_FUNCTION: any; - SQLITE_VTAB_CONSTRAINT_SUPPORT: any; - SQLITE_VTAB_INNOCUOUS: any; - SQLITE_VTAB_DIRECTONLY: any; - SQLITE_ROLLBACK: any; - SQLITE_FAIL: any; - SQLITE_REPLACE: any; - sqlite3_js_rc_str: any; - sqlite3_vfs: any; - sqlite3_io_methods: any; - sqlite3_file: any; - sqlite3_vtab: any; - sqlite3_vtab_cursor: any; - sqlite3_module: any; - sqlite3_index_info: any; - sqlite3_vtab_config: any; - sqlite3_close_v2: any; - sqlite3session_delete: any; - sqlite3_create_collation_v2: any; - sqlite3_create_collation: any; - sqlite3_config: any; - sqlite3_auto_extension: any; - sqlite3_cancel_auto_extension: any; - sqlite3_reset_auto_extension: any; + /** + * Allocates n bytes of memory from the WASM heap and returns the address of + * the first byte in the block. `alloc()` throws a {@link WasmAllocError} if + * allocation fails. If non-thowing allocation is required, use + * {@link WASM_API#alloc.impl}, which returns a WASM NULL pointer (the integer + * 0) if allocation fails. + * + * Note that memory allocated this way is not automatically zeroed out. In + * practice that has not proven to be a problem (in JS, at least) because + * memory is only explicitly allocated when it has a specific use and will be + * populated by the code which allocates it. + */ + alloc: ((numBytes: number) => WasmPointer) & { + impl: (numBytes: number) => WasmPointer; }; - // generated by console.log(Object.keys(sqlite3.wasm).map(t => ` ${t}: any;`).join('\n')) - type WASM_API = { - ptrSizeof: any; - ptrIR: any; - bigIntEnabled: any; - exports: any; - memory: any; - alloc: any; - realloc: any; - dealloc: any; - allocFromTypedArray: any; - compileOptionUsed: any; - pstack: any; - sizeofIR: any; - heap8: any; - heap8u: any; - heap16: any; - heap16u: any; - heap32: any; - heap32u: any; - heapForSize: any; - functionTable: any; - functionEntry: any; - jsFuncToWasm: any; - installFunction: any; - scopedInstallFunction: any; - uninstallFunction: any; - peek: any; - poke: any; - peekPtr: any; - pokePtr: any; - peek8: any; - poke8: any; - peek16: any; - poke16: any; - peek32: any; - poke32: any; - peek64: any; - poke64: any; - peek32f: any; - poke32f: any; - peek64f: any; - poke64f: any; - getMemValue: any; - getPtrValue: any; - setMemValue: any; - setPtrValue: any; - isPtr32: any; - isPtr: any; - cstrlen: any; - cstrToJs: any; - jstrlen: any; - jstrcpy: any; - cstrncpy: any; - jstrToUintArray: any; - allocCString: any; - scopedAllocPush: any; - scopedAllocPop: any; - scopedAlloc: any; - scopedAllocCString: any; - scopedAllocMainArgv: any; - allocMainArgv: any; - cArgvToJs: any; - scopedAllocCall: any; - allocPtr: any; - scopedAllocPtr: any; - xGet: any; - xCall: any; - xWrap: any; - xCallWrapped: any; - sqlite3_wasm_db_reset: any; - sqlite3_wasm_db_vfs: any; - sqlite3_wasm_vfs_create_file: any; - sqlite3_wasm_vfs_unlink: any; - ctype: any; + /** + * Uses {@link WASM_API#alloc} to allocate enough memory for the byte-length of + * the given JS string, plus 1 (for a `NUL` terminator), copies the given JS + * string to that memory using `jstrcpy()`, `NUL`-terminates it, and returns + * the pointer to that C-string. Ownership of the pointer is transfered to the + * caller, who must eventually pass the pointer to {@link WASM_API#dealloc} to + * free it. + * + * If passed a truthy 2nd argument then its return semantics change: it + * returns `[ptr,n]`, where `ptr` is the C-string's pointer and n is its + * cstrlen(). + */ + allocCString( + jsString: string, + returnPtrAndLength: undefined | false, + ): WasmPointer; + allocCString( + jsString: string, + returnPtrAndLength: true, + ): [WasmPointer, number]; + + /** + * Creates a C-style array, using `alloc()`, suitable for passing to a C-level + * `main()` routine. The input is a collection with a `length` property and a + * `forEach()` method. A block of memory `list.length` entries long is + * allocated and each pointer-sized block of that memory is populated with the + * `allocCString()` conversion of the `(''+value)` of each element. Returns a + * pointer to the start of the list, suitable for passing as the 2nd argument + * to a C-style `main()` function. + * + * Throws if `list.length` is falsy. + * + * Note that the returned value is troublesome to deallocate but it is + * intended for use with calling a C-level `main()` function, where the + * strings must live as long as the application. See `scopedAllocMainArgv()` + * for a variant which is trivial to deallocate. + */ + allocMainArgv: (list: ListLike<{ toString(): string }>) => WasmPointer; + + /** + * Allocates one or more pointers as a single chunk of memory and zeroes them + * out. + * + * The first argument is the number of pointers to allocate. The second + * specifies whether they should use a "safe" pointer size (8 bytes) or + * whether they may use the default pointer size (typically 4 but also + * possibly 8). + * + * How the result is returned depends on its first argument: if passed 1, it + * returns the allocated memory address. If passed more than one then an array + * of pointer addresses is returned, which can optionally be used with + * "destructuring assignment" like this: + * + * Const[(p1, p2, p3)] = allocPtr(3); + * + * **ACHTUNG:** when freeing the memory, pass only the first result value to + * `dealloc()`. The others are part of the same memory chunk and must not be + * freed separately. + * + * The reason for the 2nd argument is... + * + * When one of the returned pointers will refer to a 64-bit value, e.g. a + * `double` or `int64`, and that value must be written or fetched, e.g. using + * `poke()` or `peek()`, it is important that the pointer in question be + * aligned to an 8-byte boundary or else it will not be fetched or written + * properly and will corrupt or read neighboring memory. It is only safe to + * pass false when the client code is certain that it will only get/fetch + * 4-byte values (or smaller). + */ + allocPtr(howMany: 1 | undefined, safePtrSize?: boolean): WasmPointer; + allocPtr(howMany: number, safePtrSize?: boolean): WasmPointer[]; + + /** + * Frees memory returned by `alloc()`. Results are undefined if it is passed + * any value other than a value returned by `alloc()` or + * `null`/`undefined`/`0` (all of which are no-ops). + */ + dealloc: (ptr: WasmPointer) => void; + + /** + * Semantically equivalent to `realloc(3)` or `sqlite3_realloc()`, this + * routine reallocates memory allocated via this routine or `alloc()`. Its + * first argument is either 0 or a pointer returned by this routine or + * `alloc()`. Its second argument is the number of bytes to (re)allocate, or 0 + * to free the memory specified in the first argument. On allocation error, + * `realloc()` throws a `WasmAllocError`, whereas `realloc.impl()` will return + * `0` on allocation error. + * + * Beware that reassigning the return value of `realloc.impl()` is poor + * practice and can lead to leaks of heap memory: + * + * Let m = wasm.realloc(0, 10); // allocate 10 bytes m = + * wasm.realloc.impl(m, 20); // grow m to 20 bytes + * + * If that reallocation fails, it will return 0, overwriting `m` and + * effectively leaking the first allocation. + */ + realloc: ((ptr: WasmPointer, numBytes: number) => WasmPointer) & { + impl: (ptr: WasmPointer, numBytes: number) => WasmPointer; }; -} + + /** + * For the given IR-like string in the set ('i8', 'i16', 'i32', 'f32', + * 'float', 'i64', 'f64', 'double', '_'), or any string value ending in '_', + * returns the sizeof for that value (wasm.ptrSizeof in the latter case). For + * any other value, it returns the undefined value. + * + * Some allocation routines use this enable callers to pass them an IR value + * instead of an integer. + */ + sizeofIR: ( + irStr: + | 'i8' + | 'i16' + | 'i32' + | 'f32' + | 'float' + | 'i64' + | 'f64' + | 'double' + | '_' + | string, + ) => number; + + /* -------------------------------------------------------------------------- + * "Scoped" Allocation Management + * -------------------------------------------------------------------------- + * + * It is often convenient to manage allocations in such a way that all + * allocations made in a particular block are "automatically" cleaned up + * when that block exits. This API provides "scoped" allocation routines + * which work this way. + */ + + /** + * Opens a new "scope" for allocations. All allocations made via the + * `scopedAllocXyz()` APIs will store their results into the current (most + * recently pushed) allocation scope for later cleanup. The returned value + * must be retained for passing to `scopedAllocPop()`. + * + * Any number of scopes may be active at once, but they must be popped in + * reverse order of their creation. i.e. they must nest in a manner equivalent + * to C-style scopes. + * + * **Warnings:** + * + * - All of the other `scopedAllocXyz()` routines will throw if no scope is + * active. + * - It is never legal to pass the result of a scoped allocation to `dealloc()`, + * and doing so will cause a double-free when the scope is closed with + * `scopedAllocPop()`. + * + * This function and its relatives have only a single intended usage pattern: + * + * Const scope = wasm.scopedAllocPush(); + * try { + * ... use scopedAllocXyz() routines ... + * // It is perfectly legal to use non-scoped allocations here, + * // they just won't be cleaned up when... + * } finally { + * wasm.scopedAllocPop(scope); + * } + */ + scopedAllocPush: () => WasmPointer; + + /** + * Works just like `alloc(n)` but stores the result of the allocation in the + * current scope. + * + * This function's read-only `level` property resolves to the current + * allocation scope dep + */ + scopedAlloc: ((numBytes: number) => WasmPointer) & { level: number }; + + /** + * This functions exactly like `allocMainArgv()` but is scoped to the current + * allocation scope and its contents will be freed when the current allocation + * scoped is popped. + */ + scopedAllocMainArgv: (list: ListLike<{ toString(): string }>) => WasmPointer; + + /** + * Calls `scopedAllocPush()`, calls the given `callback`, and then calls + * `scopedAllocPop()`, propagating any exception from the callback or + * returning its result. This is essentially a convenience form of: + * + * const scope = wasm.scopedAllocPush(); + * try { + * return callback(); + * } finally { + * wasm.scopedAllocPop(scope); + * } + */ + scopedAllocCall: (callback: () => T) => T; + + /** + * Works just like `allocCString()` but stores the result of the allocation in + * the current scope. + */ + scopedAllocCString( + jsString: string, + returnWithLength: undefined | false, + ): WasmPointer; + scopedAllocCString( + jsString: string, + returnPtrAndLength: true, + ): [WasmPointer, number]; + + /** + * Works just like `allocPtr()` but stores the result of the allocation in the + * current scope. + */ + scopedAllocPt(howMany: 1 | undefined, safePtrSize?: boolean): WasmPointer; + scopedAllocPtr(howMany: number, safePtrSize?: boolean): WasmPointer[]; + + /** + * Given a value returned from `scopedAllocPush()`, this "pops" that + * allocation scope and frees all memory allocated in that scope by the + * `scopedAllocXyz()` family of APIs. + * + * It is technically legal to call this without any argument, but passing an + * argument allows the allocator to perform sanity checking to ensure that + * scopes are pushed and popped in the proper order (it throws if they are + * not). Failing to pass an argument is not illegal but will make that sanity + * check impossible. + */ + scopedAllocPop: (opaque: WasmPointer) => void; + + /* -------------------------------------------------------------------------- + * "PStack" Allocation + * -------------------------------------------------------------------------- + * The "pstack" (pseudo-stack) API is a special-purpose allocator intended + * solely for use with allocating small amounts of memory such as that + * needed for output pointers. It is more efficient than the scoped + * allocation API, and covers many of the use cases for that API, but it has + * a tiny static memory limit (with an unspecified total size no less than + * 4kb). + + * The pstack API is typically used like: + * + * const pstack = sqlite3.wasm.pstack; + * const stackPtr = pstack.pointer; + * try { + * const ptr = pstack.alloc(8); + * // ==> pstack.pointer === ptr + * const otherPtr = pstack.alloc(8); + * // ==> pstack.pointer === otherPtr + * ... + * } finally { + * pstack.restore(stackPtr); + * // ==> pstack.pointer === stackPtr + * } + */ + pstack: { + /** + * Attempts to allocate the given number of bytes from the pstack. On + * success, it zeroes out a block of memory of the given size, adjusts the + * pstack pointer, and returns a pointer to the memory. On error, returns + * throws a `WasmAllocError`. The memory must eventually be released using + * `pstack.restore()`. + * + * The `n` may be a string accepted by `wasm.sizeofIR()`, and any string + * value not accepted by that function will trigger a `WasmAllocError` + * exception. + * + * This method always adjusts the given value to be a multiple of 8 bytes + * because failing to do so can lead to incorrect results when reading and + * writing 64-bit values from/to the WASM heap. Similarly, the returned + * address is always 8-byte aligned. + */ + alloc: (n: number | string) => WasmPointer; + + /** + * `Alloc()`'s `n` chunks, each `sz` bytes, as a single memory block and + * returns the addresses as an array of `n` element, each holding the + * address of one chunk. + * + * The `sz` argument may be a string value accepted by `wasm.sizeofIR()`, + * and any string value not accepted by that function will trigger a + * `WasmAllocError` exception. + * + * Throws a `WasmAllocError` if allocation fails. + * + * Example: + * + * Const[(p1, p2, p3)] = pstack.allocChunks(3, 4); + */ + allocChunks: (n: number, sz: number | string) => WasmPointer[]; + + /** + * A convenience wrapper for `allocChunks()` which sizes each chunk as + * either 8 bytes (`safePtrSize` is truthy) or `wasm.ptrSizeof` (if + * `safePtrSize` is falsy). + * + * How it returns its result differs depending on its first argument: if + * it's 1, it returns a single pointer value. If it's more than 1, it + * returns the same as `allocChunks()`. + * + * When any returned pointers will refer to a 64-bit value, e.g. a double or + * int64, and that value must be written or fetched, e.g. using + * `wasm.poke()` or `wasm.peek()`, it is important that the pointer in + * question be aligned to an 8-byte boundary or else it will not be fetched + * or written properly and will corrupt or read neighboring memory. + * + * However, when all pointers involved point to "small" data, it is safe to + * pass a falsy value to save a tiny bit of memory. + */ + allocPtr(howMany: 1 | undefined, safePtrSize?: boolean): WasmPointer; + allocPtr(howMany: number, safePtrSize?: boolean): WasmPointer[]; + + /** + * This property resolves to the current pstack position pointer. This value + * is intended only to be saved for passing to `restore()`. Writing to this + * memory, without first reserving it via `pstack.alloc()` (or equivalent) + * leads to undefined results. + */ + pointer: WasmPointer; + + /** + * This property resolves to the total number of bytes available in the + * pstack, including any space which is currently allocated. This value is a + * compile-time constant.unknown + */ + quota: number; + + /** This property resolves to the amount of space remaining in the pstack. */ + remaining: number; + + /** + * Sets the current pstack position to the given pointer. Results are + * `undefined` if the passed-in value did not come from `pstack.pointer` or + * if memory allocated in the space before the given pointer are used after + * this call. + */ + restore: (pstackptr: WasmPointer) => void; + }; + + /* -------------------------------------------------------------------------- + * Getting/Setting Memory Values + * -------------------------------------------------------------------------- + * + * The WASM memory heap is exposed to JS as a byte array of memory which is + * made to appear contiguous (though it's really allocated in chunks). Given + * a byte-oriented view of the heap, it is possible to read and write + * individual bytes of the heap, just like in C: + * + * const X = wasm.heap8u(); // a uint8-oriented view of the heap + * X[someAddress] = 0x2a; + * console.log( X[someAddress] ); // ==> 42 + * + * Obviously, writing arbitrary addresses can corrupt the WASM heap, just like in + * C, so one has to be careful with the memory addresses the work with (just like + * in C!). + * + * Tip: it is important never to hold on to objects returned from methods + * like `heap8u()` long-term, as they may be invalidated if the heap grows. + * It is acceptable to hold the reference for a brief series of calls, so + * long as those calls are guaranteed not to allocate memory on the WASM + * heap, but it should never be cached for later use. + * + * Before describing the routines for manipulating the heap, we first need + * to look at data type descriptors, sometimes referred to as "IR" (internal + * representation). These are short strings which identify the specific data + * types supported by WASM and/or the JS/WASM glue code: + * + * - `i8`: 8-bit signed integer + * - `i16`: 16-bit signed integer + * - `i32`: 32-bit signed integer. Aliases: `int`, `*`, `**` (noting that + * `*` and `**` may be remapped dynamically to to i64 when WASM environments + * gain 64-bit pointer capabilities). + * - `i64`: 64-bit signed integer. APIs which use this require that the + * application has been built with BigInt support, and will throw if that is + * not the case. + * - `f32`: 32-bit floating point value. Alias: float + * - `f64`: 64-bit floating point value. Alias: double + * + * These are used extensively by the memory accessor APIs and need to be + * committed to memory. + */ + + /** + * The first form fetches a single value from memory. The second form fetches + * the value from each pointer in the given array and returns the array of + * values. The heap view used for reading the memory is specified by the + * second argument, defaulting to byte-oriented view. + * + * If the 2nd argument ends with `"*"` then the pointer-sized representation + * is always used (currently always 32 bits). + */ + peek(addr: WasmPointer, representation?: string): number; + peek(addrs: WasmPointer[], representation?: string): number[]; + + /** + * Equivalent to `peek(X,'*')`. Most frequently used for fetching output + * pointer values. + */ + peekPtr: (addr: WasmPointer) => number; + + /** Equivalent to peek(X,'i8') */ + peek8: (addr: WasmPointer) => number; + + /** Equivalent to peek(X,'i16') */ + peek16: (addr: WasmPointer) => number; + + /** Equivalent to peek(X,'i32') */ + peek32: (addr: WasmPointer) => number; + + /** + * Equivalent to peek(X,'i64'). Will throw if the environment is not + * configured with BigInt support. + */ + peek64: (addr: WasmPointer) => BigInt; + + /** Equivalent to peek(X,'f32') */ + peek32f: (addr: WasmPointer) => number; + + /** Equivalent to peek(X,'f64') */ + peek64f: (addr: WasmPointer) => number; + + /** + * Requires `n` to be one of: + * + * - Integer 8, 16, or 32. + * - A integer-type TypedArray constructor: `Int8Array`, `Int16Array`, + * `Int32Array`, or their `Uint` counterparts. + * + * If `BigInt` support is enabled, it also accepts the value 64 or a + * `BigInt64Array`/`BigUint64Array`, else it throws if passed 64 or one of + * those constructors. + * + * Returns an integer-based `TypedArray` view of the WASM heap memory buffer + * associated with the given block size. If passed an integer as the first + * argument and unsigned is truthy then the `"U"` (unsigned) variant of that + * view is returned, else the signed variant is returned. If passed a + * `TypedArray` value, the 2nd argument is ignored. Note that `Float32Array` + * and `Float64Array` views are not supported by this function. + * + * Be aware that growth of the heap may invalidate any references to this + * heap, so do not hold a reference longer than needed and do not use a + * reference after any operation which may allocate. Instead, re-fetch the + * reference by calling this function again, which automatically refreshes the + * view if need. + * + * Throws if passed an invalid `n`. + * + * Use of this function in client code is very rare. In practice, one of the + * (faster) convenience forms is used. + */ + heapForSize(n: 8, unsigned: false | undefined): Int8Array; + heapForSize(n: 8, unsigned: true): Uint8Array; + heapForSize(n: typeof Int8Array): Int8Array; + heapForSize(n: typeof Uint8Array): Uint8Array; + heapForSize(n: 16, unsigned: false | undefined): Int16Array; + heapForSize(n: 16, unsigned: true): Uint16Array; + heapForSize(n: typeof Int16Array): Int16Array; + heapForSize(n: typeof Uint16Array): Uint16Array; + heapForSize(n: 32, unsigned: false | undefined): Int32Array; + heapForSize(n: 32, unsigned: true): Uint32Array; + heapForSize(n: typeof Int32Array): Int32Array; + heapForSize(n: typeof Uint32Array): Uint32Array; + heapForSize(n: 64, unsigned: false | undefined): BigInt64Array; + heapForSize(n: 64, unsigned: true): BigUint64Array; + heapForSize(n: typeof Int32Array): BigInt64Array; + heapForSize(n: typeof Uint32Array): BigUint64Array; + + /** Faster convenience method to get a Int8Array view of the WASM heap. */ + heap8: () => Int8Array; + + /** Faster convenience method to get a UInt8Array view of the WASM heap. */ + heap8u: () => Uint8Array; + + /** Faster convenience method to get a Int16Array view of the WASM heap. */ + heap16: () => Int16Array; + + /** Faster convenience method to get a UInt16Array view of the WASM heap. */ + heap16u: () => Uint16Array; + + /** Faster convenience method to get a Int32Array view of the WASM heap. */ + heap32: () => Int32Array; + + /** Faster convenience method to get a UInt32Array view of the WASM heap. */ + heap32u: () => Uint32Array; + + /** Faster convenience method to get a BigInt64Array view of the WASM heap. */ + heap64: () => BigInt64Array; + + /** Faster convenience method to get a BigUint64Array view of the WASM heap. */ + heap64u: () => BigUint64Array; + + /** + * Fetches the `heapForSize()` for the given representation then writes the + * given numeric value to it. Only numbers may be written this way, and + * passing a non-number might trigger an exception. If passed an array of + * pointers, it writes the given value to all of them. + * + * Returns this. + */ + poke(addr: WasmPointer, value: number, representation?: string): WASM_API; + poke(addrs: WasmPointer[], value: number, representation?: string): WASM_API; + + /** + * Equivalent to `poke(X,Y,'*')`. Most frequently used for clearing output + * pointer values. + */ + pokePtr: (addr: WasmPointer, value: number) => WASM_API; + + /** Equivalent to poke(X,Y,'i8') */ + poke8: (addr: WasmPointer, value: number) => WASM_API; + + /** Equivalent to poke(X,Y,'i16') */ + poke16: (addr: WasmPointer, value: number) => WASM_API; + + /** Equivalent to poke(X,Y,'i32') */ + poke32: (addr: WasmPointer, value: number) => WASM_API; + + /** Equivalent to poke(X,Y,'i64') */ + poke64: (addr: WasmPointer, value: number) => WASM_API; + + /** Equivalent to poke(X,Y,'f32') */ + poke32f: (addr: WasmPointer, value: number) => WASM_API; + + /** Equivalent to poke(X,Y,'f64') */ + poke64f: (addr: WasmPointer, value: number) => WASM_API; + + /* -------------------------------------------------------------------------- + * String Conversion and Utilities + * -------------------------------------------------------------------------- + * Passing strings into and out of WASM is frequently required, but how JS + * and C code represent strings varies significantly. The following routines + * are available for conversion of strings and related algorithms. + */ + + /** + * Expects to be given a C-style string array and its length. It returns a JS + * array of strings and/or null values: any entry in the `pArgv` array which + * is `NULL` results in a null entry in the result array. If `argc` is 0 then + * an empty array is returned. + * + * Results are `undefined` if any entry in the first `argc` entries of `pArgv` + * are neither `0` (`NULL`) nor legal UTF-format C strings. + * + * To be clear, the expected C-style arguments to be passed to this function + * are `(int, char **)` (optionally const-qualified). + */ + cArgvToJs: ( + argc: number, + pArgv: WasmPointer, + ) => (string | null)[] | undefined; + + /** + * Expects its argument to be a pointer into the WASM heap memory which refers + * to a NUL-terminated C-style string encoded as UTF-8. This function counts + * its byte length using `cstrlen()` then returns a JS-format string + * representing its contents. As a special case, if the argument is falsy, + * `null` is returned. + */ + cstrToJs: (ptr: WasmPointer) => string | null; + + /** + * Expects its argument to be a pointer into the WASM heap memory which refers + * to a NUL-terminated C-style string encoded as UTF-8. Returns the length, in + * bytes, of the string, as for `strlen(3)`. As a special case, if the + * argument is falsy then it it returns null. Throws if the argument is out of + * range for `wasm.heap8u()`. + */ + cstrlen: (ptr: WasmPointer) => number | null; + + /** + * Works similarly to C's `strncpy(3)`, copying, at most, `n` bytes (not + * characters) from `srcPtr` to `tgtPtr`. It copies until `n` bytes have been + * copied or a `0` byte is reached in `src`. Unlike `strncpy()`, it returns + * the number of bytes it assigns in `tgtPtr`, including the NUL byte (if + * any). If `n` is reached before a NUL byte in `srcPtr`, `tgtPtr` will not be + * NUL-terminated. If a NUL byte is reached before `n` bytes are copied, + * `tgtPtr` will be NUL-terminated. + * + * If `n` is negative, `cstrlen(srcPtr)+1` is used to calculate it, the `+1` + * being for the NUL byte. + * + * Throws if `tgtPtr` or `srcPtr` are falsy. Results are `undefined` if: + * + * - Either is not a pointer into the WASM heap or + * - `srcPtr` is not NUL-terminated AND `n` is less than `srcPtr`'s logical + * length. + * + * **ACHTUNG:** when passing in a non-negative `n` value, it is possible to + * copy partial multi-byte characters this way, and converting such strings + * back to JS strings will have undefined results. + */ + cstrncpy: (tgtPtr: WasmPointer, srcPtr: WasmPointer, n: number) => number; + + /** + * Forewarning: this API is somewhat complicated and is, in practice, never + * needed from client code. + * + * Encodes the given JS string as UTF-8 into the given `TypedArray` `tgt` + * (which must be a `Int8Array` or `Uint8Array`), starting at the given offset + * and writing, at most, `maxBytes` bytes (including the NUL terminator if + * `addNul` is true, else no NUL is added). If it writes any bytes at all and + * `addNul` is true, it always NUL-terminates the output, even if doing so + * means that the NUL byte is all that it writes. + * + * If `maxBytes` is negative (the default) then it is treated as the remaining + * length of `tgt`, starting at the given offset. + * + * If writing the last character would surpass the `maxBytes` count because + * the character is multi-byte, that character will not be written (as opposed + * to writing a truncated multi-byte character). This can lead to it writing + * as many as 3 fewer bytes than `maxBytes` specifies. + * + * Returns the number of bytes written to the target, including the NUL + * terminator (if any). If it returns 0, it wrote nothing at all, which can + * happen if: + * + * jsString is empty and addNul is false. + * offset < 0. + * maxBytes === 0. + * maxBytes is less than the byte length of a multi-byte jsString[0]. + * + * Throws if `tgt` is not an `Int8Array` or `Uint8Array`. + */ + jstrcpy: ( + jsString: string, + tgt: Int8Array | Uint8Array, + offset?: number, + maxBytes?: number, + addNul?: boolean, + ) => number; + + /** + * Given a JS string, this function returns its UTF-8 length in bytes. Returns + * `null` if its argument is not a string. This is a relatively expensive + * calculation and should be avoided when not necessary. + */ + jstrlen: (jsString: string) => number | null; + + /** + * For the given JS string, returns a `Uint8Array` of its contents encoded as + * UTF-8. If `addNul` is true, the returned array will have a trailing 0 + * entry, else it will not. + * + * Trivia: this was written before JS's TextEncoder was known to this code's + * author. The same functionality, sans the trailing NUL option, can be + * achieved with new TextEncoder().encode(str). + */ + jstrToUintArray: (jsString: string, addNul?: boolean) => Uint8Array; + + /* -------------------------------------------------------------------------- + * String Conversion and Utilities + * -------------------------------------------------------------------------- + */ + + /** + * `wasm.alloc()`'s `srcTypedArray.byteLength` bytes, populates them with the + * values from the source `TypedArray`, and returns the pointer to that + * memory. The returned pointer must eventually be passed to `wasm.dealloc()` + * to clean it up. + * + * The argument may be a `Uint8Array`, `Int8Array`, or `ArrayBuffer`, and it + * throws if passed any other type. + * + * As a special case, to avoid further special cases where this routine is + * used, if `srcTypedArray.byteLength` is 0, it allocates a single byte and + * sets it to the value 0. Even in such cases, calls must behave as if the + * allocated memory has exactly `srcTypedArray.byteLength` usable bytes. + */ + allocFromTypedArray: ( + srcTypedArray: Uint8Array | Int8Array | ArrayBuffer, + ) => WasmPointer; + + /* ========================================================================== + * Bridging JS/WASM Functions + * ========================================================================== + * This section documents the helper APIs related to bridging the gap + * between JavaScript and WebAssembly functions. + * + * A WASM module exposes all exported functions to the user, but they are in + * "raw" form. That is, they perform no argument or result type conversion and only + * support data types supported by WASM (i.e. only numeric types). That's fine + * for functions which only accept and return numbers, but is generally less + * helpful for functions which take or return strings or have output pointers. + * For usability reasons, it's desirable to reduce the JS/C friction by + * automatically performing mundane tasks such as the allocation and + * deallocation of memory needed for converting strings between JS and WASM. + * + * Additionally, it's often useful to add new functions to the WASM runtime + * from JS, which requires compiling binary WASM code on the fly. A common + * example of this is creating user-defined SQL functions. For the most + * part, the JS bindings of the sqlite3 API take care of such conversions + * for the user, but there are cases where client code will need to, or want + * to, perform such conversions itself. + */ + + /* -------------------------------------------------------------------------- + * WASM Function Table + * -------------------------------------------------------------------------- + * + * WASM-exported functions, as well as JavaScript functions which have been + * bound to WASM at runtime, are exposed to clients via a `WebAssembly.Table` + * instance. The following APIs are available for working with that. + */ + + /** + * Given a function pointer, returns the WASM function table entry if found, + * else returns a falsy value. + */ + functionEntry: (fnPtr: WasmPointer) => Function | undefined; + + /** Returns the WASM module's indirect function table. */ + functionTable: () => WebAssembly.Table; + + /* -------------------------------------------------------------------------- + * Calling and Wrapping Functions + * -------------------------------------------------------------------------- + */ + + /** + * Calls a WASM-exported function by name, passing on all supplied arguments + * (which may optionally be supplied as an array). If throws if the function + * is not exported or if the argument count does not match. This routine does + * no type conversion and is essentially equivalent to: + * + * const rc = wasm.exports.some_func(...args); + * + * With the exception that `xCall()` throws if the argument count does not + * match that of the WASM-exported function. + */ + xCall(functionName: string, ...args: any[]): any; + xCall(functionName: string, args: any[]): any; + + /** + * Functions like `xCall()` but performs argument and result type conversions + * as for `xWrap()`. + * + * The first argument is the name of the exported function to call. The 2nd + * its the name of its result type, as documented for `xWrap()`. The 3rd is an + * array of argument type names, as documented for `xWrap()`. The 4th+ + * arguments are arguments for the call, with the special case that if the 4th + * argument is an array, it is used as the arguments for the call. + * + * Returns the converted result of the call. + * + * This is just a thin wrapper around `xWrap()`. If the given function is to + * be called more than once, it's more efficient to use `xWrap()` to create a + * wrapper, then to call that wrapper as many times as needed. For one-shot + * calls, however, this variant is arguably more efficient because it will + * hypothetically free the wrapper function quickly. + */ + xCallWrappe( + functionName: string, + resultType: string, + argTypes: string[], + ...args: any[] + ): any; + xCallWrapped( + functionName: string, + resultType: string, + argTypes: string[], + args: any[], + ): any; + + /** + * Returns a WASM-exported function by name, or throws if the function is not + * found. + */ + xGet: (functionName: string) => Function; + + /** + * `xWrap()` creates a JS function which calls a WASM-exported function, as + * described for `xCall(`). + * + * Creates a wrapper for the WASM-exported function `fname`. It uses `xGet()` + * to fetch the exported function (which throws on error) and returns either + * that function or a wrapper for that function which converts the JS-side + * argument types into WASM-side types and converts the result type. If the + * function takes no arguments and `resultType` is null then the function is + * returned as-is, else a wrapper is created for it to adapt its arguments and + * result value, as described below. + * + * This function's arguments are: + * + * - `functionName`: the exported function's name. `xGet()` is used to fetch + * this, so will throw if no exported function is found with that name. + * - `resultType`: the name of the result type. A literal `null` means to return + * the original function's value as-is (mnemonic: there is "null" conversion + * going on). Literal `undefined` or the string `"void"` mean to ignore the + * function's result and return `undefined`. Aside from those two special + * cases, it may be one of the values described below or any mapping + * installed by the client using `xWrap.resultAdapter()`. + * + * If passed 3 arguments and the final one is an array, that array must + * contain a list of type names (see below) for adapting the arguments from JS + * to WASM. If passed 2 arguments, more than 3, or the 3rd is not an array, + * all arguments after the 2nd (if any) are treated as type names. In other + * words, the following usages are equivalent: + * + * xWrap('funcname', 'i32', 'string', 'f64'); + * xWrap('funcname', 'i32', ['string', 'f64']); + * + * As are: + * + * xWrap('funcname', 'i32'); // no arguments + * xWrap('funcname', 'i32', []); + * + * Type names are symbolic names which map the function's result and arguments + * to an adapter function to convert, if needed, the value before passing it + * on to WASM or to convert a return result from WASM. + * + * **The list of built-in names.** + * + * The following lists describe each, noting that some apply only to arguments + * or return results, the two often having different semantics: + * + * - `i8`, `i16`, `i32` (args and results): all integer conversions which + * convert their argument to an integer and truncate it to the given bit + * length. + * - `N*` (args): a type name in the form `N*`, where N is a numeric type name, + * is treated the same as WASM pointer. + * - `*` and `pointer` (args): are assumed to be opaque WASM pointers and are + * treated like the current WASM pointer numeric type. Non-numbers will + * coerce to a value of 0 and out-of-range numbers will have `undefined` + * results (as with any pointer misuse). + * - `*` and `pointer` (results): are aliases for the current WASM pointer + * numeric type. + * - `**` (args): is simply a descriptive alias for `'*'`. It's primarily + * intended to mark output-pointer arguments. + * - `i64` (args and results): passes the value to `BigInt()` to convert it to + * an `int64`. Only available if `BigInt` support is enabled. + * - `f32` (float), `f64` (double) (args and results): pass their argument to + * `Number()`. i.e. the adapter does not currently distinguish between the + * two types of floating-point numbers. + * - `number` (results): converts the result to a JS Number using + * `Number(theValue).valueOf()`. Note that this is for result conversions + * only, as it's not possible to generically know which type of number to + * convert arguments to. + * + * Non-numeric conversions include: + * + * - `string` or `utf8` (args): has two different semantics in order to + * accommodate various uses of certain C APIs... + * + * - If the arg is a JS string, a temporary C-string, UTF-8 encoded, is created + * to pass to the exported function, which gets cleaned up before the + * wrapper returns. If a long-lived C-string pointer is required, + * client-side code is required to create the string, then pass its + * pointer to the function. + * - Else the arg is assumed to be a pointer to a string the client has already + * allocated and it's passed on as a WASM pointer. + * - `string` or `utf8` (results): treats the result value as a const C-string, + * encoded as UTF-8, copies it to a JS string, and returns that JS string. + * - `string:dealloc` or `utf8:dealloc` (results): treats the result value as a + * non-const C-string, encoded as UTF-8, ownership of which has just been + * transfered to the caller. It copies the C-string to a JS string, frees + * the C-string using `dealloc()`, and returns the JS string. If such a + * result value is NULL, the JS result is null. **Achtung:** when using an + * API which returns results from a specific allocator, this conversion is + * not legal. Instead, an equivalent conversion which uses the appropriate + * deallocator is required. An example of such is provided in the next + * section. + * - `string:flexible` (args): are an expanded version of `string` described in + * the C-style API docs. These are widely used for SQL string inputs in the + * library. + * - `string:static` (args): if passed a pointer, returns it as is. Anything + * else: gets coerced to a JS string for use as a map key. If a matching + * entry is found (as described next), it is returned, else + * `wasm.allocCString()` is used to create a a new string, map its pointer + * to `(''+v)` for the remainder of the application's life, and returns that + * pointer value for this call and all future calls which are passed a + * string-equivalent argument. This conversion is intended for cases which + * require static/long-lived string arguments, e.g. `sqlite3_bind_pointer()` + * and `sqlite3_result_pointer()`. + * - `json` (results): treats the result as a const C-string and returns the + * result of passing the converted-to-JS string to `JSON.parse()`. Returns + * `null` if the C-string is a NULL pointer. Propagates any exception from + * `JSON.parse()`. + * - `json:dealloc` (results): works exactly like `string:dealloc` but returns + * the same thing as the json adapter. Note the warning in `string:dealloc` + * about the allocator and deallocator. + * + * The type names for results and arguments are validated when `xWrap()` is + * called and any unknown names will trigger an exception. + * + * Clients may map their own result and argument adapters using + * `xWrap.resultAdapter()` and `xWrap.argAdaptor()`, noting that not all type + * conversions are valid for both arguments and result types as they often + * have different memory ownership requirements. That topic is covered in the + * next section... + * + * **Argument and Result Value Type Conversions** + * + * When `xWrap()` is called and evaluates function call signatures, it looks + * up the argument and result type adapters for a match. It is possible to + * install custom adapters for arguments and result values using the methods + * listed below. + * + * `xWrap()` has two methods with identical signatures: + * + * xWrap.argAdapter(string, function) + * xWrap.resultAdapter(string, function) + * + * Each one expects a type name string, such as the ones described for + * `xWrap()`, and a function which is passed a single value and must return + * that value, a conversion of that value, or throw an exception. Each of + * those functions returns itself so that calls may be chained. + * + * For example's sake, let's assume we have a C-bound function which returns a + * C-style string allocated using a non-default allocator, `my_str_alloc()`. + * The returned memory is owned by the caller and must be freed, but needs to + * be freed using the allocator's deallocation counterpart, `my_str_free()`. + * We can create such a result value adapter with: + * + * wasm.xWrap.resultAdaptor('my_str_alloc*', (v)=>{ + * try { return v ? target.cstrToJs(v) : null } + * finally{ wasm.exports.my_str_free(v) } + * }; + * + * With that in place, we can make calls like: + * + * const f = wasm.xWrap('my_function', 'my_str_alloc*', [ + * 'i32', + * 'string', + * ]); + * const str = f(17, 'hello, world'); + * // ^^^ the memory allocated for the result using my_str_alloc() + * // is freed using my_str_free() before f() returns. + * + * Similarly, let's assume that we have a custom JS class which has a member + * property named `pointer` which refers to C-side memory of a struct which + * this JS class represents. We can then make it legal to pass such objects on + * to the C APIs with something like: + * + * const argPointer = wasm.xWrap.argAdapter('*'); // default pointer-type adapter + * wasm.xWrap.argAdaptor('MyType', (v) => { + * if (v instanceof MyType) v = v.pointer; + * if (wasm.isPtr(v)) return argPointer(v); + * throw new Error('Invalid value for MyType argument.'); + * }); + * + * With that in place we can wrap one of our functions like: + * + * const f = wasm.xWrap('MyType_method', undefined, ['MyType', 'i32']); + * const my = new MyType(...); + * // ^^^ assume this allocates WASM memory referenced via my.pointer. + * f( my, // will use my.pointer + * 17 ); + * + * Similar conversions can be done for result values, though how to do so for + * result values depends entirely on client-side semantics of memory + * management. + */ + xWrap( + functionName: string, + resultType: string | undefined, + ...argTypes: string[] + ): Function; + xWrap( + functionName: string, + resultType: string | undefined, + argTypes: string[], + ): Function; + + /* -------------------------------------------------------------------------- + * (Un)Installing WASM Functions + * -------------------------------------------------------------------------- + * When using C APIs which take callback function pointers, one cannot + * simply pass JS functions to them. Instead, the JS function has to be + * proxied into WASM environment and that proxy has to be passed to C. That + * is done by compiling, on the fly, a small amount of binary WASM code + * which describes the function's signature in WASM terms, forwards its + * arguments to the provided JS function, and returns the result of that JS + * function. The details are ugly, but usage is simple... + */ + + /** + * Expects a JS function and signature, exactly as for `wasm.jsFuncToWasm()`. + * It uses that function to create a WASM-exported function, installs that + * function to the next available slot of `wasm.functionTable()`, and returns + * the function's index in that table (which acts as a pointer to that + * function). The returned pointer can be passed to `wasm.uninstallFunction()` + * to uninstall it and free up the table slot for reuse. + * + * As a special case, if the passed-in function is a WASM-exported function + * then the signature argument is ignored and `func` is installed as-is, + * without requiring re-compilation/re-wrapping. + * + * This function will propagate an exception if `WebAssembly.Table.grow()` + * throws or `wasm.jsFuncToWasm()` throws. The former case can happen in an + * Emscripten-compiled environment when building without Emscripten's + * `-sALLOW_TABLE_GROWTH` flag. + */ + installFunction(func: Function, signature: string): WasmPointer; + installFunction(signature: string, func: Function): WasmPointer; + + /** + * Creates a WASM function which wraps the given JS function and returns the + * JS binding of that WASM function. The function signature string must be in + * the form used by jaccwabyt or Emscripten's `addFunction()`. In short: in + * may have one of the following formats: + * + * - Emscripten: `"x..."`, where the first `x` is a letter representing the + * result type and subsequent letters represent the argument types. See + * below. Functions with no arguments have only a single letter. + * - Jaccwabyt: `"x(...)"` where x is the letter representing the result type + * and letters in the parens (if any) represent the argument types. + * Functions with no arguments use `x()`. See below. + * + * Supported letters: + * + * - `i` = `int32` + * - `p` = `int32` ("pointer") + * - `j` = `int64` + * - `f` = `float32` + * - `d` = `float64` + * - `v` = `void`, only legal for use as the result type + * + * It throws if an invalid signature letter is used. + * + * Jaccwabyt-format signatures support some additional letters which have no + * special meaning here but (in this context) act as aliases for other + * letters: + * + * - `s`, `P`: same as `p` + */ + jsFuncToWasm(func: Function, signature: string): Function; + jsFuncToWasm(signature: string, func: Function): Function; + + /** + * This works exactly like `installFunction()` except that the installation is + * scoped to the current allocation scope and is uninstalled when the current + * allocation scope is popped. It will throw if no allocation scope is + * active. + */ + scopedInstallFunction(func: Function, signature: string): WasmPointer; + scopedInstallFunction(signature: string, func: Function): WasmPointer; + + /** + * Requires a pointer value previously returned from `wasm.installFunction()`. + * Removes that function from the WASM function table, marks its table slot as + * free for re-use, and returns that function. It is illegal to call this + * before `installFunction()` has been called and results are undefined if the + * argument was not returned by that function. The returned function may be + * passed back to `installFunction()` to reinstall it. + */ + uninstallFunction: (fnPtr: WasmPointer) => Function; + + /* ========================================================================== + * Generic Utility Functions + * ========================================================================== + */ + + /** + * Returns true if its value is a WASM pointer type. That is, it's a a 32-bit + * integer greater than or equal to zero. + * + * Sidebar: `isPtr()` is an alias for `isPtr32()`. If/when 64-bit WASM pointer + * support becomes widespread, it will become an alias for either `isPtr32()` + * or the as-yet-hypothetical `isPtr64()`, depending on a configuration + * option. + */ + isPtr: (v: unknown) => v is WasmPointer; + + /** See {@link WASM_API#isPtr} */ + isPtr32: (v: unknown) => v is WasmPointer; + + /** Size of a WASM pointer in bytes. */ + ptrSizeof: number; + + // Undocumented fields + ptrIR: unknown; + bigIntEnabled: unknown; + memory: unknown; + compileOptionUsed: unknown; + getMemValue: unknown; + getPtrValue: unknown; + setMemValue: unknown; + setPtrValue: unknown; + sqlite3_wasm_db_reset: unknown; + sqlite3_wasm_db_vfs: unknown; + sqlite3_wasm_vfs_create_file: unknown; + sqlite3_wasm_vfs_unlink: unknown; + ctype: unknown; +}; + +// generated by Object.keys(sqlite3.capi).map(k => `${k}: any;`).join('\n') +declare type CAPI = { + sqlite3_vfs: typeof sqlite3_vfs; + sqlite3_io_methods: typeof sqlite3_io_methods; + sqlite3_file: typeof sqlite3_file; + sqlite3_vtab: typeof sqlite3_vtab; + sqlite3_vtab_cursor: typeof sqlite3_vtab_cursor; + sqlite3_module: typeof sqlite3_module; + sqlite3_index_info: typeof sqlite3_index_info; + sqlite3_bind_blob: any; + sqlite3_bind_text: any; + sqlite3_create_function_v2: any; + sqlite3_create_function: any; + sqlite3_create_window_function: any; + sqlite3_prepare_v3: any; + sqlite3_prepare_v2: any; + sqlite3_exec: any; + sqlite3_randomness: any; + sqlite3_wasmfs_opfs_dir: any; + sqlite3_wasmfs_filename_is_persistent: any; + sqlite3_js_db_uses_vfs: any; + sqlite3_js_vfs_list: any; + sqlite3_js_db_export: any; + sqlite3_js_db_vfs: any; + sqlite3_js_aggregate_context: any; + sqlite3_js_vfs_create_file: any; + sqlite3_db_config: any; + sqlite3_value_to_js: any; + sqlite3_values_to_js: any; + sqlite3_result_error_js: any; + sqlite3_result_js: any; + sqlite3_column_js: any; + sqlite3_preupdate_new_js: any; + sqlite3_preupdate_old_js: any; + sqlite3changeset_new_js: any; + sqlite3changeset_old_js: any; + sqlite3_aggregate_context: any; + sqlite3_bind_double: any; + sqlite3_bind_int: any; + sqlite3_bind_null: any; + sqlite3_bind_parameter_count: any; + sqlite3_bind_parameter_index: any; + sqlite3_bind_pointer: any; + sqlite3_busy_handler: any; + sqlite3_busy_timeout: any; + sqlite3_changes: any; + sqlite3_clear_bindings: any; + sqlite3_collation_needed: any; + sqlite3_column_blob: any; + sqlite3_column_bytes: any; + sqlite3_column_count: any; + sqlite3_column_double: any; + sqlite3_column_int: any; + sqlite3_column_name: any; + sqlite3_column_text: any; + sqlite3_column_type: any; + sqlite3_column_value: any; + sqlite3_commit_hook: any; + sqlite3_compileoption_get: any; + sqlite3_compileoption_used: any; + sqlite3_complete: any; + sqlite3_context_db_handle: any; + sqlite3_data_count: any; + sqlite3_db_filename: any; + sqlite3_db_handle: any; + sqlite3_db_name: any; + sqlite3_db_status: any; + sqlite3_errcode: any; + sqlite3_errmsg: any; + sqlite3_error_offset: any; + sqlite3_errstr: any; + sqlite3_expanded_sql: any; + sqlite3_extended_errcode: any; + sqlite3_extended_result_codes: any; + sqlite3_file_control: any; + sqlite3_finalize: any; + sqlite3_free: any; + sqlite3_get_auxdata: any; + sqlite3_initialize: any; + sqlite3_keyword_count: any; + sqlite3_keyword_name: any; + sqlite3_keyword_check: any; + sqlite3_libversion: any; + sqlite3_libversion_number: any; + sqlite3_limit: any; + sqlite3_malloc: any; + sqlite3_open: any; + sqlite3_open_v2: any; + sqlite3_progress_handler: any; + sqlite3_realloc: any; + sqlite3_reset: any; + sqlite3_result_blob: any; + sqlite3_result_double: any; + sqlite3_result_error: any; + sqlite3_result_error_code: any; + sqlite3_result_error_nomem: any; + sqlite3_result_error_toobig: any; + sqlite3_result_int: any; + sqlite3_result_null: any; + sqlite3_result_pointer: any; + sqlite3_result_subtype: any; + sqlite3_result_text: any; + sqlite3_result_zeroblob: any; + sqlite3_rollback_hook: any; + sqlite3_set_authorizer: any; + sqlite3_set_auxdata: any; + sqlite3_shutdown: any; + sqlite3_sourceid: any; + sqlite3_sql: any; + sqlite3_status: any; + sqlite3_step: any; + sqlite3_stmt_isexplain: any; + sqlite3_stmt_readonly: any; + sqlite3_stmt_status: any; + sqlite3_strglob: any; + sqlite3_stricmp: any; + sqlite3_strlike: any; + sqlite3_strnicmp: any; + sqlite3_table_column_metadata: any; + sqlite3_total_changes: any; + sqlite3_trace_v2: any; + sqlite3_txn_state: any; + sqlite3_uri_boolean: any; + sqlite3_uri_key: any; + sqlite3_uri_parameter: any; + sqlite3_user_data: any; + sqlite3_value_blob: any; + sqlite3_value_bytes: any; + sqlite3_value_double: any; + sqlite3_value_dup: any; + sqlite3_value_free: any; + sqlite3_value_frombind: any; + sqlite3_value_int: any; + sqlite3_value_nochange: any; + sqlite3_value_numeric_type: any; + sqlite3_value_pointer: any; + sqlite3_value_subtype: any; + sqlite3_value_text: any; + sqlite3_value_type: any; + sqlite3_vfs_find: any; + sqlite3_vfs_register: any; + sqlite3_vfs_unregister: any; + sqlite3_bind_int64: any; + sqlite3_changes64: any; + sqlite3_column_int64: any; + sqlite3_create_module: any; + sqlite3_create_module_v2: any; + sqlite3_declare_vtab: any; + sqlite3_deserialize: any; + sqlite3_drop_modules: any; + sqlite3_last_insert_rowid: any; + sqlite3_malloc64: any; + sqlite3_msize: any; + sqlite3_overload_function: any; + sqlite3_preupdate_blobwrite: any; + sqlite3_preupdate_count: any; + sqlite3_preupdate_depth: any; + sqlite3_preupdate_hook: any; + sqlite3_preupdate_new: any; + sqlite3_preupdate_old: any; + sqlite3_realloc64: any; + sqlite3_result_int64: any; + sqlite3_result_zeroblob64: any; + sqlite3_serialize: any; + sqlite3_set_last_insert_rowid: any; + sqlite3_status64: any; + sqlite3_total_changes64: any; + sqlite3_update_hook: any; + sqlite3_uri_int64: any; + sqlite3_value_int64: any; + sqlite3_vtab_collation: any; + sqlite3_vtab_distinct: any; + sqlite3_vtab_in: any; + sqlite3_vtab_in_first: any; + sqlite3_vtab_in_next: any; + sqlite3_vtab_nochange: any; + sqlite3_vtab_on_conflict: any; + sqlite3_vtab_rhs_value: any; + sqlite3changegroup_add: any; + sqlite3changegroup_add_strm: any; + sqlite3changegroup_delete: any; + sqlite3changegroup_new: any; + sqlite3changegroup_output: any; + sqlite3changegroup_output_strm: any; + sqlite3changeset_apply: any; + sqlite3changeset_apply_strm: any; + sqlite3changeset_apply_v2: any; + sqlite3changeset_apply_v2_strm: any; + sqlite3changeset_concat: any; + sqlite3changeset_concat_strm: any; + sqlite3changeset_conflict: any; + sqlite3changeset_finalize: any; + sqlite3changeset_fk_conflicts: any; + sqlite3changeset_invert: any; + sqlite3changeset_invert_strm: any; + sqlite3changeset_new: any; + sqlite3changeset_next: any; + sqlite3changeset_old: any; + sqlite3changeset_op: any; + sqlite3changeset_pk: any; + sqlite3changeset_start: any; + sqlite3changeset_start_strm: any; + sqlite3changeset_start_v2: any; + sqlite3changeset_start_v2_strm: any; + sqlite3session_attach: any; + sqlite3session_changeset: any; + sqlite3session_changeset_size: any; + sqlite3session_changeset_strm: any; + sqlite3session_config: any; + sqlite3session_create: any; + sqlite3session_diff: any; + sqlite3session_enable: any; + sqlite3session_indirect: any; + sqlite3session_isempty: any; + sqlite3session_memory_used: any; + sqlite3session_object_config: any; + sqlite3session_patchset: any; + sqlite3session_patchset_strm: any; + sqlite3session_table_filter: any; + SQLITE_ACCESS_EXISTS: any; + SQLITE_ACCESS_READWRITE: any; + SQLITE_ACCESS_READ: any; + SQLITE_DENY: any; + SQLITE_IGNORE: any; + SQLITE_CREATE_INDEX: any; + SQLITE_CREATE_TABLE: any; + SQLITE_CREATE_TEMP_INDEX: any; + SQLITE_CREATE_TEMP_TABLE: any; + SQLITE_CREATE_TEMP_TRIGGER: any; + SQLITE_CREATE_TEMP_VIEW: any; + SQLITE_CREATE_TRIGGER: any; + SQLITE_CREATE_VIEW: any; + SQLITE_DELETE: any; + SQLITE_DROP_INDEX: any; + SQLITE_DROP_TABLE: any; + SQLITE_DROP_TEMP_INDEX: any; + SQLITE_DROP_TEMP_TABLE: any; + SQLITE_DROP_TEMP_TRIGGER: any; + SQLITE_DROP_TEMP_VIEW: any; + SQLITE_DROP_TRIGGER: any; + SQLITE_DROP_VIEW: any; + SQLITE_INSERT: any; + SQLITE_PRAGMA: any; + SQLITE_READ: any; + SQLITE_SELECT: any; + SQLITE_TRANSACTION: any; + SQLITE_UPDATE: any; + SQLITE_ATTACH: any; + SQLITE_DETACH: any; + SQLITE_ALTER_TABLE: any; + SQLITE_REINDEX: any; + SQLITE_ANALYZE: any; + SQLITE_CREATE_VTABLE: any; + SQLITE_DROP_VTABLE: any; + SQLITE_FUNCTION: any; + SQLITE_SAVEPOINT: any; + SQLITE_RECURSIVE: any; + SQLITE_STATIC: any; + SQLITE_TRANSIENT: any; + SQLITE_WASM_DEALLOC: any; + SQLITE_CHANGESETSTART_INVERT: any; + SQLITE_CHANGESETAPPLY_NOSAVEPOINT: any; + SQLITE_CHANGESETAPPLY_INVERT: any; + SQLITE_CHANGESET_DATA: any; + SQLITE_CHANGESET_NOTFOUND: any; + SQLITE_CHANGESET_CONFLICT: any; + SQLITE_CHANGESET_CONSTRAINT: any; + SQLITE_CHANGESET_FOREIGN_KEY: any; + SQLITE_CHANGESET_OMIT: any; + SQLITE_CHANGESET_REPLACE: any; + SQLITE_CHANGESET_ABORT: any; + SQLITE_CONFIG_SINGLETHREAD: any; + SQLITE_CONFIG_MULTITHREAD: any; + SQLITE_CONFIG_SERIALIZED: any; + SQLITE_CONFIG_MALLOC: any; + SQLITE_CONFIG_GETMALLOC: any; + SQLITE_CONFIG_SCRATCH: any; + SQLITE_CONFIG_PAGECACHE: any; + SQLITE_CONFIG_HEAP: any; + SQLITE_CONFIG_MEMSTATUS: any; + SQLITE_CONFIG_MUTEX: any; + SQLITE_CONFIG_GETMUTEX: any; + SQLITE_CONFIG_LOOKASIDE: any; + SQLITE_CONFIG_PCACHE: any; + SQLITE_CONFIG_GETPCACHE: any; + SQLITE_CONFIG_LOG: any; + SQLITE_CONFIG_URI: any; + SQLITE_CONFIG_PCACHE2: any; + SQLITE_CONFIG_GETPCACHE2: any; + SQLITE_CONFIG_COVERING_INDEX_SCAN: any; + SQLITE_CONFIG_SQLLOG: any; + SQLITE_CONFIG_MMAP_SIZE: any; + SQLITE_CONFIG_WIN32_HEAPSIZE: any; + SQLITE_CONFIG_PCACHE_HDRSZ: any; + SQLITE_CONFIG_PMASZ: any; + SQLITE_CONFIG_STMTJRNL_SPILL: any; + SQLITE_CONFIG_SMALL_MALLOC: any; + SQLITE_CONFIG_SORTERREF_SIZE: any; + SQLITE_CONFIG_MEMDB_MAXSIZE: any; + SQLITE_INTEGER: any; + SQLITE_FLOAT: any; + SQLITE_TEXT: any; + SQLITE_BLOB: any; + SQLITE_NULL: any; + SQLITE_DBCONFIG_MAINDBNAME: any; + SQLITE_DBCONFIG_LOOKASIDE: any; + SQLITE_DBCONFIG_ENABLE_FKEY: any; + SQLITE_DBCONFIG_ENABLE_TRIGGER: any; + SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER: any; + SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION: any; + SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE: any; + SQLITE_DBCONFIG_ENABLE_QPSG: any; + SQLITE_DBCONFIG_TRIGGER_EQP: any; + SQLITE_DBCONFIG_RESET_DATABASE: any; + SQLITE_DBCONFIG_DEFENSIVE: any; + SQLITE_DBCONFIG_WRITABLE_SCHEMA: any; + SQLITE_DBCONFIG_LEGACY_ALTER_TABLE: any; + SQLITE_DBCONFIG_DQS_DML: any; + SQLITE_DBCONFIG_DQS_DDL: any; + SQLITE_DBCONFIG_ENABLE_VIEW: any; + SQLITE_DBCONFIG_LEGACY_FILE_FORMAT: any; + SQLITE_DBCONFIG_TRUSTED_SCHEMA: any; + SQLITE_DBCONFIG_MAX: any; + SQLITE_DBSTATUS_LOOKASIDE_USED: any; + SQLITE_DBSTATUS_CACHE_USED: any; + SQLITE_DBSTATUS_SCHEMA_USED: any; + SQLITE_DBSTATUS_STMT_USED: any; + SQLITE_DBSTATUS_LOOKASIDE_HIT: any; + SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE: any; + SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL: any; + SQLITE_DBSTATUS_CACHE_HIT: any; + SQLITE_DBSTATUS_CACHE_MISS: any; + SQLITE_DBSTATUS_CACHE_WRITE: any; + SQLITE_DBSTATUS_DEFERRED_FKS: any; + SQLITE_DBSTATUS_CACHE_USED_SHARED: any; + SQLITE_DBSTATUS_CACHE_SPILL: any; + SQLITE_DBSTATUS_MAX: any; + SQLITE_UTF8: any; + SQLITE_UTF16LE: any; + SQLITE_UTF16BE: any; + SQLITE_UTF16: any; + SQLITE_UTF16_ALIGNED: any; + SQLITE_FCNTL_LOCKSTATE: any; + SQLITE_FCNTL_GET_LOCKPROXYFILE: any; + SQLITE_FCNTL_SET_LOCKPROXYFILE: any; + SQLITE_FCNTL_LAST_ERRNO: any; + SQLITE_FCNTL_SIZE_HINT: any; + SQLITE_FCNTL_CHUNK_SIZE: any; + SQLITE_FCNTL_FILE_POINTER: any; + SQLITE_FCNTL_SYNC_OMITTED: any; + SQLITE_FCNTL_WIN32_AV_RETRY: any; + SQLITE_FCNTL_PERSIST_WAL: any; + SQLITE_FCNTL_OVERWRITE: any; + SQLITE_FCNTL_VFSNAME: any; + SQLITE_FCNTL_POWERSAFE_OVERWRITE: any; + SQLITE_FCNTL_PRAGMA: any; + SQLITE_FCNTL_BUSYHANDLER: any; + SQLITE_FCNTL_TEMPFILENAME: any; + SQLITE_FCNTL_MMAP_SIZE: any; + SQLITE_FCNTL_TRACE: any; + SQLITE_FCNTL_HAS_MOVED: any; + SQLITE_FCNTL_SYNC: any; + SQLITE_FCNTL_COMMIT_PHASETWO: any; + SQLITE_FCNTL_WIN32_SET_HANDLE: any; + SQLITE_FCNTL_WAL_BLOCK: any; + SQLITE_FCNTL_ZIPVFS: any; + SQLITE_FCNTL_RBU: any; + SQLITE_FCNTL_VFS_POINTER: any; + SQLITE_FCNTL_JOURNAL_POINTER: any; + SQLITE_FCNTL_WIN32_GET_HANDLE: any; + SQLITE_FCNTL_PDB: any; + SQLITE_FCNTL_BEGIN_ATOMIC_WRITE: any; + SQLITE_FCNTL_COMMIT_ATOMIC_WRITE: any; + SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE: any; + SQLITE_FCNTL_LOCK_TIMEOUT: any; + SQLITE_FCNTL_DATA_VERSION: any; + SQLITE_FCNTL_SIZE_LIMIT: any; + SQLITE_FCNTL_CKPT_DONE: any; + SQLITE_FCNTL_RESERVE_BYTES: any; + SQLITE_FCNTL_CKPT_START: any; + SQLITE_FCNTL_EXTERNAL_READER: any; + SQLITE_FCNTL_CKSM_FILE: any; + SQLITE_LOCK_NONE: any; + SQLITE_LOCK_SHARED: any; + SQLITE_LOCK_RESERVED: any; + SQLITE_LOCK_PENDING: any; + SQLITE_LOCK_EXCLUSIVE: any; + SQLITE_IOCAP_ATOMIC: any; + SQLITE_IOCAP_ATOMIC512: any; + SQLITE_IOCAP_ATOMIC1K: any; + SQLITE_IOCAP_ATOMIC2K: any; + SQLITE_IOCAP_ATOMIC4K: any; + SQLITE_IOCAP_ATOMIC8K: any; + SQLITE_IOCAP_ATOMIC16K: any; + SQLITE_IOCAP_ATOMIC32K: any; + SQLITE_IOCAP_ATOMIC64K: any; + SQLITE_IOCAP_SAFE_APPEND: any; + SQLITE_IOCAP_SEQUENTIAL: any; + SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN: any; + SQLITE_IOCAP_POWERSAFE_OVERWRITE: any; + SQLITE_IOCAP_IMMUTABLE: any; + SQLITE_IOCAP_BATCH_ATOMIC: any; + SQLITE_MAX_ALLOCATION_SIZE: any; + SQLITE_LIMIT_LENGTH: any; + SQLITE_MAX_LENGTH: any; + SQLITE_LIMIT_SQL_LENGTH: any; + SQLITE_MAX_SQL_LENGTH: any; + SQLITE_LIMIT_COLUMN: any; + SQLITE_MAX_COLUMN: any; + SQLITE_LIMIT_EXPR_DEPTH: any; + SQLITE_MAX_EXPR_DEPTH: any; + SQLITE_LIMIT_COMPOUND_SELECT: any; + SQLITE_MAX_COMPOUND_SELECT: any; + SQLITE_LIMIT_VDBE_OP: any; + SQLITE_MAX_VDBE_OP: any; + SQLITE_LIMIT_FUNCTION_ARG: any; + SQLITE_MAX_FUNCTION_ARG: any; + SQLITE_LIMIT_ATTACHED: any; + SQLITE_MAX_ATTACHED: any; + SQLITE_LIMIT_LIKE_PATTERN_LENGTH: any; + SQLITE_MAX_LIKE_PATTERN_LENGTH: any; + SQLITE_LIMIT_VARIABLE_NUMBER: any; + SQLITE_MAX_VARIABLE_NUMBER: any; + SQLITE_LIMIT_TRIGGER_DEPTH: any; + SQLITE_MAX_TRIGGER_DEPTH: any; + SQLITE_LIMIT_WORKER_THREADS: any; + SQLITE_MAX_WORKER_THREADS: any; + SQLITE_OPEN_READONLY: any; + SQLITE_OPEN_READWRITE: any; + SQLITE_OPEN_CREATE: any; + SQLITE_OPEN_URI: any; + SQLITE_OPEN_MEMORY: any; + SQLITE_OPEN_NOMUTEX: any; + SQLITE_OPEN_FULLMUTEX: any; + SQLITE_OPEN_SHAREDCACHE: any; + SQLITE_OPEN_PRIVATECACHE: any; + SQLITE_OPEN_EXRESCODE: any; + SQLITE_OPEN_NOFOLLOW: any; + SQLITE_OPEN_MAIN_DB: any; + SQLITE_OPEN_MAIN_JOURNAL: any; + SQLITE_OPEN_TEMP_DB: any; + SQLITE_OPEN_TEMP_JOURNAL: any; + SQLITE_OPEN_TRANSIENT_DB: any; + SQLITE_OPEN_SUBJOURNAL: any; + SQLITE_OPEN_SUPER_JOURNAL: any; + SQLITE_OPEN_WAL: any; + SQLITE_OPEN_DELETEONCLOSE: any; + SQLITE_OPEN_EXCLUSIVE: any; + SQLITE_PREPARE_PERSISTENT: any; + SQLITE_PREPARE_NORMALIZE: any; + SQLITE_PREPARE_NO_VTAB: any; + SQLITE_OK: any; + SQLITE_ERROR: any; + SQLITE_INTERNAL: any; + SQLITE_PERM: any; + SQLITE_ABORT: any; + SQLITE_BUSY: any; + SQLITE_LOCKED: any; + SQLITE_NOMEM: any; + SQLITE_READONLY: any; + SQLITE_INTERRUPT: any; + SQLITE_IOERR: any; + SQLITE_CORRUPT: any; + SQLITE_NOTFOUND: any; + SQLITE_FULL: any; + SQLITE_CANTOPEN: any; + SQLITE_PROTOCOL: any; + SQLITE_EMPTY: any; + SQLITE_SCHEMA: any; + SQLITE_TOOBIG: any; + SQLITE_CONSTRAINT: any; + SQLITE_MISMATCH: any; + SQLITE_MISUSE: any; + SQLITE_NOLFS: any; + SQLITE_AUTH: any; + SQLITE_FORMAT: any; + SQLITE_RANGE: any; + SQLITE_NOTADB: any; + SQLITE_NOTICE: any; + SQLITE_WARNING: any; + SQLITE_ROW: any; + SQLITE_DONE: any; + SQLITE_ERROR_MISSING_COLLSEQ: any; + SQLITE_ERROR_RETRY: any; + SQLITE_ERROR_SNAPSHOT: any; + SQLITE_IOERR_READ: any; + SQLITE_IOERR_SHORT_READ: any; + SQLITE_IOERR_WRITE: any; + SQLITE_IOERR_FSYNC: any; + SQLITE_IOERR_DIR_FSYNC: any; + SQLITE_IOERR_TRUNCATE: any; + SQLITE_IOERR_FSTAT: any; + SQLITE_IOERR_UNLOCK: any; + SQLITE_IOERR_RDLOCK: any; + SQLITE_IOERR_DELETE: any; + SQLITE_IOERR_BLOCKED: any; + SQLITE_IOERR_NOMEM: any; + SQLITE_IOERR_ACCESS: any; + SQLITE_IOERR_CHECKRESERVEDLOCK: any; + SQLITE_IOERR_LOCK: any; + SQLITE_IOERR_CLOSE: any; + SQLITE_IOERR_DIR_CLOSE: any; + SQLITE_IOERR_SHMOPEN: any; + SQLITE_IOERR_SHMSIZE: any; + SQLITE_IOERR_SHMLOCK: any; + SQLITE_IOERR_SHMMAP: any; + SQLITE_IOERR_SEEK: any; + SQLITE_IOERR_DELETE_NOENT: any; + SQLITE_IOERR_MMAP: any; + SQLITE_IOERR_GETTEMPPATH: any; + SQLITE_IOERR_CONVPATH: any; + SQLITE_IOERR_VNODE: any; + SQLITE_IOERR_AUTH: any; + SQLITE_IOERR_BEGIN_ATOMIC: any; + SQLITE_IOERR_COMMIT_ATOMIC: any; + SQLITE_IOERR_ROLLBACK_ATOMIC: any; + SQLITE_IOERR_DATA: any; + SQLITE_IOERR_CORRUPTFS: any; + SQLITE_LOCKED_SHAREDCACHE: any; + SQLITE_LOCKED_VTAB: any; + SQLITE_BUSY_RECOVERY: any; + SQLITE_BUSY_SNAPSHOT: any; + SQLITE_BUSY_TIMEOUT: any; + SQLITE_CANTOPEN_NOTEMPDIR: any; + SQLITE_CANTOPEN_ISDIR: any; + SQLITE_CANTOPEN_FULLPATH: any; + SQLITE_CANTOPEN_CONVPATH: any; + SQLITE_CANTOPEN_SYMLINK: any; + SQLITE_CORRUPT_VTAB: any; + SQLITE_CORRUPT_SEQUENCE: any; + SQLITE_CORRUPT_INDEX: any; + SQLITE_READONLY_RECOVERY: any; + SQLITE_READONLY_CANTLOCK: any; + SQLITE_READONLY_ROLLBACK: any; + SQLITE_READONLY_DBMOVED: any; + SQLITE_READONLY_CANTINIT: any; + SQLITE_READONLY_DIRECTORY: any; + SQLITE_ABORT_ROLLBACK: any; + SQLITE_CONSTRAINT_CHECK: any; + SQLITE_CONSTRAINT_COMMITHOOK: any; + SQLITE_CONSTRAINT_FOREIGNKEY: any; + SQLITE_CONSTRAINT_FUNCTION: any; + SQLITE_CONSTRAINT_NOTNULL: any; + SQLITE_CONSTRAINT_PRIMARYKEY: any; + SQLITE_CONSTRAINT_TRIGGER: any; + SQLITE_CONSTRAINT_UNIQUE: any; + SQLITE_CONSTRAINT_VTAB: any; + SQLITE_CONSTRAINT_ROWID: any; + SQLITE_CONSTRAINT_PINNED: any; + SQLITE_CONSTRAINT_DATATYPE: any; + SQLITE_NOTICE_RECOVER_WAL: any; + SQLITE_NOTICE_RECOVER_ROLLBACK: any; + SQLITE_WARNING_AUTOINDEX: any; + SQLITE_AUTH_USER: any; + SQLITE_OK_LOAD_PERMANENTLY: any; + SQLITE_STATUS_MEMORY_USED: any; + SQLITE_STATUS_PAGECACHE_USED: any; + SQLITE_STATUS_PAGECACHE_OVERFLOW: any; + SQLITE_STATUS_MALLOC_SIZE: any; + SQLITE_STATUS_PARSER_STACK: any; + SQLITE_STATUS_PAGECACHE_SIZE: any; + SQLITE_STATUS_MALLOC_COUNT: any; + SQLITE_STMTSTATUS_FULLSCAN_STEP: any; + SQLITE_STMTSTATUS_SORT: any; + SQLITE_STMTSTATUS_AUTOINDEX: any; + SQLITE_STMTSTATUS_VM_STEP: any; + SQLITE_STMTSTATUS_REPREPARE: any; + SQLITE_STMTSTATUS_RUN: any; + SQLITE_STMTSTATUS_FILTER_MISS: any; + SQLITE_STMTSTATUS_FILTER_HIT: any; + SQLITE_STMTSTATUS_MEMUSED: any; + SQLITE_SYNC_NORMAL: any; + SQLITE_SYNC_FULL: any; + SQLITE_SYNC_DATAONLY: any; + SQLITE_TRACE_STMT: any; + SQLITE_TRACE_PROFILE: any; + SQLITE_TRACE_ROW: any; + SQLITE_TRACE_CLOSE: any; + SQLITE_TXN_NONE: any; + SQLITE_TXN_READ: any; + SQLITE_TXN_WRITE: any; + SQLITE_DETERMINISTIC: any; + SQLITE_DIRECTONLY: any; + SQLITE_INNOCUOUS: any; + SQLITE_VERSION_NUMBER: any; + SQLITE_VERSION: any; + SQLITE_SOURCE_ID: any; + SQLITE_SERIALIZE_NOCOPY: any; + SQLITE_DESERIALIZE_FREEONCLOSE: any; + SQLITE_DESERIALIZE_READONLY: any; + SQLITE_DESERIALIZE_RESIZEABLE: any; + SQLITE_SESSION_CONFIG_STRMSIZE: any; + SQLITE_SESSION_OBJCONFIG_SIZE: any; + SQLITE_INDEX_SCAN_UNIQUE: any; + SQLITE_INDEX_CONSTRAINT_EQ: any; + SQLITE_INDEX_CONSTRAINT_GT: any; + SQLITE_INDEX_CONSTRAINT_LE: any; + SQLITE_INDEX_CONSTRAINT_LT: any; + SQLITE_INDEX_CONSTRAINT_GE: any; + SQLITE_INDEX_CONSTRAINT_MATCH: any; + SQLITE_INDEX_CONSTRAINT_LIKE: any; + SQLITE_INDEX_CONSTRAINT_GLOB: any; + SQLITE_INDEX_CONSTRAINT_REGEXP: any; + SQLITE_INDEX_CONSTRAINT_NE: any; + SQLITE_INDEX_CONSTRAINT_ISNOT: any; + SQLITE_INDEX_CONSTRAINT_ISNOTNULL: any; + SQLITE_INDEX_CONSTRAINT_ISNULL: any; + SQLITE_INDEX_CONSTRAINT_IS: any; + SQLITE_INDEX_CONSTRAINT_LIMIT: any; + SQLITE_INDEX_CONSTRAINT_OFFSET: any; + SQLITE_INDEX_CONSTRAINT_FUNCTION: any; + SQLITE_VTAB_CONSTRAINT_SUPPORT: any; + SQLITE_VTAB_INNOCUOUS: any; + SQLITE_VTAB_DIRECTONLY: any; + SQLITE_ROLLBACK: any; + SQLITE_FAIL: any; + SQLITE_REPLACE: any; + sqlite3_js_rc_str: any; + sqlite3_vtab_config: any; + sqlite3_close_v2: any; + sqlite3session_delete: any; + sqlite3_create_collation_v2: any; + sqlite3_create_collation: any; + sqlite3_config: any; + sqlite3_auto_extension: any; + sqlite3_cancel_auto_extension: any; + sqlite3_reset_auto_extension: any; +}; diff --git a/package.json b/package.json index 14360ef..6dee9db 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,7 @@ "node-fetch": "^3.3.2", "prettier": "^3.0.2", "publint": "^0.2.2", + "prettier-plugin-jsdoc": "^1.0.1", "shx": "^0.3.4" }, "optionalDependencies": { From 0d69daa64108b42c12a99988081acb6e2e56d412 Mon Sep 17 00:00:00 2001 From: Johannes Baiter Date: Fri, 25 Aug 2023 22:56:08 +0200 Subject: [PATCH 06/12] Add type hints for sqlite.capi --- index.d.ts | 2118 +++++++++++++++++++++++++++++++++++--------------- package.json | 4 +- 2 files changed, 1490 insertions(+), 632 deletions(-) diff --git a/index.d.ts b/index.d.ts index 6ec7a5c..9062e84 100644 --- a/index.d.ts +++ b/index.d.ts @@ -8,13 +8,12 @@ declare type SqlValue = | ArrayBuffer; /** Internal data types supported by SQLite3. */ -declare enum SQLiteDataType { - SQLITE_INTEGER = 1, - SQLITE_FLOAT, - SQLITE_TEXT, - SQLITE_BLOB, - SQLITE_NULL, -} +declare type SQLiteDataType = + | CAPI['SQLITE_INTEGER'] + | CAPI['SQLITE_FLOAT'] + | CAPI['SQLITE_TEXT'] + | CAPI['SQLITE_BLOB'] + | CAPI['SQLITE_NULL']; /** Specifies parameter bindings. */ declare type BindingSpec = @@ -1049,9 +1048,25 @@ declare class Database { */ selectValue( sql: FlexibleString, - bind?: BindingSpec, - asType?: SQLiteDataType, - ): SqlValue | undefined; + bind: BindingSpec | undefined, + asType: CAPI['SQLITE_INTEGER'] | CAPI['SQLITE_FLOAT'], + ): number | undefined; + selectValue( + sql: FlexibleString, + bind: BindingSpec | undefined, + asType: CAPI['SQLITE_TEXT'], + ): string | undefined; + selectValue( + sql: FlexibleString, + bind: BindingSpec | undefined, + asType: CAPI['SQLITE_BLOB'], + ): Uint8Array | undefined; + selectValue( + sql: FlexibleString, + bind: BindingSpec | undefined, + asType: CAPI['SQLITE_NULL'], + ): null | undefined; + selectValue(sql: FlexibleString, bind?: BindingSpec): SqlValue | undefined; /** * Runs the given query and returns an array of the values from the first @@ -1478,6 +1493,8 @@ declare class sqlite3_vfs extends SQLiteStruct { pNext: WasmPointer; zName: WasmPointer; pAppData: WasmPointer; + + constructor(pointer?: WasmPointer); xOpen: ( vfsPtr: WasmPointer, zName: WasmPointer, @@ -1530,6 +1547,8 @@ declare class sqlite3_vfs extends SQLiteStruct { declare class sqlite3_io_methods extends SQLiteStruct { iVersion: number; + + constructor(pointer?: WasmPointer); xClose: (file: WasmPointer) => number; xRead: ( file: WasmPointer, @@ -1578,20 +1597,28 @@ declare class sqlite3_io_methods extends SQLiteStruct { declare class sqlite3_file extends SQLiteStruct { pMethods: WasmPointer; + + constructor(pointer?: WasmPointer); } declare class sqlite3_vtab extends SQLiteStruct { pModule: WasmPointer; nRef: number; zErrMsg: WasmPointer; + + constructor(pointer?: WasmPointer); } declare class sqlite3_vtab_cursor extends SQLiteStruct { pVtab: WasmPointer; + + constructor(pointer?: WasmPointer); } declare class sqlite3_module extends SQLiteStruct { iVersion: number; + + constructor(pointer?: WasmPointer); xCreate: ( db: WasmPointer, pAux: WasmPointer, @@ -1658,16 +1685,22 @@ declare class sqlite3_index_constraint extends SQLiteStruct { op: number; usable: number; iTermOffset: number; + + constructor(pointer?: WasmPointer); } declare class sqlite3_index_constraint_usage extends SQLiteStruct { argvIndex: number; omit: number; + + constructor(pointer?: WasmPointer); } declare class sqlite3_index_orderby extends SQLiteStruct { iColumn: number; desc: number; + + constructor(pointer?: WasmPointer); } declare class sqlite3_index_info extends SQLiteStruct { @@ -1687,6 +1720,8 @@ declare class sqlite3_index_info extends SQLiteStruct { sqlite3_index_constraint: sqlite3_index_constraint; sqlite3_index_orderby: sqlite3_index_orderby; sqlite3_index_constraint_usage: sqlite3_index_constraint_usage; + + constructor(pointer?: WasmPointer); } declare type Sqlite3Static = { @@ -1946,6 +1981,7 @@ declare type Sqlite3Static = { }; declare type InitOptions = { + locateFile?: (path: string, prefix: string) => string; print?: (msg: string) => void; printErr?: (msg: string) => void; }; @@ -2334,7 +2370,7 @@ declare type WASM_API = { * However, when all pointers involved point to "small" data, it is safe to * pass a falsy value to save a tiny bit of memory. */ - allocPtr(howMany: 1 | undefined, safePtrSize?: boolean): WasmPointer; + allocPtr(howMany?: 1 | undefined, safePtrSize?: boolean): WasmPointer; allocPtr(howMany: number, safePtrSize?: boolean): WasmPointer[]; /** @@ -2754,8 +2790,8 @@ declare type WASM_API = { * With the exception that `xCall()` throws if the argument count does not * match that of the WASM-exported function. */ - xCall(functionName: string, ...args: any[]): any; - xCall(functionName: string, args: any[]): any; + xCall(fn: string | Function, ...args: any[]): any; + xCall(fn: string | Function, args: any[]): any; /** * Functions like `xCall()` but performs argument and result type conversions @@ -3119,622 +3155,1442 @@ declare type CAPI = { sqlite3_vtab_cursor: typeof sqlite3_vtab_cursor; sqlite3_module: typeof sqlite3_module; sqlite3_index_info: typeof sqlite3_index_info; - sqlite3_bind_blob: any; - sqlite3_bind_text: any; - sqlite3_create_function_v2: any; - sqlite3_create_function: any; - sqlite3_create_window_function: any; - sqlite3_prepare_v3: any; - sqlite3_prepare_v2: any; - sqlite3_exec: any; - sqlite3_randomness: any; - sqlite3_wasmfs_opfs_dir: any; - sqlite3_wasmfs_filename_is_persistent: any; - sqlite3_js_db_uses_vfs: any; - sqlite3_js_vfs_list: any; - sqlite3_js_db_export: any; - sqlite3_js_db_vfs: any; - sqlite3_js_aggregate_context: any; - sqlite3_js_vfs_create_file: any; - sqlite3_db_config: any; - sqlite3_value_to_js: any; - sqlite3_values_to_js: any; - sqlite3_result_error_js: any; - sqlite3_result_js: any; - sqlite3_column_js: any; - sqlite3_preupdate_new_js: any; - sqlite3_preupdate_old_js: any; - sqlite3changeset_new_js: any; - sqlite3changeset_old_js: any; - sqlite3_aggregate_context: any; - sqlite3_bind_double: any; - sqlite3_bind_int: any; - sqlite3_bind_null: any; - sqlite3_bind_parameter_count: any; - sqlite3_bind_parameter_index: any; - sqlite3_bind_pointer: any; - sqlite3_busy_handler: any; - sqlite3_busy_timeout: any; - sqlite3_changes: any; - sqlite3_clear_bindings: any; - sqlite3_collation_needed: any; - sqlite3_column_blob: any; - sqlite3_column_bytes: any; - sqlite3_column_count: any; - sqlite3_column_double: any; - sqlite3_column_int: any; - sqlite3_column_name: any; - sqlite3_column_text: any; - sqlite3_column_type: any; - sqlite3_column_value: any; - sqlite3_commit_hook: any; - sqlite3_compileoption_get: any; - sqlite3_compileoption_used: any; - sqlite3_complete: any; - sqlite3_context_db_handle: any; - sqlite3_data_count: any; - sqlite3_db_filename: any; - sqlite3_db_handle: any; - sqlite3_db_name: any; - sqlite3_db_status: any; - sqlite3_errcode: any; - sqlite3_errmsg: any; - sqlite3_error_offset: any; - sqlite3_errstr: any; - sqlite3_expanded_sql: any; - sqlite3_extended_errcode: any; - sqlite3_extended_result_codes: any; - sqlite3_file_control: any; - sqlite3_finalize: any; - sqlite3_free: any; - sqlite3_get_auxdata: any; - sqlite3_initialize: any; - sqlite3_keyword_count: any; - sqlite3_keyword_name: any; - sqlite3_keyword_check: any; - sqlite3_libversion: any; - sqlite3_libversion_number: any; - sqlite3_limit: any; - sqlite3_malloc: any; - sqlite3_open: any; - sqlite3_open_v2: any; - sqlite3_progress_handler: any; - sqlite3_realloc: any; - sqlite3_reset: any; - sqlite3_result_blob: any; - sqlite3_result_double: any; - sqlite3_result_error: any; - sqlite3_result_error_code: any; - sqlite3_result_error_nomem: any; - sqlite3_result_error_toobig: any; - sqlite3_result_int: any; - sqlite3_result_null: any; - sqlite3_result_pointer: any; - sqlite3_result_subtype: any; - sqlite3_result_text: any; - sqlite3_result_zeroblob: any; - sqlite3_rollback_hook: any; - sqlite3_set_authorizer: any; - sqlite3_set_auxdata: any; - sqlite3_shutdown: any; - sqlite3_sourceid: any; - sqlite3_sql: any; - sqlite3_status: any; - sqlite3_step: any; - sqlite3_stmt_isexplain: any; - sqlite3_stmt_readonly: any; - sqlite3_stmt_status: any; - sqlite3_strglob: any; - sqlite3_stricmp: any; - sqlite3_strlike: any; - sqlite3_strnicmp: any; - sqlite3_table_column_metadata: any; - sqlite3_total_changes: any; - sqlite3_trace_v2: any; - sqlite3_txn_state: any; - sqlite3_uri_boolean: any; - sqlite3_uri_key: any; - sqlite3_uri_parameter: any; - sqlite3_user_data: any; - sqlite3_value_blob: any; - sqlite3_value_bytes: any; - sqlite3_value_double: any; - sqlite3_value_dup: any; - sqlite3_value_free: any; - sqlite3_value_frombind: any; - sqlite3_value_int: any; - sqlite3_value_nochange: any; - sqlite3_value_numeric_type: any; - sqlite3_value_pointer: any; - sqlite3_value_subtype: any; - sqlite3_value_text: any; - sqlite3_value_type: any; - sqlite3_vfs_find: any; - sqlite3_vfs_register: any; - sqlite3_vfs_unregister: any; - sqlite3_bind_int64: any; - sqlite3_changes64: any; - sqlite3_column_int64: any; - sqlite3_create_module: any; - sqlite3_create_module_v2: any; - sqlite3_declare_vtab: any; - sqlite3_deserialize: any; - sqlite3_drop_modules: any; - sqlite3_last_insert_rowid: any; - sqlite3_malloc64: any; - sqlite3_msize: any; - sqlite3_overload_function: any; - sqlite3_preupdate_blobwrite: any; - sqlite3_preupdate_count: any; - sqlite3_preupdate_depth: any; - sqlite3_preupdate_hook: any; - sqlite3_preupdate_new: any; - sqlite3_preupdate_old: any; - sqlite3_realloc64: any; - sqlite3_result_int64: any; - sqlite3_result_zeroblob64: any; - sqlite3_serialize: any; - sqlite3_set_last_insert_rowid: any; - sqlite3_status64: any; - sqlite3_total_changes64: any; - sqlite3_update_hook: any; - sqlite3_uri_int64: any; - sqlite3_value_int64: any; - sqlite3_vtab_collation: any; - sqlite3_vtab_distinct: any; - sqlite3_vtab_in: any; - sqlite3_vtab_in_first: any; - sqlite3_vtab_in_next: any; - sqlite3_vtab_nochange: any; - sqlite3_vtab_on_conflict: any; - sqlite3_vtab_rhs_value: any; - sqlite3changegroup_add: any; - sqlite3changegroup_add_strm: any; - sqlite3changegroup_delete: any; - sqlite3changegroup_new: any; - sqlite3changegroup_output: any; - sqlite3changegroup_output_strm: any; - sqlite3changeset_apply: any; - sqlite3changeset_apply_strm: any; - sqlite3changeset_apply_v2: any; - sqlite3changeset_apply_v2_strm: any; - sqlite3changeset_concat: any; - sqlite3changeset_concat_strm: any; - sqlite3changeset_conflict: any; - sqlite3changeset_finalize: any; - sqlite3changeset_fk_conflicts: any; - sqlite3changeset_invert: any; - sqlite3changeset_invert_strm: any; - sqlite3changeset_new: any; - sqlite3changeset_next: any; - sqlite3changeset_old: any; - sqlite3changeset_op: any; - sqlite3changeset_pk: any; - sqlite3changeset_start: any; - sqlite3changeset_start_strm: any; - sqlite3changeset_start_v2: any; - sqlite3changeset_start_v2_strm: any; - sqlite3session_attach: any; - sqlite3session_changeset: any; - sqlite3session_changeset_size: any; - sqlite3session_changeset_strm: any; - sqlite3session_config: any; - sqlite3session_create: any; - sqlite3session_diff: any; - sqlite3session_enable: any; - sqlite3session_indirect: any; - sqlite3session_isempty: any; - sqlite3session_memory_used: any; - sqlite3session_object_config: any; - sqlite3session_patchset: any; - sqlite3session_patchset_strm: any; - sqlite3session_table_filter: any; - SQLITE_ACCESS_EXISTS: any; - SQLITE_ACCESS_READWRITE: any; - SQLITE_ACCESS_READ: any; - SQLITE_DENY: any; - SQLITE_IGNORE: any; - SQLITE_CREATE_INDEX: any; - SQLITE_CREATE_TABLE: any; - SQLITE_CREATE_TEMP_INDEX: any; - SQLITE_CREATE_TEMP_TABLE: any; - SQLITE_CREATE_TEMP_TRIGGER: any; - SQLITE_CREATE_TEMP_VIEW: any; - SQLITE_CREATE_TRIGGER: any; - SQLITE_CREATE_VIEW: any; - SQLITE_DELETE: any; - SQLITE_DROP_INDEX: any; - SQLITE_DROP_TABLE: any; - SQLITE_DROP_TEMP_INDEX: any; - SQLITE_DROP_TEMP_TABLE: any; - SQLITE_DROP_TEMP_TRIGGER: any; - SQLITE_DROP_TEMP_VIEW: any; - SQLITE_DROP_TRIGGER: any; - SQLITE_DROP_VIEW: any; - SQLITE_INSERT: any; - SQLITE_PRAGMA: any; - SQLITE_READ: any; - SQLITE_SELECT: any; - SQLITE_TRANSACTION: any; - SQLITE_UPDATE: any; - SQLITE_ATTACH: any; - SQLITE_DETACH: any; - SQLITE_ALTER_TABLE: any; - SQLITE_REINDEX: any; - SQLITE_ANALYZE: any; - SQLITE_CREATE_VTABLE: any; - SQLITE_DROP_VTABLE: any; - SQLITE_FUNCTION: any; - SQLITE_SAVEPOINT: any; - SQLITE_RECURSIVE: any; - SQLITE_STATIC: any; - SQLITE_TRANSIENT: any; - SQLITE_WASM_DEALLOC: any; - SQLITE_CHANGESETSTART_INVERT: any; - SQLITE_CHANGESETAPPLY_NOSAVEPOINT: any; - SQLITE_CHANGESETAPPLY_INVERT: any; - SQLITE_CHANGESET_DATA: any; - SQLITE_CHANGESET_NOTFOUND: any; - SQLITE_CHANGESET_CONFLICT: any; - SQLITE_CHANGESET_CONSTRAINT: any; - SQLITE_CHANGESET_FOREIGN_KEY: any; - SQLITE_CHANGESET_OMIT: any; - SQLITE_CHANGESET_REPLACE: any; - SQLITE_CHANGESET_ABORT: any; - SQLITE_CONFIG_SINGLETHREAD: any; - SQLITE_CONFIG_MULTITHREAD: any; - SQLITE_CONFIG_SERIALIZED: any; - SQLITE_CONFIG_MALLOC: any; - SQLITE_CONFIG_GETMALLOC: any; - SQLITE_CONFIG_SCRATCH: any; - SQLITE_CONFIG_PAGECACHE: any; - SQLITE_CONFIG_HEAP: any; - SQLITE_CONFIG_MEMSTATUS: any; - SQLITE_CONFIG_MUTEX: any; - SQLITE_CONFIG_GETMUTEX: any; - SQLITE_CONFIG_LOOKASIDE: any; - SQLITE_CONFIG_PCACHE: any; - SQLITE_CONFIG_GETPCACHE: any; - SQLITE_CONFIG_LOG: any; - SQLITE_CONFIG_URI: any; - SQLITE_CONFIG_PCACHE2: any; - SQLITE_CONFIG_GETPCACHE2: any; - SQLITE_CONFIG_COVERING_INDEX_SCAN: any; - SQLITE_CONFIG_SQLLOG: any; - SQLITE_CONFIG_MMAP_SIZE: any; - SQLITE_CONFIG_WIN32_HEAPSIZE: any; - SQLITE_CONFIG_PCACHE_HDRSZ: any; - SQLITE_CONFIG_PMASZ: any; - SQLITE_CONFIG_STMTJRNL_SPILL: any; - SQLITE_CONFIG_SMALL_MALLOC: any; - SQLITE_CONFIG_SORTERREF_SIZE: any; - SQLITE_CONFIG_MEMDB_MAXSIZE: any; - SQLITE_INTEGER: any; - SQLITE_FLOAT: any; - SQLITE_TEXT: any; - SQLITE_BLOB: any; - SQLITE_NULL: any; - SQLITE_DBCONFIG_MAINDBNAME: any; - SQLITE_DBCONFIG_LOOKASIDE: any; - SQLITE_DBCONFIG_ENABLE_FKEY: any; - SQLITE_DBCONFIG_ENABLE_TRIGGER: any; - SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER: any; - SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION: any; - SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE: any; - SQLITE_DBCONFIG_ENABLE_QPSG: any; - SQLITE_DBCONFIG_TRIGGER_EQP: any; - SQLITE_DBCONFIG_RESET_DATABASE: any; - SQLITE_DBCONFIG_DEFENSIVE: any; - SQLITE_DBCONFIG_WRITABLE_SCHEMA: any; - SQLITE_DBCONFIG_LEGACY_ALTER_TABLE: any; - SQLITE_DBCONFIG_DQS_DML: any; - SQLITE_DBCONFIG_DQS_DDL: any; - SQLITE_DBCONFIG_ENABLE_VIEW: any; - SQLITE_DBCONFIG_LEGACY_FILE_FORMAT: any; - SQLITE_DBCONFIG_TRUSTED_SCHEMA: any; - SQLITE_DBCONFIG_MAX: any; - SQLITE_DBSTATUS_LOOKASIDE_USED: any; - SQLITE_DBSTATUS_CACHE_USED: any; - SQLITE_DBSTATUS_SCHEMA_USED: any; - SQLITE_DBSTATUS_STMT_USED: any; - SQLITE_DBSTATUS_LOOKASIDE_HIT: any; - SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE: any; - SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL: any; - SQLITE_DBSTATUS_CACHE_HIT: any; - SQLITE_DBSTATUS_CACHE_MISS: any; - SQLITE_DBSTATUS_CACHE_WRITE: any; - SQLITE_DBSTATUS_DEFERRED_FKS: any; - SQLITE_DBSTATUS_CACHE_USED_SHARED: any; - SQLITE_DBSTATUS_CACHE_SPILL: any; - SQLITE_DBSTATUS_MAX: any; - SQLITE_UTF8: any; - SQLITE_UTF16LE: any; - SQLITE_UTF16BE: any; - SQLITE_UTF16: any; - SQLITE_UTF16_ALIGNED: any; - SQLITE_FCNTL_LOCKSTATE: any; - SQLITE_FCNTL_GET_LOCKPROXYFILE: any; - SQLITE_FCNTL_SET_LOCKPROXYFILE: any; - SQLITE_FCNTL_LAST_ERRNO: any; - SQLITE_FCNTL_SIZE_HINT: any; - SQLITE_FCNTL_CHUNK_SIZE: any; - SQLITE_FCNTL_FILE_POINTER: any; - SQLITE_FCNTL_SYNC_OMITTED: any; - SQLITE_FCNTL_WIN32_AV_RETRY: any; - SQLITE_FCNTL_PERSIST_WAL: any; - SQLITE_FCNTL_OVERWRITE: any; - SQLITE_FCNTL_VFSNAME: any; - SQLITE_FCNTL_POWERSAFE_OVERWRITE: any; - SQLITE_FCNTL_PRAGMA: any; - SQLITE_FCNTL_BUSYHANDLER: any; - SQLITE_FCNTL_TEMPFILENAME: any; - SQLITE_FCNTL_MMAP_SIZE: any; - SQLITE_FCNTL_TRACE: any; - SQLITE_FCNTL_HAS_MOVED: any; - SQLITE_FCNTL_SYNC: any; - SQLITE_FCNTL_COMMIT_PHASETWO: any; - SQLITE_FCNTL_WIN32_SET_HANDLE: any; - SQLITE_FCNTL_WAL_BLOCK: any; - SQLITE_FCNTL_ZIPVFS: any; - SQLITE_FCNTL_RBU: any; - SQLITE_FCNTL_VFS_POINTER: any; - SQLITE_FCNTL_JOURNAL_POINTER: any; - SQLITE_FCNTL_WIN32_GET_HANDLE: any; - SQLITE_FCNTL_PDB: any; - SQLITE_FCNTL_BEGIN_ATOMIC_WRITE: any; - SQLITE_FCNTL_COMMIT_ATOMIC_WRITE: any; - SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE: any; - SQLITE_FCNTL_LOCK_TIMEOUT: any; - SQLITE_FCNTL_DATA_VERSION: any; - SQLITE_FCNTL_SIZE_LIMIT: any; - SQLITE_FCNTL_CKPT_DONE: any; - SQLITE_FCNTL_RESERVE_BYTES: any; - SQLITE_FCNTL_CKPT_START: any; - SQLITE_FCNTL_EXTERNAL_READER: any; - SQLITE_FCNTL_CKSM_FILE: any; - SQLITE_LOCK_NONE: any; - SQLITE_LOCK_SHARED: any; - SQLITE_LOCK_RESERVED: any; - SQLITE_LOCK_PENDING: any; - SQLITE_LOCK_EXCLUSIVE: any; - SQLITE_IOCAP_ATOMIC: any; - SQLITE_IOCAP_ATOMIC512: any; - SQLITE_IOCAP_ATOMIC1K: any; - SQLITE_IOCAP_ATOMIC2K: any; - SQLITE_IOCAP_ATOMIC4K: any; - SQLITE_IOCAP_ATOMIC8K: any; - SQLITE_IOCAP_ATOMIC16K: any; - SQLITE_IOCAP_ATOMIC32K: any; - SQLITE_IOCAP_ATOMIC64K: any; - SQLITE_IOCAP_SAFE_APPEND: any; - SQLITE_IOCAP_SEQUENTIAL: any; - SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN: any; - SQLITE_IOCAP_POWERSAFE_OVERWRITE: any; - SQLITE_IOCAP_IMMUTABLE: any; - SQLITE_IOCAP_BATCH_ATOMIC: any; - SQLITE_MAX_ALLOCATION_SIZE: any; - SQLITE_LIMIT_LENGTH: any; - SQLITE_MAX_LENGTH: any; - SQLITE_LIMIT_SQL_LENGTH: any; - SQLITE_MAX_SQL_LENGTH: any; - SQLITE_LIMIT_COLUMN: any; - SQLITE_MAX_COLUMN: any; - SQLITE_LIMIT_EXPR_DEPTH: any; - SQLITE_MAX_EXPR_DEPTH: any; - SQLITE_LIMIT_COMPOUND_SELECT: any; - SQLITE_MAX_COMPOUND_SELECT: any; - SQLITE_LIMIT_VDBE_OP: any; - SQLITE_MAX_VDBE_OP: any; - SQLITE_LIMIT_FUNCTION_ARG: any; - SQLITE_MAX_FUNCTION_ARG: any; - SQLITE_LIMIT_ATTACHED: any; - SQLITE_MAX_ATTACHED: any; - SQLITE_LIMIT_LIKE_PATTERN_LENGTH: any; - SQLITE_MAX_LIKE_PATTERN_LENGTH: any; - SQLITE_LIMIT_VARIABLE_NUMBER: any; - SQLITE_MAX_VARIABLE_NUMBER: any; - SQLITE_LIMIT_TRIGGER_DEPTH: any; - SQLITE_MAX_TRIGGER_DEPTH: any; - SQLITE_LIMIT_WORKER_THREADS: any; - SQLITE_MAX_WORKER_THREADS: any; - SQLITE_OPEN_READONLY: any; - SQLITE_OPEN_READWRITE: any; - SQLITE_OPEN_CREATE: any; - SQLITE_OPEN_URI: any; - SQLITE_OPEN_MEMORY: any; - SQLITE_OPEN_NOMUTEX: any; - SQLITE_OPEN_FULLMUTEX: any; - SQLITE_OPEN_SHAREDCACHE: any; - SQLITE_OPEN_PRIVATECACHE: any; - SQLITE_OPEN_EXRESCODE: any; - SQLITE_OPEN_NOFOLLOW: any; - SQLITE_OPEN_MAIN_DB: any; - SQLITE_OPEN_MAIN_JOURNAL: any; - SQLITE_OPEN_TEMP_DB: any; - SQLITE_OPEN_TEMP_JOURNAL: any; - SQLITE_OPEN_TRANSIENT_DB: any; - SQLITE_OPEN_SUBJOURNAL: any; - SQLITE_OPEN_SUPER_JOURNAL: any; - SQLITE_OPEN_WAL: any; - SQLITE_OPEN_DELETEONCLOSE: any; - SQLITE_OPEN_EXCLUSIVE: any; - SQLITE_PREPARE_PERSISTENT: any; - SQLITE_PREPARE_NORMALIZE: any; - SQLITE_PREPARE_NO_VTAB: any; - SQLITE_OK: any; - SQLITE_ERROR: any; - SQLITE_INTERNAL: any; - SQLITE_PERM: any; - SQLITE_ABORT: any; - SQLITE_BUSY: any; - SQLITE_LOCKED: any; - SQLITE_NOMEM: any; - SQLITE_READONLY: any; - SQLITE_INTERRUPT: any; - SQLITE_IOERR: any; - SQLITE_CORRUPT: any; - SQLITE_NOTFOUND: any; - SQLITE_FULL: any; - SQLITE_CANTOPEN: any; - SQLITE_PROTOCOL: any; - SQLITE_EMPTY: any; - SQLITE_SCHEMA: any; - SQLITE_TOOBIG: any; - SQLITE_CONSTRAINT: any; - SQLITE_MISMATCH: any; - SQLITE_MISUSE: any; - SQLITE_NOLFS: any; - SQLITE_AUTH: any; - SQLITE_FORMAT: any; - SQLITE_RANGE: any; - SQLITE_NOTADB: any; - SQLITE_NOTICE: any; - SQLITE_WARNING: any; - SQLITE_ROW: any; - SQLITE_DONE: any; - SQLITE_ERROR_MISSING_COLLSEQ: any; - SQLITE_ERROR_RETRY: any; - SQLITE_ERROR_SNAPSHOT: any; - SQLITE_IOERR_READ: any; - SQLITE_IOERR_SHORT_READ: any; - SQLITE_IOERR_WRITE: any; - SQLITE_IOERR_FSYNC: any; - SQLITE_IOERR_DIR_FSYNC: any; - SQLITE_IOERR_TRUNCATE: any; - SQLITE_IOERR_FSTAT: any; - SQLITE_IOERR_UNLOCK: any; - SQLITE_IOERR_RDLOCK: any; - SQLITE_IOERR_DELETE: any; - SQLITE_IOERR_BLOCKED: any; - SQLITE_IOERR_NOMEM: any; - SQLITE_IOERR_ACCESS: any; - SQLITE_IOERR_CHECKRESERVEDLOCK: any; - SQLITE_IOERR_LOCK: any; - SQLITE_IOERR_CLOSE: any; - SQLITE_IOERR_DIR_CLOSE: any; - SQLITE_IOERR_SHMOPEN: any; - SQLITE_IOERR_SHMSIZE: any; - SQLITE_IOERR_SHMLOCK: any; - SQLITE_IOERR_SHMMAP: any; - SQLITE_IOERR_SEEK: any; - SQLITE_IOERR_DELETE_NOENT: any; - SQLITE_IOERR_MMAP: any; - SQLITE_IOERR_GETTEMPPATH: any; - SQLITE_IOERR_CONVPATH: any; - SQLITE_IOERR_VNODE: any; - SQLITE_IOERR_AUTH: any; - SQLITE_IOERR_BEGIN_ATOMIC: any; - SQLITE_IOERR_COMMIT_ATOMIC: any; - SQLITE_IOERR_ROLLBACK_ATOMIC: any; - SQLITE_IOERR_DATA: any; - SQLITE_IOERR_CORRUPTFS: any; - SQLITE_LOCKED_SHAREDCACHE: any; - SQLITE_LOCKED_VTAB: any; - SQLITE_BUSY_RECOVERY: any; - SQLITE_BUSY_SNAPSHOT: any; - SQLITE_BUSY_TIMEOUT: any; - SQLITE_CANTOPEN_NOTEMPDIR: any; - SQLITE_CANTOPEN_ISDIR: any; - SQLITE_CANTOPEN_FULLPATH: any; - SQLITE_CANTOPEN_CONVPATH: any; - SQLITE_CANTOPEN_SYMLINK: any; - SQLITE_CORRUPT_VTAB: any; - SQLITE_CORRUPT_SEQUENCE: any; - SQLITE_CORRUPT_INDEX: any; - SQLITE_READONLY_RECOVERY: any; - SQLITE_READONLY_CANTLOCK: any; - SQLITE_READONLY_ROLLBACK: any; - SQLITE_READONLY_DBMOVED: any; - SQLITE_READONLY_CANTINIT: any; - SQLITE_READONLY_DIRECTORY: any; - SQLITE_ABORT_ROLLBACK: any; - SQLITE_CONSTRAINT_CHECK: any; - SQLITE_CONSTRAINT_COMMITHOOK: any; - SQLITE_CONSTRAINT_FOREIGNKEY: any; - SQLITE_CONSTRAINT_FUNCTION: any; - SQLITE_CONSTRAINT_NOTNULL: any; - SQLITE_CONSTRAINT_PRIMARYKEY: any; - SQLITE_CONSTRAINT_TRIGGER: any; - SQLITE_CONSTRAINT_UNIQUE: any; - SQLITE_CONSTRAINT_VTAB: any; - SQLITE_CONSTRAINT_ROWID: any; - SQLITE_CONSTRAINT_PINNED: any; - SQLITE_CONSTRAINT_DATATYPE: any; - SQLITE_NOTICE_RECOVER_WAL: any; - SQLITE_NOTICE_RECOVER_ROLLBACK: any; - SQLITE_WARNING_AUTOINDEX: any; - SQLITE_AUTH_USER: any; - SQLITE_OK_LOAD_PERMANENTLY: any; - SQLITE_STATUS_MEMORY_USED: any; - SQLITE_STATUS_PAGECACHE_USED: any; - SQLITE_STATUS_PAGECACHE_OVERFLOW: any; - SQLITE_STATUS_MALLOC_SIZE: any; - SQLITE_STATUS_PARSER_STACK: any; - SQLITE_STATUS_PAGECACHE_SIZE: any; - SQLITE_STATUS_MALLOC_COUNT: any; - SQLITE_STMTSTATUS_FULLSCAN_STEP: any; - SQLITE_STMTSTATUS_SORT: any; - SQLITE_STMTSTATUS_AUTOINDEX: any; - SQLITE_STMTSTATUS_VM_STEP: any; - SQLITE_STMTSTATUS_REPREPARE: any; - SQLITE_STMTSTATUS_RUN: any; - SQLITE_STMTSTATUS_FILTER_MISS: any; - SQLITE_STMTSTATUS_FILTER_HIT: any; - SQLITE_STMTSTATUS_MEMUSED: any; - SQLITE_SYNC_NORMAL: any; - SQLITE_SYNC_FULL: any; - SQLITE_SYNC_DATAONLY: any; - SQLITE_TRACE_STMT: any; - SQLITE_TRACE_PROFILE: any; - SQLITE_TRACE_ROW: any; - SQLITE_TRACE_CLOSE: any; - SQLITE_TXN_NONE: any; - SQLITE_TXN_READ: any; - SQLITE_TXN_WRITE: any; - SQLITE_DETERMINISTIC: any; - SQLITE_DIRECTONLY: any; - SQLITE_INNOCUOUS: any; - SQLITE_VERSION_NUMBER: any; - SQLITE_VERSION: any; - SQLITE_SOURCE_ID: any; - SQLITE_SERIALIZE_NOCOPY: any; - SQLITE_DESERIALIZE_FREEONCLOSE: any; - SQLITE_DESERIALIZE_READONLY: any; - SQLITE_DESERIALIZE_RESIZEABLE: any; - SQLITE_SESSION_CONFIG_STRMSIZE: any; - SQLITE_SESSION_OBJCONFIG_SIZE: any; - SQLITE_INDEX_SCAN_UNIQUE: any; - SQLITE_INDEX_CONSTRAINT_EQ: any; - SQLITE_INDEX_CONSTRAINT_GT: any; - SQLITE_INDEX_CONSTRAINT_LE: any; - SQLITE_INDEX_CONSTRAINT_LT: any; - SQLITE_INDEX_CONSTRAINT_GE: any; - SQLITE_INDEX_CONSTRAINT_MATCH: any; - SQLITE_INDEX_CONSTRAINT_LIKE: any; - SQLITE_INDEX_CONSTRAINT_GLOB: any; - SQLITE_INDEX_CONSTRAINT_REGEXP: any; - SQLITE_INDEX_CONSTRAINT_NE: any; - SQLITE_INDEX_CONSTRAINT_ISNOT: any; - SQLITE_INDEX_CONSTRAINT_ISNOTNULL: any; - SQLITE_INDEX_CONSTRAINT_ISNULL: any; - SQLITE_INDEX_CONSTRAINT_IS: any; - SQLITE_INDEX_CONSTRAINT_LIMIT: any; - SQLITE_INDEX_CONSTRAINT_OFFSET: any; - SQLITE_INDEX_CONSTRAINT_FUNCTION: any; - SQLITE_VTAB_CONSTRAINT_SUPPORT: any; - SQLITE_VTAB_INNOCUOUS: any; - SQLITE_VTAB_DIRECTONLY: any; - SQLITE_ROLLBACK: any; - SQLITE_FAIL: any; - SQLITE_REPLACE: any; - sqlite3_js_rc_str: any; - sqlite3_vtab_config: any; - sqlite3_close_v2: any; - sqlite3session_delete: any; - sqlite3_create_collation_v2: any; - sqlite3_create_collation: any; - sqlite3_config: any; - sqlite3_auto_extension: any; - sqlite3_cancel_auto_extension: any; - sqlite3_reset_auto_extension: any; + sqlite3_bind_blob: ( + stmt: PreparedStatement | WasmPointer, + idx: number, + blob: WasmPointer, + n: number, + dtor: + | (() => void) + | WasmPointer + | CAPI['SQLITE_STATIC'] + | CAPI['SQLITE_TRANSIENT'] + | CAPI['SQLITE_WASM_DEALLOC'], + ) => number; + sqlite3_bind_text: ( + stmt: PreparedStatement | WasmPointer, + idx: number, + text: string, + n: number, + dtor: + | (() => void) + | WasmPointer + | CAPI['SQLITE_STATIC'] + | CAPI['SQLITE_TRANSIENT'] + | CAPI['SQLITE_WASM_DEALLOC'], + ) => number; + sqlite3_create_function_v2: ( + db: Database | WasmPointer, + functionName: string | WasmPointer, + nArg: number, + eTextRep: number, + pApp: WasmPointer, + xFunc: + | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => void) + | WasmPointer, + xStep: + | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => void) + | WasmPointer, + xFinal: ((ctx: WasmPointer) => void) | WasmPointer, + xDestroy: (() => void) | WasmPointer, + ) => number; + sqlite3_create_function: ( + db: Database | WasmPointer, + functionName: string | WasmPointer, + nArg: number, + eTextRep: number, + pApp: WasmPointer, + xFunc: + | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => void) + | WasmPointer, + xStep: + | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => void) + | WasmPointer, + xFinal: ((ctx: WasmPointer) => void) | WasmPointer, + ) => number; + sqlite3_create_window_function: ( + db: Database | WasmPointer, + functionName: string | WasmPointer, + nArg: number, + eTextRep: number, + pApp: WasmPointer, + xStep: + | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => void) + | WasmPointer, + xFinal: ((ctx: WasmPointer) => void) | WasmPointer, + xValue: ((ctx: WasmPointer) => void) | WasmPointer, + xInverse: + | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => void) + | WasmPointer, + xDestroy: (() => void) | WasmPointer, + ) => number; + sqlite3_prepare_v3: ( + db: Database | WasmPointer, + sql: string | WasmPointer, + nByte: number, + prepFlags: number, + ppStmt: WasmPointer, + pzTail: WasmPointer, + ) => number; + sqlite3_prepare_v2: ( + db: Database | WasmPointer, + sql: string | WasmPointer, + nByte: number, + ppStmt: WasmPointer, + pzTail: WasmPointer, + ) => number; + sqlite3_exec: ( + db: Database | WasmPointer, + sql: string | WasmPointer, + callback: + | (( + cbArg: WasmPointer, + nColumns: number, + values: WasmPointer, + names: WasmPointer, + ) => number) + | WasmPointer, + cbArg: WasmPointer, + pzErrMsg: WasmPointer, + ) => number; + sqlite3_randomness: (N: number, P: WasmPointer) => void; + sqlite3_wasmfs_opfs_dir: () => string; + sqlite3_wasmfs_filename_is_persistent: (name: string) => boolean; + sqlite3_js_db_uses_vfs: ( + db: Database | WasmPointer, + vfsName: string, + dbName: string, + ) => boolean; + sqlite3_js_vfs_list: () => string[]; + sqlite3_js_db_export: ( + db: Database | WasmPointer, + schema?: string | WasmPointer, + ) => Uint8Array; + sqlite3_js_db_vfs: ( + db: Database | WasmPointer, + dbName?: string | WasmPointer, + ) => WasmPointer; + sqlite3_js_aggregate_context: ( + ctx: WasmPointer, + nBytes: number, + ) => WasmPointer; + sqlite3_js_vfs_create_file: ( + vfs: string | WasmPointer | sqlite3_vfs, + name: string | WasmPointer, + data: undefined | WasmPointer | Uint8Array | ArrayBuffer, + dataLen?: number, + ) => void; + sqlite3_db_config: ( + db: Database | WasmPointer, + op: + | CAPI['SQLITE_DBCONFIG_LOOKASIDE'] + | CAPI['SQLITE_DBCONFIG_ENABLE_FKEY'] + | CAPI['SQLITE_DBCONFIG_ENABLE_TRIGGER'] + | CAPI['SQLITE_DBCONFIG_ENABLE_VIEW'] + | CAPI['SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER'] + | CAPI['SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION'] + | CAPI['SQLITE_DBCONFIG_MAINDBNAME'] + | CAPI['SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE'] + | CAPI['SQLITE_DBCONFIG_ENABLE_QPSG'] + | CAPI['SQLITE_DBCONFIG_TRIGGER_EQP'] + | CAPI['SQLITE_DBCONFIG_RESET_DATABASE'] + | CAPI['SQLITE_DBCONFIG_DEFENSIVE'] + | CAPI['SQLITE_DBCONFIG_WRITABLE_SCHEMA'] + | CAPI['SQLITE_DBCONFIG_LEGACY_ALTER_TABLE'] + | CAPI['SQLITE_DBCONFIG_DQS_DML'] + | CAPI['SQLITE_DBCONFIG_DQS_DDL'] + | CAPI['SQLITE_DBCONFIG_TRUSTED_SCHEMA'] + | CAPI['SQLITE_DBCONFIG_LEGACY_FILE_FORMAT'], + ...args: number[] + ) => number; + sqlite3_value_to_js( + sqliteValue: WasmPointer, + throwIfCannotConvert?: true, + ): SqlValue; + sqlite3_value_to_js( + sqliteValue: WasmPointer, + throwIfCannotConvert: false, + ): SqlValue | undefined; + sqlite3_values_to_js( + numVals: number, + sqliteValues: WasmPointer, + throwIfCannotConvert?: true, + ): SqlValue[]; + sqlite3_values_to_js( + numVals: number, + sqliteValues: WasmPointer, + throwIfCannotConvert: false, + ): (SqlValue | undefined)[]; + sqlite3_result_error_js: (ctx: WasmPointer, err: Error) => void; + sqlite3_result_js: ( + ctx: WasmPointer, + val: + | Error + | null + | boolean + | number + | BigInt + | string + | Uint8Array + | Int8Array + | undefined, + ) => void; + sqlite3_column_js( + stmt: PreparedStatement | WasmPointer, + colIdx: number, + throwIfCannotConvert?: true, + ): SqlValue; + sqlite3_column_js( + stmt: PreparedStatement | WasmPointer, + colIdx: number, + throwIfCannotConvert: false, + ): SqlValue | undefined; + sqlite3_preupdate_new_js: ( + db: Database | WasmPointer, + colIdx: number, + ) => SqlValue; + sqlite3_preupdate_old_js: ( + db: Database | WasmPointer, + colIdx: number, + ) => SqlValue; + sqlite3changeset_new_js: ( + pChangeSetIter: WasmPointer, + colIdx: number, + ) => SqlValue; + sqlite3changeset_old_js: ( + pChangeSetIter: WasmPointer, + colIdx: number, + ) => SqlValue; + sqlite3_aggregate_context: (ctx: WasmPointer, nBytes: number) => WasmPointer; + sqlite3_bind_double: ( + stmt: PreparedStatement | WasmPointer, + idx: number, + value: number, + ) => number; + sqlite3_bind_int: ( + stmt: PreparedStatement | WasmPointer, + idx: number, + value: number, + ) => number; + sqlite3_bind_null: ( + stmt: PreparedStatement | WasmPointer, + idx: number, + ) => number; + sqlite3_bind_parameter_count: ( + stmt: PreparedStatement | WasmPointer, + ) => number; + sqlite3_bind_parameter_index: ( + stmt: PreparedStatement | WasmPointer, + name: string | WasmPointer, + ) => number; + sqlite3_bind_pointer: ( + stmt: PreparedStatement | WasmPointer, + idx: number, + value: WasmPointer, + type: string | WasmPointer, + dtor: + | (() => void) + | WasmPointer + | CAPI['SQLITE_STATIC'] + | CAPI['SQLITE_TRANSIENT'] + | CAPI['SQLITE_WASM_DEALLOC'], + ) => number; + sqlite3_busy_handler: ( + db: Database | WasmPointer, + callback: ((cbArg: WasmPointer, nTries: number) => number) | WasmPointer, + cbArg: WasmPointer, + ) => number; + sqlite3_busy_timeout: (db: Database | WasmPointer, ms: number) => number; + sqlite3_changes: (db: Database | WasmPointer) => number; + sqlite3_clear_bindings: (db: Database | WasmPointer) => number; + sqlite3_collation_needed: ( + db: Database | WasmPointer, + cbArg: WasmPointer, + callback: + | (( + cbArg: WasmPointer, + db: Database | WasmPointer, + eTextRep: number, + name: string | WasmPointer, + ) => void) + | WasmPointer, + ) => number; + sqlite3_column_blob: ( + stmt: PreparedStatement | WasmPointer, + colIdx: number, + ) => WasmPointer; + sqlite3_column_bytes: ( + stmt: PreparedStatement | WasmPointer, + colIdx: number, + ) => number; + sqlite3_column_count: (stmt: PreparedStatement | WasmPointer) => number; + sqlite3_column_double: ( + stmt: PreparedStatement | WasmPointer, + colIdx: number, + ) => number; + sqlite3_column_int: ( + stmt: PreparedStatement | WasmPointer, + colIdx: number, + ) => number; + sqlite3_column_name: ( + stmt: PreparedStatement | WasmPointer, + colIdx: number, + ) => string; + sqlite3_column_text: ( + stmt: PreparedStatement | WasmPointer, + colIdx: number, + ) => string; + sqlite3_column_type: ( + stmt: PreparedStatement | WasmPointer, + colIdx: number, + ) => number; + sqlite3_column_value: ( + stmt: PreparedStatement | WasmPointer, + colIdx: number, + ) => WasmPointer; + + sqlite3_commit_hook: ( + db: Database | WasmPointer, + hook: ((cbArg: WasmPointer) => number) | WasmPointer, + cbArg: WasmPointer, + ) => void; + sqlite3_compileoption_get: (idx: number) => string; + sqlite3_compileoption_used: (optName: string) => number; + sqlite3_complete: (sql: string | WasmPointer) => number; + sqlite3_context_db_handle: (ctx: WasmPointer) => WasmPointer; + sqlite3_data_count: (stmt: PreparedStatement | WasmPointer) => number; + sqlite3_db_filename: ( + db: Database | WasmPointer, + dbName: string | WasmPointer, + ) => string; + sqlite3_db_handle: (stmt: PreparedStatement | WasmPointer) => WasmPointer; + sqlite3_db_name: (db: Database | WasmPointer, dbIdx: number) => string; + sqlite3_db_status: ( + db: Database | WasmPointer, + op: + | CAPI['SQLITE_DBSTATUS_LOOKASIDE_USED'] + | CAPI['SQLITE_DBSTATUS_CACHE_USED'] + | CAPI['SQLITE_DBSTATUS_SCHEMA_USED'] + | CAPI['SQLITE_DBSTATUS_STMT_USED'] + | CAPI['SQLITE_DBSTATUS_LOOKASIDE_HIT'] + | CAPI['SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE'] + | CAPI['SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL'] + | CAPI['SQLITE_DBSTATUS_CACHE_HIT'] + | CAPI['SQLITE_DBSTATUS_CACHE_MISS'] + | CAPI['SQLITE_DBSTATUS_CACHE_WRITE'] + | CAPI['SQLITE_DBSTATUS_DEFERRED_FKS'] + | CAPI['SQLITE_DBSTATUS_CACHE_USED_SHARED'] + | CAPI['SQLITE_DBSTATUS_CACHE_SPILL'] + | CAPI['SQLITE_DBSTATUS_MAX'], + pCur: WasmPointer, + pHighWater: WasmPointer, + resetFlag: number, + ) => number; + sqlite3_errcode: (db: Database | WasmPointer) => number; + sqlite3_errmsg: (db: Database | WasmPointer) => string; + sqlite3_error_offset: (db: Database | WasmPointer) => number; + sqlite3_errstr: (rc: number) => string; + sqlite3_expanded_sql: (stmt: PreparedStatement | WasmPointer) => string; + sqlite3_extended_errcode: (db: Database | WasmPointer) => number; + sqlite3_extended_result_codes: ( + db: Database | WasmPointer, + onoff: number, + ) => number; + sqlite3_file_control: ( + db: Database | WasmPointer, + dbName: string | WasmPointer, + op: + | CAPI['SQLITE_FCNTL_BEGIN_ATOMIC_WRITE'] + | CAPI['SQLITE_FCNTL_LOCKSTATE'] + | CAPI['SQLITE_FCNTL_GET_LOCKPROXYFILE'] + | CAPI['SQLITE_FCNTL_SET_LOCKPROXYFILE'] + | CAPI['SQLITE_FCNTL_LAST_ERRNO'] + | CAPI['SQLITE_FCNTL_SIZE_HINT'] + | CAPI['SQLITE_FCNTL_CHUNK_SIZE'] + | CAPI['SQLITE_FCNTL_FILE_POINTER'] + | CAPI['SQLITE_FCNTL_SYNC_OMITTED'] + | CAPI['SQLITE_FCNTL_WIN32_AV_RETRY'] + | CAPI['SQLITE_FCNTL_PERSIST_WAL'] + | CAPI['SQLITE_FCNTL_OVERWRITE'] + | CAPI['SQLITE_FCNTL_VFSNAME'] + | CAPI['SQLITE_FCNTL_POWERSAFE_OVERWRITE'] + | CAPI['SQLITE_FCNTL_PRAGMA'] + | CAPI['SQLITE_FCNTL_BUSYHANDLER'] + | CAPI['SQLITE_FCNTL_TEMPFILENAME'] + | CAPI['SQLITE_FCNTL_MMAP_SIZE'] + | CAPI['SQLITE_FCNTL_TRACE'] + | CAPI['SQLITE_FCNTL_HAS_MOVED'] + | CAPI['SQLITE_FCNTL_SYNC'] + | CAPI['SQLITE_FCNTL_COMMIT_PHASETWO'] + | CAPI['SQLITE_FCNTL_WIN32_SET_HANDLE'] + | CAPI['SQLITE_FCNTL_WAL_BLOCK'] + | CAPI['SQLITE_FCNTL_ZIPVFS'] + | CAPI['SQLITE_FCNTL_RBU'] + | CAPI['SQLITE_FCNTL_VFS_POINTER'] + | CAPI['SQLITE_FCNTL_JOURNAL_POINTER'] + | CAPI['SQLITE_FCNTL_WIN32_GET_HANDLE'] + | CAPI['SQLITE_FCNTL_PDB'] + | CAPI['SQLITE_FCNTL_BEGIN_ATOMIC_WRITE'] + | CAPI['SQLITE_FCNTL_COMMIT_ATOMIC_WRITE'] + | CAPI['SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE'] + | CAPI['SQLITE_FCNTL_LOCK_TIMEOUT'] + | CAPI['SQLITE_FCNTL_DATA_VERSION'] + | CAPI['SQLITE_FCNTL_SIZE_LIMIT'] + | CAPI['SQLITE_FCNTL_CKPT_DONE'] + | CAPI['SQLITE_FCNTL_RESERVE_BYTES'] + | CAPI['SQLITE_FCNTL_CKPT_START'] + | CAPI['SQLITE_FCNTL_EXTERNAL_READER'] + | CAPI['SQLITE_FCNTL_CKSM_FILE'] + | CAPI['SQLITE_FCNTL_RESET_CACHE'], + arg: WasmPointer, + ) => number; + sqlite3_finalize: (stmt: PreparedStatement | WasmPointer) => number; + sqlite3_free: (ptr: WasmPointer) => void; + sqlite3_get_auxdata: (ctx: WasmPointer, n: number) => WasmPointer; + sqlite3_initialize: () => number; + sqlite3_keyword_count: () => number; + sqlite3_keyword_name: ( + i: number, + pOut: WasmPointer, + pOutLen: WasmPointer, + ) => number; + sqlite3_keyword_check: (name: string | WasmPointer, n: number) => number; + sqlite3_libversion: () => string; + sqlite3_libversion_number: () => number; + sqlite3_limit: ( + db: Database | WasmPointer, + id: number, + newVal: number, + ) => number; + sqlite3_malloc: (size: number) => WasmPointer; + sqlite3_open: (filename: string | WasmPointer, ppDb: WasmPointer) => number; + sqlite3_open_v2: ( + filename: string | WasmPointer, + ppDb: WasmPointer, + flags: number, + vfs: string | WasmPointer, + ) => number; + sqlite3_progress_handler: ( + db: Database | WasmPointer, + nOps: number, + callback: ((cbArg: WasmPointer) => number) | WasmPointer, + cbArg: WasmPointer, + ) => void; + sqlite3_realloc: (ptr: WasmPointer, size: number) => WasmPointer; + sqlite3_reset: (stmt: PreparedStatement | WasmPointer) => number; + + sqlite3_result_blob: ( + ctx: WasmPointer, + blob: WasmPointer, + blobLen: number, + dtor: + | (() => void) + | WasmPointer + | CAPI['SQLITE_STATIC'] + | CAPI['SQLITE_TRANSIENT'] + | CAPI['SQLITE_WASM_DEALLOC'], + ) => void; + sqlite3_result_double: (ctx: WasmPointer, value: number) => void; + sqlite3_result_error: ( + ctx: WasmPointer, + msg: string | WasmPointer, + msgLen: number, + ) => void; + sqlite3_result_error_code: (ctx: WasmPointer, code: number) => void; + sqlite3_result_error_nomem: (ctx: WasmPointer) => void; + sqlite3_result_error_toobig: (ctx: WasmPointer) => void; + sqlite3_result_int: (ctx: WasmPointer, value: number) => void; + sqlite3_result_null: (ctx: WasmPointer) => void; + sqlite3_result_pointer: ( + ctx: WasmPointer, + value: WasmPointer, + type: string | WasmPointer, + dtor: + | (() => void) + | WasmPointer + | CAPI['SQLITE_STATIC'] + | CAPI['SQLITE_TRANSIENT'] + | CAPI['SQLITE_WASM_DEALLOC'], + ) => void; + sqlite3_result_subtype: (ctx: WasmPointer, subtype: number) => void; + sqlite3_result_text: ( + ctx: WasmPointer, + text: string | WasmPointer, + textLen: number, + dtor: + | (() => void) + | WasmPointer + | CAPI['SQLITE_STATIC'] + | CAPI['SQLITE_TRANSIENT'] + | CAPI['SQLITE_WASM_DEALLOC'], + ) => void; + sqlite3_result_zeroblob: (ctx: WasmPointer, blobLen: number) => void; + + sqlite3_rollback_hook: ( + db: Database | WasmPointer, + hook: ((cbArg: WasmPointer) => number) | WasmPointer, + cbArg: WasmPointer, + ) => void; + sqlite3_set_authorizer: ( + db: Database | WasmPointer, + xAuth: ( + cbArg: WasmPointer, + actionCode: number, + arg1: string | 0, + arg2: string | 0, + arg3: string | 0, + arg4: string | 0, + ) => number, + cbArg: WasmPointer, + ) => number; + sqlite3_set_auxdata: ( + ctx: WasmPointer, + n: number, + pAux: WasmPointer, + xDelete: (() => void) | WasmPointer, + ) => void; + sqlite3_shutdown: () => number; + sqlite3_sourceid: () => string; + sqlite3_sql: (stmt: PreparedStatement | WasmPointer) => string; + sqlite3_status: ( + op: + | CAPI['SQLITE_STATUS_MEMORY_USED'] + | CAPI['SQLITE_STATUS_MALLOC_SIZE'] + | CAPI['SQLITE_STATUS_MALLOC_COUNT'] + | CAPI['SQLITE_STATUS_PAGECACHE_USED'] + | CAPI['SQLITE_STATUS_PAGECACHE_OVERFLOW'] + | CAPI['SQLITE_STATUS_PAGECACHE_SIZE'] + | CAPI['SQLITE_STATUS_SCRATCH_USED'] + | CAPI['SQLITE_STATUS_SCRATCH_OVERFLOW'] + | CAPI['SQLITE_STATUS_SCRATCH_SIZE'], + pCurrent: WasmPointer, + pHighwater: WasmPointer, + resetFlag: number, + ) => number; + sqlite3_step: (stmt: PreparedStatement | WasmPointer) => number; + sqlite3_stmt_isexplain: (stmt: PreparedStatement | WasmPointer) => number; + sqlite3_stmt_readonly: (stmt: PreparedStatement | WasmPointer) => number; + sqlite3_stmt_status: ( + stmt: PreparedStatement | WasmPointer, + op: + | CAPI['SQLITE_STMTSTATUS_FULLSCAN_STEP'] + | CAPI['SQLITE_STMTSTATUS_SORT'] + | CAPI['SQLITE_STMTSTATUS_AUTOINDEX'] + | CAPI['SQLITE_STMTSTATUS_VM_STEP'] + | CAPI['SQLITE_STMTSTATUS_REPREPARE'] + | CAPI['SQLITE_STMTSTATUS_RUN'] + | CAPI['SQLITE_STMTSTATUS_FILTER_MISS'] + | CAPI['SQLITE_STMTSTATUS_FILTER_HIT'] + | CAPI['SQLITE_STMTSTATUS_MEMUSED'], + resetFlag: number, + ) => number; + sqlite3_strglob: ( + glob: string | WasmPointer, + str: string | WasmPointer, + ) => number; + sqlite3_stricmp: ( + str1: string | WasmPointer, + str2: string | WasmPointer, + ) => number; + sqlite3_strlike: ( + glob: string | WasmPointer, + str: string | WasmPointer, + esc: number, + ) => number; + sqlite3_strnicmp: ( + str1: string | WasmPointer, + str2: string | WasmPointer, + n: number, + ) => number; + sqlite3_table_column_metadata: ( + db: Database | WasmPointer, + dbName: string | WasmPointer, + tblName: string | WasmPointer, + colName: string | WasmPointer, + pDataType: WasmPointer, + pCollSeq: WasmPointer, + pNotNull: WasmPointer, + pPrimaryKey: WasmPointer, + pAutoinc: WasmPointer, + ) => number; + sqlite3_total_changes: (db: Database | WasmPointer) => number; + sqlite3_trace_v2: ( + db: Database | WasmPointer, + mask: number, + xCallback: ( + reason: + | CAPI['SQLITE_TRACE_CLOSE'] + | CAPI['SQLITE_TRACE_PROFILE'] + | CAPI['SQLITE_TRACE_ROW'] + | CAPI['SQLITE_TRACE_STMT'], + cbArg: WasmPointer, + arg1: WasmPointer, + arg2: WasmPointer, + ) => number, + ) => number; + sqlite3_txn_state: ( + db: Database | WasmPointer, + schema: string | WasmPointer, + ) => + | CAPI['SQLITE_TXN_NONE'] + | CAPI['SQLITE_TXN_READ'] + | CAPI['SQLITE_TXN_WRITE'] + | -1; + sqlite3_uri_boolean: ( + uri: string | WasmPointer, + param: string | WasmPointer, + dflt: number, + ) => number; + sqlite3_uri_key: (uri: string | WasmPointer, idx: number) => string; + sqlite3_uri_parameter: ( + uri: string | WasmPointer, + param: string | WasmPointer, + ) => string; + sqlite3_user_data: (ctx: WasmPointer) => WasmPointer; + + sqlite3_value_blob: (sqliteValue: WasmPointer) => WasmPointer; + sqlite3_value_bytes: (sqliteValue: WasmPointer) => number; + sqlite3_value_double: (sqliteValue: WasmPointer) => number; + sqlite3_value_dup: (sqliteValue: WasmPointer) => WasmPointer; + sqlite3_value_free: (sqliteValue: WasmPointer) => void; + sqlite3_value_frombind: (sqliteValue: WasmPointer) => number; + sqlite3_value_int: (sqliteValue: WasmPointer) => number; + sqlite3_value_nochange: (sqliteValue: WasmPointer) => number; + sqlite3_value_numeric_type: (sqliteValue: WasmPointer) => number; + sqlite3_value_pointer: ( + sqliteValue: WasmPointer, + type: string | WasmPointer, + ) => WasmPointer; + sqlite3_value_subtype: (sqliteValue: WasmPointer) => number; + sqlite3_value_text: (sqliteValue: WasmPointer) => string; + sqlite3_value_type: (sqliteValue: WasmPointer) => number; + sqlite3_value_int64: (sqliteValue: WasmPointer) => BigInt; + + sqlite3_vfs_find: (vfsName: string) => sqlite3_vfs; + sqlite3_vfs_register: ( + vfs: sqlite3_vfs | WasmPointer, + makeDflt: number, + ) => number; + sqlite3_vfs_unregister: (vfs: sqlite3_vfs | WasmPointer) => number; + sqlite3_bind_int64: (stmt: WasmPointer, idx: number, value: BigInt) => number; + sqlite3_changes64: (db: Database | WasmPointer) => BigInt; + sqlite3_column_int64: (db: Database | WasmPointer, colIdx: number) => BigInt; + sqlite3_create_module: ( + db: Database | WasmPointer, + name: string, + module: WasmPointer | sqlite3_module, + clientData: WasmPointer, + ) => number; + sqlite3_create_module_v2: ( + db: Database | WasmPointer, + name: string, + module: WasmPointer | sqlite3_module, + clientData: WasmPointer, + destroy?: () => void, + ) => number; + sqlite3_declare_vtab: ( + db: Database | WasmPointer, + sql: string | WasmPointer, + ) => number; + sqlite3_deserialize: ( + db: Database | WasmPointer, + schema: string | WasmPointer, + data: Uint8Array | Int8Array | ArrayBuffer | WasmPointer, + dbSize: number, + bufferSize: number, + flags: number, + ) => number; + sqlite3_drop_modules: ( + db: Database | WasmPointer, + azKeep: WasmPointer, + ) => number; + sqlite3_last_insert_rowid: (db: Database | WasmPointer) => BigInt; + sqlite3_malloc64: (numBytes: BigInt) => WasmPointer; + sqlite3_msize: (ptr: WasmPointer) => BigInt; + sqlite3_overload_function: ( + db: Database | WasmPointer, + funcName: string, + nArgs: number, + ) => number; + + sqlite3_preupdate_blobwrite: (db: Database | WasmPointer) => number; + sqlite3_preupdate_count: (db: Database | WasmPointer) => number; + sqlite3_preupdate_depth: (db: Database | WasmPointer) => number; + sqlite3_preupdate_hook: ( + db: Database | WasmPointer, + xPreUpdate: ( + ctx: WasmPointer, + db: WasmPointer, + op: CAPI['SQLITE_UPDATE'] | CAPI['SQLITE_DELETE'] | CAPI['SQLITE_INSERT'], + dbName: string, + tableName: string, + oldRowid: BigInt, + newRowid: BigInt, + ) => void, + ) => void; + sqlite3_preupdate_new: ( + db: Database | WasmPointer, + colIdx: number, + sqlValues: WasmPointer, + ) => number; + sqlite3_preupdate_old: ( + db: Database | WasmPointer, + colIdx: number, + sqlValues: WasmPointer, + ) => number; + + sqlite3_realloc64: (ptr: WasmPointer, numBytes: BigInt) => WasmPointer; + sqlite3_result_int64: (ctx: WasmPointer, value: BigInt) => void; + sqlite3_result_zeroblob64: (ctx: WasmPointer, blobLen: BigInt) => void; + sqlite3_serialize: ( + db: Database | WasmPointer, + schema: string | WasmPointer, + piSize: WasmPointer, + flags: number, + ) => WasmPointer; + sqlite3_set_last_insert_rowid: ( + db: Database | WasmPointer, + rowid: BigInt, + ) => void; + sqlite3_status64: ( + op: + | CAPI['SQLITE_STATUS_MALLOC_COUNT'] + | CAPI['SQLITE_STATUS_MALLOC_SIZE'] + | CAPI['SQLITE_STATUS_PARSER_STACK'] + | CAPI['SQLITE_STATUS_PAGECACHE_USED'] + | CAPI['SQLITE_STATUS_PAGECACHE_OVERFLOW'] + | CAPI['SQLITE_STATUS_PAGECACHE_SIZE'] + | CAPI['SQLITE_STATUS_MEMORY_USED'], + pCurrent: WasmPointer, + pHighwater: WasmPointer, + resetFlag: number, + ) => number; + sqlite3_total_changes64: (db: Database | WasmPointer) => BigInt; + sqlite3_update_hook: ( + db: Database | WasmPointer, + xUpdate: ( + userCtx: WasmPointer, + op: CAPI['SQLITE_UPDATE'] | CAPI['SQLITE_DELETE'] | CAPI['SQLITE_INSERT'], + dbName: string, + tableName: string, + newRowId: BigInt, + ) => void, + userCtx: WasmPointer, + ) => void; + sqlite3_uri_int64: ( + uri: string | WasmPointer, + paramName: string | WasmPointer, + defaultVal: BigInt, + ) => BigInt; + + sqlite3_vtab_collation: ( + indexInfo: sqlite3_index_info | WasmPointer, + constraintidx: number, + ) => string; + sqlite3_vtab_distinct: ( + indexInfo: sqlite3_index_info | WasmPointer, + ) => number; + sqlite3_vtab_in: ( + indexInfo: sqlite3_index_info | WasmPointer, + iCons: number, + bhandle: number, + ) => number; + sqlite3_vtab_in_first: ( + sqlValue: WasmPointer, + outValues: WasmPointer, + ) => number; + sqlite3_vtab_in_next: ( + sqlValue: WasmPointer, + outValues: WasmPointer, + ) => number; + sqlite3_vtab_nochange: (ctx: WasmPointer) => number; + sqlite3_vtab_on_conflict: (db: Database | WasmPointer) => number; + sqlite3_vtab_rhs_value: ( + indexInfo: sqlite3_index_info | WasmPointer, + constraintIdx: number, + outValues: WasmPointer, + ) => number; + + sqlite3changegroup_add: ( + changeGrp: WasmPointer, + nData: number, + data: WasmPointer, + ) => number; + sqlite3changegroup_add_strm: ( + changeGrp: WasmPointer, + xInput: ( + pIn: WasmPointer, + pData: WasmPointer, + pnData: WasmPointer, + ) => number, + pIn: WasmPointer, + ) => number; + sqlite3changegroup_delete: (changeGrp: WasmPointer) => number; + sqlite3changegroup_new: (ppOut: WasmPointer) => number; + sqlite3changegroup_output: ( + changeGrp: WasmPointer, + pnData: WasmPointer, + ppData: WasmPointer, + ) => number; + sqlite3changegroup_output_strm: ( + changeGrp: WasmPointer, + xOutput: (pOut: WasmPointer, pData: WasmPointer, nData: number) => number, + pOut: WasmPointer, + ) => number; + + sqlite3changeset_apply: ( + db: Database | WasmPointer, + nChangeset: number, + pChangeSet: WasmPointer, + xFilter: ((pCtx: WasmPointer, tableName: string) => number) | WasmPointer, + xConflict: + | (( + pCtx: WasmPointer, + eConflict: number /* TODO: Can be more specific? */, + ) => + | CAPI['SQLITE_CHANGESET_OMIT'] + | CAPI['SQLITE_CHANGESET_ABORT'] + | CAPI['SQLITE_CHANGESET_REPLACE']) + | WasmPointer, + pCtx: WasmPointer, + ) => number; + sqlite3changeset_apply_strm: ( + db: Database | WasmPointer, + xInput: + | ((pIn: WasmPointer, pData: WasmPointer, pnData: WasmPointer) => number) + | WasmPointer, + pIn: WasmPointer, + xFilter: ((pCtx: WasmPointer, tableName: string) => number) | WasmPointer, + xConflict: + | (( + pCtx: WasmPointer, + eConflict: number /* TODO: Can be more specific? */, + ) => number) + | WasmPointer, + pCtx: WasmPointer, + ) => number; + sqlite3changeset_apply_v2: ( + db: Database | WasmPointer, + nChangeset: number, + pChangeset: WasmPointer, + xFilter: ((pCtx: WasmPointer, tableName: string) => number) | WasmPointer, + xConflict: + | (( + pCtx: WasmPointer, + eConflict: number /* TODO: Can be more specific? */, + ) => + | CAPI['SQLITE_CHANGESET_OMIT'] + | CAPI['SQLITE_CHANGESET_ABORT'] + | CAPI['SQLITE_CHANGESET_REPLACE']) + | WasmPointer, + pCtx: WasmPointer, + ppRebase: WasmPointer, + pnRebase: WasmPointer, + flags: number, + ) => number; + sqlite3changeset_apply_v2_strm: ( + db: Database | WasmPointer, + xInput: + | ((pIn: WasmPointer, pData: WasmPointer, pnData: WasmPointer) => number) + | WasmPointer, + pIn: WasmPointer, + xFilter: ((pCtx: WasmPointer, tableName: string) => number) | WasmPointer, + xConflict: + | (( + pCtx: WasmPointer, + eConflict: number /* TODO: Can be more specific? */, + ) => number) + | WasmPointer, + pCtx: WasmPointer, + ppRebase: WasmPointer, + pnRebase: WasmPointer, + flags: number, + ) => number; + sqlite3changeset_concat: ( + nA: number, + pA: WasmPointer, + nB: number, + pB: WasmPointer, + pnOut: WasmPointer, + ppOut: WasmPointer, + ) => number; + sqlite3changeset_concat_strm: ( + xInputA: + | ((pIn: WasmPointer, pData: WasmPointer, pnData: WasmPointer) => number) + | WasmPointer, + pInA: WasmPointer, + xInputB: + | ((pIn: WasmPointer, pData: WasmPointer, pnData: WasmPointer) => number) + | WasmPointer, + pInB: WasmPointer, + xOutput: + | ((pOut: WasmPointer, pData: WasmPointer, nData: number) => number) + | WasmPointer, + pOut: WasmPointer, + ) => number; + sqlite3changeset_conflict: ( + pIter: WasmPointer, + colNum: number, + ppValue: WasmPointer, + ) => number; + sqlite3changeset_finalize: (pIter: WasmPointer) => number; + sqlite3changeset_fk_conflicts: ( + pIter: WasmPointer, + pnOut: WasmPointer, + ) => number; + sqlite3changeset_invert: ( + nIn: number, + pIn: WasmPointer, + pnOut: WasmPointer, + ppOut: WasmPointer, + ) => number; + sqlite3changeset_invert_strm: ( + xInput: + | ((pIn: WasmPointer, pData: WasmPointer, pnData: WasmPointer) => number) + | WasmPointer, + pIn: WasmPointer, + xOutput: + | ((pOut: WasmPointer, pData: WasmPointer, nData: number) => number) + | WasmPointer, + pOut: WasmPointer, + ) => number; + sqlite3changeset_new: ( + pIter: WasmPointer, + colNum: number, + ppValue: WasmPointer, + ) => number; + sqlite3changeset_next: (pIter: WasmPointer) => number; + sqlite3changeset_old: ( + pIter: WasmPointer, + colNum: number, + ppValue: WasmPointer, + ) => number; + sqlite3changeset_op: ( + pIter: WasmPointer, + pzTab: WasmPointer, + pnCol: WasmPointer, + pOp: WasmPointer, + pbIndirect: WasmPointer, + ) => number; + sqlite3changeset_pk: ( + pIter: WasmPointer, + pabPK: WasmPointer, + pnCol: WasmPointer, + ) => number; + sqlite3changeset_start: ( + ppIter: WasmPointer, + nChangeset: number, + pChangeset: WasmPointer, + ) => number; + sqlite3changeset_start_strm: ( + ppIter: WasmPointer, + xInput: + | ((pIn: WasmPointer, pData: WasmPointer, pnData: WasmPointer) => number) + | WasmPointer, + pIn: WasmPointer, + ) => number; + sqlite3changeset_start_v2: ( + ppIter: WasmPointer, + nChangeset: number, + pChangeset: WasmPointer, + flags: number, + ) => number; + sqlite3changeset_start_v2_strm: ( + ppIter: WasmPointer, + xInput: + | ((pIn: WasmPointer, pData: WasmPointer, pnData: WasmPointer) => number) + | WasmPointer, + pIn: WasmPointer, + flags: number, + ) => number; + + sqlite3session_attach: (pSession: WasmPointer, tableName: string) => number; + sqlite3session_changeset: ( + pSession: WasmPointer, + pnChangeset: WasmPointer, + ppChangeset: WasmPointer, + ) => number; + sqlite3session_changeset_size: (pSession: WasmPointer) => number; + sqlite3session_changeset_strm: ( + pSession: WasmPointer, + xOutput: + | ((pOut: WasmPointer, pData: WasmPointer, nData: number) => number) + | WasmPointer, + pOut: WasmPointer, + ) => number; + sqlite3session_config: ( + op: CAPI['SQLITE_SESSION_CONFIG_STRMSIZE'], + pArg: WasmPointer, + ) => number; + sqlite3session_create: ( + db: Database | WasmPointer, + dbName: string, + ppSession: WasmPointer, + ) => number; + sqlite3session_diff: ( + pSession: WasmPointer, + fromDb: string, + tableName: string, + pzErrMsg: WasmPointer, + ) => number; + sqlite3session_enable: (pSession: WasmPointer, bEnable: number) => number; + sqlite3session_indirect: (pSession: WasmPointer, bIndirect: number) => number; + sqlite3session_isempty: (pSession: WasmPointer) => number; + sqlite3session_memory_used: (pSession: WasmPointer) => number; + sqlite3session_object_config: (pSession: WasmPointer, op: number) => number; + sqlite3session_patchset: ( + pSession: WasmPointer, + pnPatchset: WasmPointer, + ppPatchset: WasmPointer, + ) => number; + sqlite3session_patchset_strm: ( + pSession: WasmPointer, + xOutput: + | ((pOut: WasmPointer, pData: WasmPointer, nData: number) => number) + | WasmPointer, + pOut: WasmPointer, + ) => number; + sqlite3session_table_filter: ( + pSession: WasmPointer, + xFilter: ((pCtx: WasmPointer, tableName: string) => number) | WasmPointer, + pCtx: WasmPointer, + ) => void; + + SQLITE_ACCESS_EXISTS: 0; + SQLITE_ACCESS_READWRITE: 1; + SQLITE_ACCESS_READ: 2; + SQLITE_DENY: 1; + SQLITE_IGNORE: 2; + SQLITE_CREATE_INDEX: 1; + SQLITE_CREATE_TABLE: 2; + SQLITE_CREATE_TEMP_INDEX: 3; + SQLITE_CREATE_TEMP_TABLE: 4; + SQLITE_CREATE_TEMP_TRIGGER: 5; + SQLITE_CREATE_TEMP_VIEW: 6; + SQLITE_CREATE_TRIGGER: 7; + SQLITE_CREATE_VIEW: 8; + SQLITE_DELETE: 9; + SQLITE_DROP_INDEX: 10; + SQLITE_DROP_TABLE: 11; + SQLITE_DROP_TEMP_INDEX: 12; + SQLITE_DROP_TEMP_TABLE: 13; + SQLITE_DROP_TEMP_TRIGGER: 14; + SQLITE_DROP_TEMP_VIEW: 15; + SQLITE_DROP_TRIGGER: 16; + SQLITE_DROP_VIEW: 17; + SQLITE_INSERT: 18; + SQLITE_PRAGMA: 19; + SQLITE_READ: 20; + SQLITE_SELECT: 21; + SQLITE_TRANSACTION: 22; + SQLITE_UPDATE: 23; + SQLITE_ATTACH: 24; + SQLITE_DETACH: 25; + SQLITE_ALTER_TABLE: 26; + SQLITE_REINDEX: 27; + SQLITE_ANALYZE: 28; + SQLITE_CREATE_VTABLE: 29; + SQLITE_DROP_VTABLE: 30; + SQLITE_FUNCTION: 31; + SQLITE_SAVEPOINT: 32; + SQLITE_RECURSIVE: 33; + SQLITE_STATIC: 0; + SQLITE_TRANSIENT: -1; + SQLITE_WASM_DEALLOC: 1; + SQLITE_CHANGESETSTART_INVERT: 2; + SQLITE_CHANGESETAPPLY_NOSAVEPOINT: 1; + SQLITE_CHANGESETAPPLY_INVERT: 2; + SQLITE_CHANGESET_DATA: 1; + SQLITE_CHANGESET_NOTFOUND: 2; + SQLITE_CHANGESET_CONFLICT: 3; + SQLITE_CHANGESET_CONSTRAINT: 4; + SQLITE_CHANGESET_FOREIGN_KEY: 5; + SQLITE_CHANGESET_OMIT: 0; + SQLITE_CHANGESET_REPLACE: 1; + SQLITE_CHANGESET_ABORT: 2; + SQLITE_CONFIG_SINGLETHREAD: 1; + SQLITE_CONFIG_MULTITHREAD: 2; + SQLITE_CONFIG_SERIALIZED: 3; + SQLITE_CONFIG_MALLOC: 4; + SQLITE_CONFIG_GETMALLOC: 5; + SQLITE_CONFIG_SCRATCH: 6; + SQLITE_CONFIG_PAGECACHE: 7; + SQLITE_CONFIG_HEAP: 8; + SQLITE_CONFIG_MEMSTATUS: 9; + SQLITE_CONFIG_MUTEX: 10; + SQLITE_CONFIG_GETMUTEX: 11; + SQLITE_CONFIG_LOOKASIDE: 13; + SQLITE_CONFIG_PCACHE: 14; + SQLITE_CONFIG_GETPCACHE: 15; + SQLITE_CONFIG_LOG: 16; + SQLITE_CONFIG_URI: 17; + SQLITE_CONFIG_PCACHE2: 18; + SQLITE_CONFIG_GETPCACHE2: 19; + SQLITE_CONFIG_COVERING_INDEX_SCAN: 20; + SQLITE_CONFIG_SQLLOG: 21; + SQLITE_CONFIG_MMAP_SIZE: 22; + SQLITE_CONFIG_WIN32_HEAPSIZE: 23; + SQLITE_CONFIG_PCACHE_HDRSZ: 24; + SQLITE_CONFIG_PMASZ: 25; + SQLITE_CONFIG_STMTJRNL_SPILL: 26; + SQLITE_CONFIG_SMALL_MALLOC: 27; + SQLITE_CONFIG_SORTERREF_SIZE: 28; + SQLITE_CONFIG_MEMDB_MAXSIZE: 29; + SQLITE_INTEGER: 1; + SQLITE_FLOAT: 2; + SQLITE_TEXT: 3; + SQLITE_BLOB: 4; + SQLITE_NULL: 5; + SQLITE_DBCONFIG_MAINDBNAME: 1000; + SQLITE_DBCONFIG_LOOKASIDE: 1001; + SQLITE_DBCONFIG_ENABLE_FKEY: 1002; + SQLITE_DBCONFIG_ENABLE_TRIGGER: 1003; + SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER: 1004; + SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION: 1005; + SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE: 1006; + SQLITE_DBCONFIG_ENABLE_QPSG: 1007; + SQLITE_DBCONFIG_TRIGGER_EQP: 1008; + SQLITE_DBCONFIG_RESET_DATABASE: 1009; + SQLITE_DBCONFIG_DEFENSIVE: 1010; + SQLITE_DBCONFIG_WRITABLE_SCHEMA: 1011; + SQLITE_DBCONFIG_LEGACY_ALTER_TABLE: 1012; + SQLITE_DBCONFIG_DQS_DML: 1013; + SQLITE_DBCONFIG_DQS_DDL: 1014; + SQLITE_DBCONFIG_ENABLE_VIEW: 1015; + SQLITE_DBCONFIG_LEGACY_FILE_FORMAT: 1016; + SQLITE_DBCONFIG_TRUSTED_SCHEMA: 1017; + SQLITE_DBCONFIG_MAX: 1019; + SQLITE_DBSTATUS_LOOKASIDE_USED: 0; + SQLITE_DBSTATUS_CACHE_USED: 1; + SQLITE_DBSTATUS_SCHEMA_USED: 2; + SQLITE_DBSTATUS_STMT_USED: 3; + SQLITE_DBSTATUS_LOOKASIDE_HIT: 4; + SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE: 5; + SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL: 6; + SQLITE_DBSTATUS_CACHE_HIT: 7; + SQLITE_DBSTATUS_CACHE_MISS: 8; + SQLITE_DBSTATUS_CACHE_WRITE: 9; + SQLITE_DBSTATUS_DEFERRED_FKS: 10; + SQLITE_DBSTATUS_CACHE_USED_SHARED: 11; + SQLITE_DBSTATUS_CACHE_SPILL: 12; + SQLITE_DBSTATUS_MAX: 12; + SQLITE_UTF8: 1; + SQLITE_UTF16LE: 2; + SQLITE_UTF16BE: 3; + SQLITE_UTF16: 4; + SQLITE_UTF16_ALIGNED: 8; + SQLITE_FCNTL_LOCKSTATE: 1; + SQLITE_FCNTL_GET_LOCKPROXYFILE: 2; + SQLITE_FCNTL_SET_LOCKPROXYFILE: 3; + SQLITE_FCNTL_LAST_ERRNO: 4; + SQLITE_FCNTL_SIZE_HINT: 5; + SQLITE_FCNTL_CHUNK_SIZE: 6; + SQLITE_FCNTL_FILE_POINTER: 7; + SQLITE_FCNTL_SYNC_OMITTED: 8; + SQLITE_FCNTL_WIN32_AV_RETRY: 9; + SQLITE_FCNTL_PERSIST_WAL: 10; + SQLITE_FCNTL_OVERWRITE: 11; + SQLITE_FCNTL_VFSNAME: 12; + SQLITE_FCNTL_POWERSAFE_OVERWRITE: 13; + SQLITE_FCNTL_PRAGMA: 14; + SQLITE_FCNTL_BUSYHANDLER: 15; + SQLITE_FCNTL_TEMPFILENAME: 16; + SQLITE_FCNTL_MMAP_SIZE: 18; + SQLITE_FCNTL_TRACE: 19; + SQLITE_FCNTL_HAS_MOVED: 20; + SQLITE_FCNTL_SYNC: 21; + SQLITE_FCNTL_COMMIT_PHASETWO: 22; + SQLITE_FCNTL_WIN32_SET_HANDLE: 23; + SQLITE_FCNTL_WAL_BLOCK: 24; + SQLITE_FCNTL_ZIPVFS: 25; + SQLITE_FCNTL_RBU: 26; + SQLITE_FCNTL_VFS_POINTER: 27; + SQLITE_FCNTL_JOURNAL_POINTER: 28; + SQLITE_FCNTL_WIN32_GET_HANDLE: 29; + SQLITE_FCNTL_PDB: 30; + SQLITE_FCNTL_BEGIN_ATOMIC_WRITE: 31; + SQLITE_FCNTL_COMMIT_ATOMIC_WRITE: 32; + SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE: 33; + SQLITE_FCNTL_LOCK_TIMEOUT: 34; + SQLITE_FCNTL_DATA_VERSION: 35; + SQLITE_FCNTL_SIZE_LIMIT: 36; + SQLITE_FCNTL_CKPT_DONE: 37; + SQLITE_FCNTL_RESERVE_BYTES: 38; + SQLITE_FCNTL_CKPT_START: 39; + SQLITE_FCNTL_EXTERNAL_READER: 40; + SQLITE_FCNTL_CKSM_FILE: 41; + SQLITE_LOCK_NONE: 0; + SQLITE_LOCK_SHARED: 1; + SQLITE_LOCK_RESERVED: 2; + SQLITE_LOCK_PENDING: 3; + SQLITE_LOCK_EXCLUSIVE: 4; + SQLITE_IOCAP_ATOMIC: 1; + SQLITE_IOCAP_ATOMIC512: 2; + SQLITE_IOCAP_ATOMIC1K: 4; + SQLITE_IOCAP_ATOMIC2K: 8; + SQLITE_IOCAP_ATOMIC4K: 16; + SQLITE_IOCAP_ATOMIC8K: 32; + SQLITE_IOCAP_ATOMIC16K: 64; + SQLITE_IOCAP_ATOMIC32K: 128; + SQLITE_IOCAP_ATOMIC64K: 256; + SQLITE_IOCAP_SAFE_APPEND: 512; + SQLITE_IOCAP_SEQUENTIAL: 1024; + SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN: 2048; + SQLITE_IOCAP_POWERSAFE_OVERWRITE: 4096; + SQLITE_IOCAP_IMMUTABLE: 8192; + SQLITE_IOCAP_BATCH_ATOMIC: 16384; + SQLITE_MAX_ALLOCATION_SIZE: 536870911; + SQLITE_LIMIT_LENGTH: 0; + SQLITE_MAX_LENGTH: 1000000000; + SQLITE_LIMIT_SQL_LENGTH: 1; + SQLITE_MAX_SQL_LENGTH: 1000000000; + SQLITE_LIMIT_COLUMN: 2; + SQLITE_MAX_COLUMN: 2000; + SQLITE_LIMIT_EXPR_DEPTH: 3; + SQLITE_MAX_EXPR_DEPTH: 1000; + SQLITE_LIMIT_COMPOUND_SELECT: 4; + SQLITE_MAX_COMPOUND_SELECT: 500; + SQLITE_LIMIT_VDBE_OP: 5; + SQLITE_MAX_VDBE_OP: 250000000; + SQLITE_LIMIT_FUNCTION_ARG: 6; + SQLITE_MAX_FUNCTION_ARG: 127; + SQLITE_LIMIT_ATTACHED: 7; + SQLITE_MAX_ATTACHED: 10; + SQLITE_LIMIT_LIKE_PATTERN_LENGTH: 8; + SQLITE_MAX_LIKE_PATTERN_LENGTH: 50000; + SQLITE_LIMIT_VARIABLE_NUMBER: 9; + SQLITE_MAX_VARIABLE_NUMBER: 32766; + SQLITE_LIMIT_TRIGGER_DEPTH: 10; + SQLITE_MAX_TRIGGER_DEPTH: 1000; + SQLITE_LIMIT_WORKER_THREADS: 11; + SQLITE_MAX_WORKER_THREADS: 0; + SQLITE_OPEN_READONLY: 1; + SQLITE_OPEN_READWRITE: 2; + SQLITE_OPEN_CREATE: 4; + SQLITE_OPEN_URI: 64; + SQLITE_OPEN_MEMORY: 128; + SQLITE_OPEN_NOMUTEX: 32768; + SQLITE_OPEN_FULLMUTEX: 65536; + SQLITE_OPEN_SHAREDCACHE: 131072; + SQLITE_OPEN_PRIVATECACHE: 262144; + SQLITE_OPEN_EXRESCODE: 33554432; + SQLITE_OPEN_NOFOLLOW: 16777216; + SQLITE_OPEN_MAIN_DB: 256; + SQLITE_OPEN_MAIN_JOURNAL: 2048; + SQLITE_OPEN_TEMP_DB: 512; + SQLITE_OPEN_TEMP_JOURNAL: 4096; + SQLITE_OPEN_TRANSIENT_DB: 1024; + SQLITE_OPEN_SUBJOURNAL: 8192; + SQLITE_OPEN_SUPER_JOURNAL: 16384; + SQLITE_OPEN_WAL: 524288; + SQLITE_OPEN_DELETEONCLOSE: 8; + SQLITE_OPEN_EXCLUSIVE: 16; + SQLITE_PREPARE_PERSISTENT: 1; + SQLITE_PREPARE_NORMALIZE: 2; + SQLITE_PREPARE_NO_VTAB: 4; + SQLITE_OK: 0; + SQLITE_ERROR: 1; + SQLITE_INTERNAL: 2; + SQLITE_PERM: 3; + SQLITE_ABORT: 4; + SQLITE_BUSY: 5; + SQLITE_LOCKED: 6; + SQLITE_NOMEM: 7; + SQLITE_READONLY: 8; + SQLITE_INTERRUPT: 9; + SQLITE_IOERR: 10; + SQLITE_CORRUPT: 11; + SQLITE_NOTFOUND: 12; + SQLITE_FULL: 13; + SQLITE_CANTOPEN: 14; + SQLITE_PROTOCOL: 15; + SQLITE_EMPTY: 16; + SQLITE_SCHEMA: 17; + SQLITE_TOOBIG: 18; + SQLITE_CONSTRAINT: 19; + SQLITE_MISMATCH: 20; + SQLITE_MISUSE: 21; + SQLITE_NOLFS: 22; + SQLITE_AUTH: 23; + SQLITE_FORMAT: 24; + SQLITE_RANGE: 25; + SQLITE_NOTADB: 26; + SQLITE_NOTICE: 27; + SQLITE_WARNING: 28; + SQLITE_ROW: 100; + SQLITE_DONE: 101; + SQLITE_ERROR_MISSING_COLLSEQ: 257; + SQLITE_ERROR_RETRY: 513; + SQLITE_ERROR_SNAPSHOT: 769; + SQLITE_IOERR_READ: 266; + SQLITE_IOERR_SHORT_READ: 522; + SQLITE_IOERR_WRITE: 778; + SQLITE_IOERR_FSYNC: 1034; + SQLITE_IOERR_DIR_FSYNC: 1290; + SQLITE_IOERR_TRUNCATE: 1546; + SQLITE_IOERR_FSTAT: 1802; + SQLITE_IOERR_UNLOCK: 2058; + SQLITE_IOERR_RDLOCK: 2314; + SQLITE_IOERR_DELETE: 2570; + SQLITE_IOERR_BLOCKED: 2826; + SQLITE_IOERR_NOMEM: 3082; + SQLITE_IOERR_ACCESS: 3338; + SQLITE_IOERR_CHECKRESERVEDLOCK: 3594; + SQLITE_IOERR_LOCK: 3850; + SQLITE_IOERR_CLOSE: 4106; + SQLITE_IOERR_DIR_CLOSE: 4362; + SQLITE_IOERR_SHMOPEN: 4618; + SQLITE_IOERR_SHMSIZE: 4874; + SQLITE_IOERR_SHMLOCK: 5130; + SQLITE_IOERR_SHMMAP: 5386; + SQLITE_IOERR_SEEK: 5642; + SQLITE_IOERR_DELETE_NOENT: 5898; + SQLITE_IOERR_MMAP: 6154; + SQLITE_IOERR_GETTEMPPATH: 6410; + SQLITE_IOERR_CONVPATH: 6666; + SQLITE_IOERR_VNODE: 6922; + SQLITE_IOERR_AUTH: 7178; + SQLITE_IOERR_BEGIN_ATOMIC: 7434; + SQLITE_IOERR_COMMIT_ATOMIC: 7690; + SQLITE_IOERR_ROLLBACK_ATOMIC: 7946; + SQLITE_IOERR_DATA: 8202; + SQLITE_IOERR_CORRUPTFS: 8458; + SQLITE_LOCKED_SHAREDCACHE: 262; + SQLITE_LOCKED_VTAB: 518; + SQLITE_BUSY_RECOVERY: 261; + SQLITE_BUSY_SNAPSHOT: 517; + SQLITE_BUSY_TIMEOUT: 773; + SQLITE_CANTOPEN_NOTEMPDIR: 270; + SQLITE_CANTOPEN_ISDIR: 526; + SQLITE_CANTOPEN_FULLPATH: 782; + SQLITE_CANTOPEN_CONVPATH: 1038; + SQLITE_CANTOPEN_SYMLINK: 1550; + SQLITE_CORRUPT_VTAB: 267; + SQLITE_CORRUPT_SEQUENCE: 523; + SQLITE_CORRUPT_INDEX: 779; + SQLITE_READONLY_RECOVERY: 264; + SQLITE_READONLY_CANTLOCK: 520; + SQLITE_READONLY_ROLLBACK: 776; + SQLITE_READONLY_DBMOVED: 1032; + SQLITE_READONLY_CANTINIT: 1288; + SQLITE_READONLY_DIRECTORY: 1544; + SQLITE_ABORT_ROLLBACK: 516; + SQLITE_CONSTRAINT_CHECK: 275; + SQLITE_CONSTRAINT_COMMITHOOK: 531; + SQLITE_CONSTRAINT_FOREIGNKEY: 787; + SQLITE_CONSTRAINT_FUNCTION: 1043; + SQLITE_CONSTRAINT_NOTNULL: 1299; + SQLITE_CONSTRAINT_PRIMARYKEY: 1555; + SQLITE_CONSTRAINT_TRIGGER: 1811; + SQLITE_CONSTRAINT_UNIQUE: 2067; + SQLITE_CONSTRAINT_VTAB: 2323; + SQLITE_CONSTRAINT_ROWID: 2579; + SQLITE_CONSTRAINT_PINNED: 2835; + SQLITE_CONSTRAINT_DATATYPE: 3091; + SQLITE_NOTICE_RECOVER_WAL: 283; + SQLITE_NOTICE_RECOVER_ROLLBACK: 539; + SQLITE_WARNING_AUTOINDEX: 284; + SQLITE_AUTH_USER: 279; + SQLITE_OK_LOAD_PERMANENTLY: 256; + SQLITE_STATUS_MEMORY_USED: 0; + SQLITE_STATUS_PAGECACHE_USED: 1; + SQLITE_STATUS_PAGECACHE_OVERFLOW: 2; + SQLITE_STATUS_MALLOC_SIZE: 5; + SQLITE_STATUS_PARSER_STACK: 6; + SQLITE_STATUS_PAGECACHE_SIZE: 7; + SQLITE_STATUS_MALLOC_COUNT: 9; + SQLITE_STMTSTATUS_FULLSCAN_STEP: 1; + SQLITE_STMTSTATUS_SORT: 2; + SQLITE_STMTSTATUS_AUTOINDEX: 3; + SQLITE_STMTSTATUS_VM_STEP: 4; + SQLITE_STMTSTATUS_REPREPARE: 5; + SQLITE_STMTSTATUS_RUN: 6; + SQLITE_STMTSTATUS_FILTER_MISS: 7; + SQLITE_STMTSTATUS_FILTER_HIT: 8; + SQLITE_STMTSTATUS_MEMUSED: 99; + SQLITE_SYNC_NORMAL: 2; + SQLITE_SYNC_FULL: 3; + SQLITE_SYNC_DATAONLY: 16; + SQLITE_TRACE_STMT: 1; + SQLITE_TRACE_PROFILE: 2; + SQLITE_TRACE_ROW: 4; + SQLITE_TRACE_CLOSE: 8; + SQLITE_TXN_NONE: 0; + SQLITE_TXN_READ: 1; + SQLITE_TXN_WRITE: 2; + SQLITE_DETERMINISTIC: 2048; + SQLITE_DIRECTONLY: 524288; + SQLITE_INNOCUOUS: 2097152; + SQLITE_VERSION_NUMBER: 3043000; + SQLITE_VERSION: string; + SQLITE_SOURCE_ID: string; + SQLITE_SERIALIZE_NOCOPY: 1; + SQLITE_DESERIALIZE_FREEONCLOSE: 1; + SQLITE_DESERIALIZE_READONLY: 4; + SQLITE_DESERIALIZE_RESIZEABLE: 2; + SQLITE_SESSION_CONFIG_STRMSIZE: 1; + SQLITE_SESSION_OBJCONFIG_SIZE: 1; + SQLITE_INDEX_SCAN_UNIQUE: 1; + SQLITE_INDEX_CONSTRAINT_EQ: 2; + SQLITE_INDEX_CONSTRAINT_GT: 4; + SQLITE_INDEX_CONSTRAINT_LE: 8; + SQLITE_INDEX_CONSTRAINT_LT: 16; + SQLITE_INDEX_CONSTRAINT_GE: 32; + SQLITE_INDEX_CONSTRAINT_MATCH: 64; + SQLITE_INDEX_CONSTRAINT_LIKE: 65; + SQLITE_INDEX_CONSTRAINT_GLOB: 66; + SQLITE_INDEX_CONSTRAINT_REGEXP: 67; + SQLITE_INDEX_CONSTRAINT_NE: 68; + SQLITE_INDEX_CONSTRAINT_ISNOT: 69; + SQLITE_INDEX_CONSTRAINT_ISNOTNULL: 70; + SQLITE_INDEX_CONSTRAINT_ISNULL: 71; + SQLITE_INDEX_CONSTRAINT_IS: 72; + SQLITE_INDEX_CONSTRAINT_LIMIT: 73; + SQLITE_INDEX_CONSTRAINT_OFFSET: 74; + SQLITE_INDEX_CONSTRAINT_FUNCTION: 150; + SQLITE_VTAB_CONSTRAINT_SUPPORT: 1; + SQLITE_VTAB_INNOCUOUS: 2; + SQLITE_VTAB_DIRECTONLY: 3; + SQLITE_ROLLBACK: 1; + SQLITE_FAIL: 3; + SQLITE_REPLACE: 5; + sqlite3_js_rc_str: (rc: number) => string; + sqlite3_close_v2: (db: Database | WasmPointer) => number; + sqlite3session_delete: ( + pSession: WasmPointer, + ) => number; + sqlite3_create_collation_v2: ( + db: Database | WasmPointer, + zName: string, + eTextRep: number, + pArg: WasmPointer, + xCompare: ((pCtx: WasmPointer, len1: number, p1: WasmPointer, len2: number, p2: WasmPointer) => number) | WasmPointer, + xDestroy: ((pCtx: WasmPointer) => void) | WasmPointer, + ) => number; + sqlite3_create_collation: ( + db: Database | WasmPointer, + zName: string, + eTextRep: number, + pArg: WasmPointer, + xCompare: ((pCtx: WasmPointer, len1: number, p1: WasmPointer, len2: number, p2: WasmPointer) => number) | WasmPointer, + ) => number; + sqlite3_config: ( + op: number, + args: any, + ) => number; + sqlite3_auto_extension: ( + xEntryPoint: (( + db: Database | WasmPointer, + pzErrMsg: WasmPointer, + pThunk: WasmPointer + ) => number) | WasmPointer, + ) => number; + sqlite3_cancel_auto_extension: ( + xEntryPoint: (( + db: Database | WasmPointer, + pzErrMsg: WasmPointer, + pThunk: WasmPointer + ) => number) | WasmPointer, + ) => number; + sqlite3_reset_auto_extension: () => void; }; diff --git a/package.json b/package.json index 6dee9db..331a507 100644 --- a/package.json +++ b/package.json @@ -21,12 +21,14 @@ "sqlite-wasm/", "src/" ], + "types": "index.d.ts", "exports": { ".": { "types": "./index.d.ts", "import": "./index.mjs", "main": "./index.mjs", - "browser": "./index.mjs" + "browser": "./index.mjs", + "types": "./index.d.ts" }, "./src/comlink.mjs": "./src/comlink.mjs", "./package.json": "./package.json" From 5ee909a75f511bb8d8617319d5227f653c89878f Mon Sep 17 00:00:00 2001 From: Johannes Baiter Date: Sat, 26 Aug 2023 23:20:14 +0200 Subject: [PATCH 07/12] Fix some function types --- index.d.ts | 142 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 88 insertions(+), 54 deletions(-) diff --git a/index.d.ts b/index.d.ts index 9062e84..3ff375c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -3158,7 +3158,13 @@ declare type CAPI = { sqlite3_bind_blob: ( stmt: PreparedStatement | WasmPointer, idx: number, - blob: WasmPointer, + blob: + | WasmPointer + | string + | string[] + | Int8Array + | Uint8Array + | ArrayBuffer, n: number, dtor: | (() => void) @@ -3170,7 +3176,13 @@ declare type CAPI = { sqlite3_bind_text: ( stmt: PreparedStatement | WasmPointer, idx: number, - text: string, + text: + | string + | WasmPointer + | string[] + | Int8Array + | Uint8Array + | ArrayBuffer, n: number, dtor: | (() => void) @@ -3183,55 +3195,63 @@ declare type CAPI = { db: Database | WasmPointer, functionName: string | WasmPointer, nArg: number, - eTextRep: number, + eTextRep: CAPI['SQLITE_UTF8'], pApp: WasmPointer, xFunc: - | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => void) + | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => SqlValue) | WasmPointer, xStep: | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => void) | WasmPointer, - xFinal: ((ctx: WasmPointer) => void) | WasmPointer, + xFinal: ((ctx: WasmPointer) => SqlValue) | WasmPointer, xDestroy: (() => void) | WasmPointer, ) => number; sqlite3_create_function: ( db: Database | WasmPointer, functionName: string | WasmPointer, nArg: number, - eTextRep: number, + eTextRep: CAPI['SQLITE_UTF8'], pApp: WasmPointer, xFunc: - | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => void) + | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => SqlValue) | WasmPointer, xStep: | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => void) | WasmPointer, - xFinal: ((ctx: WasmPointer) => void) | WasmPointer, + xFinal: ((ctx: WasmPointer) => SqlValue) | WasmPointer, ) => number; sqlite3_create_window_function: ( db: Database | WasmPointer, functionName: string | WasmPointer, nArg: number, - eTextRep: number, + eTextRep: CAPI['SQLITE_UTF8'], pApp: WasmPointer, xStep: - | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => void) + | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => SqlValue) | WasmPointer, - xFinal: ((ctx: WasmPointer) => void) | WasmPointer, + xFinal: ((ctx: WasmPointer) => SqlValue) | WasmPointer, xValue: ((ctx: WasmPointer) => void) | WasmPointer, xInverse: | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => void) | WasmPointer, xDestroy: (() => void) | WasmPointer, ) => number; - sqlite3_prepare_v3: ( + sqlite3_prepare_v3( db: Database | WasmPointer, - sql: string | WasmPointer, + sql: Exclude, + nByte: -1, + prepFlags: number, + ppStmt: WasmPointer, + pzTail: null, + ): number; + sqlite3_prepare_v3( + db: Database | WasmPointer, + sql: WasmPointer, nByte: number, prepFlags: number, ppStmt: WasmPointer, pzTail: WasmPointer, - ) => number; + ): number; sqlite3_prepare_v2: ( db: Database | WasmPointer, sql: string | WasmPointer, @@ -3241,19 +3261,13 @@ declare type CAPI = { ) => number; sqlite3_exec: ( db: Database | WasmPointer, - sql: string | WasmPointer, - callback: - | (( - cbArg: WasmPointer, - nColumns: number, - values: WasmPointer, - names: WasmPointer, - ) => number) - | WasmPointer, + sql: FlexibleString, + callback: ((values: SqlValue[], names: string[]) => number) | WasmPointer, cbArg: WasmPointer, pzErrMsg: WasmPointer, ) => number; - sqlite3_randomness: (N: number, P: WasmPointer) => void; + sqlite3_randomness(N: number, P: WasmPointer): void; + sqlite3_randomness(arr: T): T; sqlite3_wasmfs_opfs_dir: () => string; sqlite3_wasmfs_filename_is_persistent: (name: string) => boolean; sqlite3_js_db_uses_vfs: ( @@ -3280,6 +3294,7 @@ declare type CAPI = { data: undefined | WasmPointer | Uint8Array | ArrayBuffer, dataLen?: number, ) => void; + // TODO: Type out the arguments for every option via overloading sqlite3_db_config: ( db: Database | WasmPointer, op: @@ -3659,10 +3674,7 @@ declare type CAPI = { | CAPI['SQLITE_STATUS_MALLOC_COUNT'] | CAPI['SQLITE_STATUS_PAGECACHE_USED'] | CAPI['SQLITE_STATUS_PAGECACHE_OVERFLOW'] - | CAPI['SQLITE_STATUS_PAGECACHE_SIZE'] - | CAPI['SQLITE_STATUS_SCRATCH_USED'] - | CAPI['SQLITE_STATUS_SCRATCH_OVERFLOW'] - | CAPI['SQLITE_STATUS_SCRATCH_SIZE'], + | CAPI['SQLITE_STATUS_PAGECACHE_SIZE'], pCurrent: WasmPointer, pHighwater: WasmPointer, resetFlag: number, @@ -3768,10 +3780,10 @@ declare type CAPI = { sqlite3_vfs_find: (vfsName: string) => sqlite3_vfs; sqlite3_vfs_register: ( - vfs: sqlite3_vfs | WasmPointer, + vfs: sqlite3_vfs | WasmPointer | string, makeDflt: number, ) => number; - sqlite3_vfs_unregister: (vfs: sqlite3_vfs | WasmPointer) => number; + sqlite3_vfs_unregister: (vfs: sqlite3_vfs | WasmPointer | string) => number; sqlite3_bind_int64: (stmt: WasmPointer, idx: number, value: BigInt) => number; sqlite3_changes64: (db: Database | WasmPointer) => BigInt; sqlite3_column_int64: (db: Database | WasmPointer, colIdx: number) => BigInt; @@ -3795,7 +3807,7 @@ declare type CAPI = { sqlite3_deserialize: ( db: Database | WasmPointer, schema: string | WasmPointer, - data: Uint8Array | Int8Array | ArrayBuffer | WasmPointer, + data: WasmPointer, dbSize: number, bufferSize: number, flags: number, @@ -4556,41 +4568,63 @@ declare type CAPI = { SQLITE_REPLACE: 5; sqlite3_js_rc_str: (rc: number) => string; sqlite3_close_v2: (db: Database | WasmPointer) => number; - sqlite3session_delete: ( - pSession: WasmPointer, - ) => number; + sqlite3session_delete: (pSession: WasmPointer) => number; sqlite3_create_collation_v2: ( db: Database | WasmPointer, zName: string, - eTextRep: number, + eTextRep: CAPI['SQLITE_UTF8'], pArg: WasmPointer, - xCompare: ((pCtx: WasmPointer, len1: number, p1: WasmPointer, len2: number, p2: WasmPointer) => number) | WasmPointer, + xCompare: + | (( + pCtx: WasmPointer, + len1: number, + p1: WasmPointer, + len2: number, + p2: WasmPointer, + ) => number) + | WasmPointer, xDestroy: ((pCtx: WasmPointer) => void) | WasmPointer, ) => number; sqlite3_create_collation: ( db: Database | WasmPointer, zName: string, - eTextRep: number, + eTextRep: CAPI['SQLITE_UTF8'], pArg: WasmPointer, - xCompare: ((pCtx: WasmPointer, len1: number, p1: WasmPointer, len2: number, p2: WasmPointer) => number) | WasmPointer, - ) => number; - sqlite3_config: ( - op: number, - args: any, + xCompare: + | (( + pCtx: WasmPointer, + len1: number, + p1: WasmPointer, + len2: number, + p2: WasmPointer, + ) => number) + | WasmPointer, ) => number; + sqlite3_config( + op: + | CAPI['SQLITE_CONFIG_COVERING_INDEX_SCAN'] + | CAPI['SQLITE_CONFIG_MEMSTATUS'] + | CAPI['SQLITE_CONFIG_SMALL_MALLOC'] + | CAPI['SQLITE_CONFIG_SORTERREF_SIZE'] + | CAPI['SQLITE_CONFIG_STMTJRNL_SPILL'] + | CAPI['SQLITE_CONFIG_URI'], + arg: number, + ): number; + sqlite3_config( + op: CAPI['SQLITE_CONFIG_LOOKASIDE'], + arg1: number, + arg2: number, + ): number; + sqlite3_config(op: CAPI['SQLITE_CONFIG_MEMDB_MAXSIZE'], arg: BigInt): number; sqlite3_auto_extension: ( - xEntryPoint: (( - db: Database | WasmPointer, - pzErrMsg: WasmPointer, - pThunk: WasmPointer - ) => number) | WasmPointer, - ) => number; - sqlite3_cancel_auto_extension: ( - xEntryPoint: (( - db: Database | WasmPointer, - pzErrMsg: WasmPointer, - pThunk: WasmPointer - ) => number) | WasmPointer, + xEntryPoint: + | (( + db: Database | WasmPointer, + pzErrMsg: WasmPointer, + pThunk: WasmPointer, + ) => number) + | WasmPointer, ) => number; + sqlite3_cancel_auto_extension: (xEntryPoint: WasmPointer) => number; sqlite3_reset_auto_extension: () => void; }; From eac4fa362ee796b4cd63f2990cec09a72879b588 Mon Sep 17 00:00:00 2001 From: Johannes Baiter Date: Wed, 30 Aug 2023 22:06:58 +0200 Subject: [PATCH 08/12] Add docstrings for all C-style API functions --- index.d.ts | 4717 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 3946 insertions(+), 771 deletions(-) diff --git a/index.d.ts b/index.d.ts index 3ff375c..9e8d4aa 100644 --- a/index.d.ts +++ b/index.d.ts @@ -3129,21 +3129,6 @@ declare type WASM_API = { /** Size of a WASM pointer in bytes. */ ptrSizeof: number; - - // Undocumented fields - ptrIR: unknown; - bigIntEnabled: unknown; - memory: unknown; - compileOptionUsed: unknown; - getMemValue: unknown; - getPtrValue: unknown; - setMemValue: unknown; - setPtrValue: unknown; - sqlite3_wasm_db_reset: unknown; - sqlite3_wasm_db_vfs: unknown; - sqlite3_wasm_vfs_create_file: unknown; - sqlite3_wasm_vfs_unlink: unknown; - ctype: unknown; }; // generated by Object.keys(sqlite3.capi).map(k => `${k}: any;`).join('\n') @@ -3155,145 +3140,168 @@ declare type CAPI = { sqlite3_vtab_cursor: typeof sqlite3_vtab_cursor; sqlite3_module: typeof sqlite3_module; sqlite3_index_info: typeof sqlite3_index_info; - sqlite3_bind_blob: ( - stmt: PreparedStatement | WasmPointer, - idx: number, - blob: - | WasmPointer - | string - | string[] - | Int8Array - | Uint8Array - | ArrayBuffer, - n: number, - dtor: - | (() => void) - | WasmPointer - | CAPI['SQLITE_STATIC'] - | CAPI['SQLITE_TRANSIENT'] - | CAPI['SQLITE_WASM_DEALLOC'], - ) => number; - sqlite3_bind_text: ( - stmt: PreparedStatement | WasmPointer, - idx: number, - text: - | string - | WasmPointer - | string[] - | Int8Array - | Uint8Array - | ArrayBuffer, - n: number, - dtor: - | (() => void) - | WasmPointer - | CAPI['SQLITE_STATIC'] - | CAPI['SQLITE_TRANSIENT'] - | CAPI['SQLITE_WASM_DEALLOC'], - ) => number; - sqlite3_create_function_v2: ( - db: Database | WasmPointer, - functionName: string | WasmPointer, - nArg: number, - eTextRep: CAPI['SQLITE_UTF8'], - pApp: WasmPointer, - xFunc: - | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => SqlValue) - | WasmPointer, - xStep: - | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => void) - | WasmPointer, - xFinal: ((ctx: WasmPointer) => SqlValue) | WasmPointer, - xDestroy: (() => void) | WasmPointer, - ) => number; - sqlite3_create_function: ( - db: Database | WasmPointer, - functionName: string | WasmPointer, - nArg: number, - eTextRep: CAPI['SQLITE_UTF8'], - pApp: WasmPointer, - xFunc: - | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => SqlValue) - | WasmPointer, - xStep: - | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => void) - | WasmPointer, - xFinal: ((ctx: WasmPointer) => SqlValue) | WasmPointer, - ) => number; - sqlite3_create_window_function: ( - db: Database | WasmPointer, - functionName: string | WasmPointer, - nArg: number, - eTextRep: CAPI['SQLITE_UTF8'], - pApp: WasmPointer, - xStep: - | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => SqlValue) - | WasmPointer, - xFinal: ((ctx: WasmPointer) => SqlValue) | WasmPointer, - xValue: ((ctx: WasmPointer) => void) | WasmPointer, - xInverse: - | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => void) - | WasmPointer, - xDestroy: (() => void) | WasmPointer, - ) => number; - sqlite3_prepare_v3( - db: Database | WasmPointer, - sql: Exclude, - nByte: -1, - prepFlags: number, - ppStmt: WasmPointer, - pzTail: null, - ): number; - sqlite3_prepare_v3( - db: Database | WasmPointer, - sql: WasmPointer, - nByte: number, - prepFlags: number, - ppStmt: WasmPointer, - pzTail: WasmPointer, - ): number; - sqlite3_prepare_v2: ( - db: Database | WasmPointer, - sql: string | WasmPointer, - nByte: number, - ppStmt: WasmPointer, - pzTail: WasmPointer, - ) => number; + + /** + * Returns a string corresponding to the {@link CAPI#SQLITE_VERSION} macro. + * This function is provided for use in DLLs. + * + * C Signature: + * + * const char *sqlite3_libversion(void) + * + * See https://www.sqlite.org/c3ref/libversion.html + */ + sqlite3_libversion: () => string; + + /** + * Returns returns a string constant whose value is the same as the + * `SQLITE_SOURCE_ID` C preprocessor macro. Except if SQLite is built using an + * edited copy of the amalgamation, then the last four characters of the hash + * might be different from `SQLITE_SOURCE_ID`. + * + * C Signature: + * + * const char *sqlite3_sourceid(void) + * + * See https://www.sqlite.org/c3ref/libversion.html + */ + sqlite3_sourceid: () => string; + + /** + * Returns an integer equal to {@link CAPI#SQLITE_VERSION_NUMBER}. + * + * C Signature: + * + * int sqlite3_libversion_number(void) + * + * See https://www.sqlite.org/c3ref/libversion.html + */ + sqlite3_libversion_number: () => number; + + /** + * Allows iterating over the list of options that were defined at compile time + * by returning the `idx`-th compile time option string. If `idx` is out of + * range, returns null. + * + * C Signature: + * + * const char *sqlite3_compileoption_get(int N) + * + * See https://www.sqlite.org/c3ref/compileoption_get.html + */ + sqlite3_compileoption_get: (idx: number) => string; + + /** + * Returns 0 or 1 indicating whether the specified option `optName` was + * defined at compile time. + * + * C Signature: + * + * int sqlite3_compileoption_used(const char *zOptName) + * + * See https://www.sqlite.org/c3ref/compileoption_get.html + */ + sqlite3_compileoption_used: (optName: string) => number; + + /** + * Destructor for the `sqlite3` object. + * + * C Signature: + * + * int sqlite3_close_v2(sqlite3*); + * + * See https://www.sqlite.org/c3ref/close.html + */ + + sqlite3_close_v2: (db: Database | WasmPointer) => number; + + /** + * A convenience wrapper around `sqlite3_prepare_v2()`, `sqlite3_step()`, and + * `sqlite3_finalize()`, that allows an application to run multiple statements + * of SQL without having to use a lot of C code. + * + * C Signature: + * + * int sqlite3_exec( + * sqlite3*, + * const char *sql, + * int (*callback)(void*,int,char**,char**), + * void *, + * char **errmsg + * ) + * + * See https://www.sqlite.org/c3ref/exec.html + */ sqlite3_exec: ( db: Database | WasmPointer, sql: FlexibleString, callback: ((values: SqlValue[], names: string[]) => number) | WasmPointer, - cbArg: WasmPointer, + pCbArg: WasmPointer, pzErrMsg: WasmPointer, ) => number; - sqlite3_randomness(N: number, P: WasmPointer): void; - sqlite3_randomness(arr: T): T; - sqlite3_wasmfs_opfs_dir: () => string; - sqlite3_wasmfs_filename_is_persistent: (name: string) => boolean; - sqlite3_js_db_uses_vfs: ( - db: Database | WasmPointer, - vfsName: string, - dbName: string, - ) => boolean; - sqlite3_js_vfs_list: () => string[]; - sqlite3_js_db_export: ( - db: Database | WasmPointer, - schema?: string | WasmPointer, - ) => Uint8Array; - sqlite3_js_db_vfs: ( - db: Database | WasmPointer, - dbName?: string | WasmPointer, - ) => WasmPointer; - sqlite3_js_aggregate_context: ( - ctx: WasmPointer, - nBytes: number, - ) => WasmPointer; - sqlite3_js_vfs_create_file: ( - vfs: string | WasmPointer | sqlite3_vfs, - name: string | WasmPointer, - data: undefined | WasmPointer | Uint8Array | ArrayBuffer, - dataLen?: number, - ) => void; + + /** + * Initializes the SQLite library. + * + * C Signature: + * + * int sqlite3_initialize(void); + * + * See https://www.sqlite.org/c3ref/initialize.html + */ + sqlite3_initialize: () => number; + + /** + * Deallocates any resources that were allocated by `sqlite3_initialize()`. + * + * C Signature: + * + * int sqlite3_shutdown(void); + * + * See https://www.sqlite.org/c3ref/initialize.html + */ + sqlite3_shutdown: () => number; + + /** + * Used to make global configuration changes to SQLite in order to tune SQLite + * to the specific needs of the application. The default configuration is + * recommended for most applications and so this routine is usually not + * necessary. It is provided to support rare applications with unusual needs. + * + * C Signature: + * + * int sqlite3_config(int, ...); + * + * See https://www.sqlite.org/c3ref/config.html + */ + sqlite3_config( + op: + | CAPI['SQLITE_CONFIG_COVERING_INDEX_SCAN'] + | CAPI['SQLITE_CONFIG_MEMSTATUS'] + | CAPI['SQLITE_CONFIG_SMALL_MALLOC'] + | CAPI['SQLITE_CONFIG_SORTERREF_SIZE'] + | CAPI['SQLITE_CONFIG_STMTJRNL_SPILL'] + | CAPI['SQLITE_CONFIG_URI'], + arg: number, + ): number; + sqlite3_config( + op: CAPI['SQLITE_CONFIG_LOOKASIDE'], + arg1: number, + arg2: number, + ): number; + sqlite3_config(op: CAPI['SQLITE_CONFIG_MEMDB_MAXSIZE'], arg: BigInt): number; + + /** + * Used to make configuration changes to a database connection. The interface + * is similar to `sqlite3_config()` except that the changes apply to a single + * database connection (specified in the first argument). + * + * C Signature: + * + * int sqlite3_db_config(sqlite3*, int op, ...); + * + * See https://www.sqlite.org/c3ref/db_config.html + */ // TODO: Type out the arguments for every option via overloading sqlite3_db_config: ( db: Database | WasmPointer, @@ -3318,89 +3326,1667 @@ declare type CAPI = { | CAPI['SQLITE_DBCONFIG_LEGACY_FILE_FORMAT'], ...args: number[] ) => number; - sqlite3_value_to_js( - sqliteValue: WasmPointer, - throwIfCannotConvert?: true, - ): SqlValue; - sqlite3_value_to_js( - sqliteValue: WasmPointer, - throwIfCannotConvert: false, - ): SqlValue | undefined; - sqlite3_values_to_js( - numVals: number, - sqliteValues: WasmPointer, - throwIfCannotConvert?: true, - ): SqlValue[]; - sqlite3_values_to_js( - numVals: number, - sqliteValues: WasmPointer, - throwIfCannotConvert: false, - ): (SqlValue | undefined)[]; - sqlite3_result_error_js: (ctx: WasmPointer, err: Error) => void; - sqlite3_result_js: ( - ctx: WasmPointer, - val: - | Error - | null - | boolean - | number - | BigInt - | string - | Uint8Array - | Int8Array - | undefined, + + /** + * Enables or disables the `extended result codes` feature of SQLite. The + * extended result codes are disabled by default for historical + * compatibility. + * + * C Signature: + * + * int sqlite3_extended_result_codes(sqlite3*, int onoff); + * + * See https://www.sqlite.org/c3ref/extended_result_codes.html + */ + sqlite3_extended_result_codes: ( + db: Database | WasmPointer, + onoff: number, + ) => number; + + /** + * Usually returns the `rowid` of the most recent successful `INSERT` into a + * rowid table or virtual table on database connection `db`. Inserts into + * `WITHOUT ROWID` tables are not recorded. If no successful `INSERT`s into + * rowid tables have ever occurred on the database connection `db`, then + * `sqlite3_last_insert_rowid(db)` returns zero + * + * C Signature: + * + * sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); + * + * See https://www.sqlite.org/c3ref/last_insert_rowid.html + */ + sqlite3_last_insert_rowid: (db: Database | WasmPointer) => BigInt; + + /** + * Allows the application to set the value returned by calling + * `sqlite3_last_insert_rowid(db)` to `rowid` without inserting a row into the + * database. + * + * C Signature: + * + * void sqlite3_set_last_insert_rowid(sqlite3*, sqlite3_int64); + * + * See https://www.sqlite.org/c3ref/set_last_insert_rowid.html + */ + sqlite3_set_last_insert_rowid: ( + db: Database | WasmPointer, + rowid: BigInt, + ) => void; + + /** + * Returns the number of rows modified, inserted or deleted by the most + * recently completed `INSERT`, `UPDATE` or `DELETE` statement on the database + * connection specified by the only parameter. Executing any other type of SQL + * statement does not modify the value returned by these functions. REturn + * value is undefined if the number of changes is bigger than 32 bits. Use + * `sqlite3_changes64()` instead in these cases. + * + * C Signature: + * + * int sqlite3_changes(sqlite3*); + * + * See https://www.sqlite.org/c3ref/changes.html + */ + sqlite3_changes: (db: Database | WasmPointer) => number; + + /** + * Returns the number of rows modified, inserted or deleted by the most + * recently completed `INSERT`, `UPDATE` or `DELETE` statement on the database + * connection specified by the only parameter. Executing any other type of SQL + * statement does not modify the value returned by these functions. + * + * C Signature: + * + * sqlite3_int64 sqlite3_changes(sqlite3*); + * + * See https://www.sqlite.org/c3ref/changes.html + */ + sqlite3_changes64: (db: Database | WasmPointer) => BigInt; + + /** + * Return the total number of rows inserted, modified or deleted by all + * `INSERT`, `UPDATE` or `DELETE` statements completed since the database + * connection was opened, including those executed as part of trigger + * programs. Executing any other type of SQL statement does not affect the + * value returned by `sqlite3_total_changes()`. Return value is undefined if + * the number of changes is bigger than 32 bits. Use + * `sqlite3_total_changes64()` instead in these cases. + * + * C Signature: + * + * int sqlite3_total_changes(sqlite3*); + * + * See https://www.sqlite.org/c3ref/total_changes.html + */ + sqlite3_total_changes: (db: Database | WasmPointer) => number; + + /** + * Return the total number of rows inserted, modified or deleted by all + * `INSERT`, `UPDATE` or `DELETE` statements completed since the database + * connection was opened, including those executed as part of trigger + * programs. Executing any other type of SQL statement does not affect the + * value returned by `sqlite3_total_changes()`. + * + * C Signature: + * + * sqlite_int64 sqlite3_total_changes64(sqlite3*); + * + * See https://www.sqlite.org/c3ref/total_changes.html + */ + sqlite3_total_changes64: (db: Database | WasmPointer) => BigInt; + + /** + * Useful during command-line input to determine if the currently entered text + * seems to form a complete SQL statement or if additional input is needed + * before sending the text into SQLite for parsing. + * + * C Signature: + * + * int sqlite3_complete(const char *sql); + * + * See https://www.sqlite.org/c3ref/complete.html + * + * @returns 1 if the input string appears to be a complete SQL statement, or 0 + */ + sqlite3_complete: (sql: string | WasmPointer) => number; + + /** + * Register A Callback To Handle `SQLITE_BUSY` Errors. + * + * The `sqlite3_busy_handler(db, callback, cbArg)` routine sets a callback + * function `callback` that might be invoked with argument `cbArg` whenever an + * attempt is made to access a database table associated with database + * connection `db` when another thread or process has the table locked. The + * `sqlite3_busy_handler()` interface is used to implement + * `sqlite3_busy_timeout()` and `PRAGMA busy_timeout`. + * + * C API: + * + * int sqlite3_busy_handler(sqlite3*,int(*)(void*,int),void*); + * + * See https://www.sqlite.org/c3ref/busy_handler.html + */ + sqlite3_busy_handler: ( + db: Database | WasmPointer, + callback: ((cbArg: WasmPointer, nTries: number) => number) | WasmPointer, + cbArg: WasmPointer, + ) => number; + + /** + * Set A Busy Timeout. + * + * Sets a `sqlite3_busy_handler` that sleeps for a specified amount of time + * when a table is locked. The handler will sleep multiple times until at + * least `ms` milliseconds of sleeping have accumulated. After at least `ms` + * milliseconds of sleeping, the handler returns 0 which causes + * `sqlite3_step()` to return `SQLITE_BUSY`. + * + * C API: + * + * int sqlite3_busy_timeout(sqlite3*, int ms); + * + * See https://www.sqlite.org/c3ref/busy_timeout.html + */ + sqlite3_busy_timeout: (db: Database | WasmPointer, ms: number) => number; + + /** + * Returns a pointer to a block of memory at least `size` bytes in length. ^If + * `sqlite3_malloc()` is unable to obtain sufficient free memory, it throws a + * `WasmAllocError`. + * + * C Signature: + * + * void *sqlite3_malloc(int); + * + * See https://www.sqlite.org/c3ref/free.html + */ + sqlite3_malloc: (size: number) => WasmPointer; + + /** + * Returns a pointer to a block of memory at least `size` bytes in length. ^If + * `sqlite3_malloc()` is unable to obtain sufficient free memory, it throws a + * `WasmAllocError`. + * + * C Signature: + * + * void *sqlite3_malloc(sqlite_uint64); + * + * See https://www.sqlite.org/c3ref/free.html + */ + sqlite3_malloc64: (numBytes: BigInt) => WasmPointer; + + /** + * Attempts to resize a prior memory allocation X to be at least N bytes. + * + * If the `size` parameter to `sqlite3_realloc(ptr, size)` is a NULL pointer + * then its behavior is identical to calling `sqlite3_malloc(size)`. + * + * If the `size` parameter to `sqlite3_realloc(ptr, size)` is zero or negative + * then the behavior is exactly the same as calling `sqlite3_free(ptr)`. + * + * `sqlite3_realloc(ptr, size)` returns a pointer to a memory allocation of at + * least `size` bytes in size or NULL if insufficient memory is available. + * + * C Signature: + * + * void *sqlite3_realloc(void*, int); + * + * See https://www.sqlite.org/c3ref/free.html + */ + sqlite3_realloc: (ptr: WasmPointer, size: number) => WasmPointer; + + /** + * Attempts to resize a prior memory allocation X to be at least N bytes. + * + * If the `size` parameter to `sqlite3_realloc(ptr, size)` is a NULL pointer + * then its behavior is identical to calling `sqlite3_malloc(size)`. + * + * If the `size` parameter to `sqlite3_realloc(ptr, size)` is zero or negative + * then the behavior is exactly the same as calling `sqlite3_free(ptr)`. + * + * `sqlite3_realloc(ptr, size)` returns a pointer to a memory allocation of at + * least `size` bytes in size or NULL if insufficient memory is available. + * + * C Signature: + * + * void *sqlite3_realloc(void*, sqlite_uint64); + * + * See https://www.sqlite.org/c3ref/free.html + */ + sqlite3_realloc64: (ptr: WasmPointer, numBytes: BigInt) => WasmPointer; + + /** + * Calling `sqlite3_free()` with a pointer previously returned by + * `sqlite3_malloc()` or `sqlite3_realloc()` releases that memory so that it + * might be reused. + * + * The `sqlite3_free()` routine is a no-op if is called with a NULL pointer. + * Passing a NULL pointer to `sqlite3_free()` is harmless. After being freed, + * memory should neither be read nor written. Even reading previously freed + * memory might result in a segmentation fault or other severe error. Memory + * corruption, a segmentation fault, or other severe error might result if + * `sqlite3_free()` is called with a non-NULL pointer that was not obtained + * from `sqlite3_malloc()` or `sqlite3_realloc()`. + * + * C Signature: + * + * void sqlite3_free(void*); + * + * See https://www.sqlite.org/c3ref/free.html + */ + sqlite3_free: (ptr: WasmPointer) => void; + + /** + * If `ptr` is a memory allocation previously obtained from + * `sqlite3_malloc()`, `sqlite3_malloc64()`, `sqlite3_realloc()`, or + * `sqlite3_realloc64()`, then `sqlite3_msize(ptr)` returns the size of that + * memory allocation in bytes. + * + * C Signature: + * + * sqlite3_uint64 sqlite3_msize(void*); + * + * See https://www.sqlite.org/c3ref/free.html + */ + sqlite3_msize: (ptr: WasmPointer) => BigInt; + + /** + * Pseudo-Random Number Generator + * + * A call to this routine stores `N` bytes of randomness into buffer `P` or + * array `arr`. + * + * C Signature: + * + * void sqlite3_randomness(int N, void *P); + * + * See https://www.sqlite.org/c3ref/randomness.html + */ + sqlite3_randomness(N: number, P: WasmPointer): void; + sqlite3_randomness(arr: T): T; + + /** + * This routine registers an authorizer callback with a particular database + * connection, supplied in the first argument. The authorizer callback is + * invoked as SQL statements are being compiled by `sqlite3_prepare()` or its + * variants `sqlite3_prepare_v2()`, `sqlite3_prepare_v3()`, + * `sqlite3_prepare16()`, `sqlite3_prepare16_v2()`, and + * `sqlite3_prepare16_v3()`. + * + * At various points during the compilation process, as logic is being created + * to perform various actions, the authorizer callback is invoked to see if + * those actions are allowed. + * + * The authorizer callback should return `SQLITE_OK` to allow the action, + * `SQLITE_IGNORE` to disallow the specific action but allow the SQL statement + * to continue to be compiled, or `SQLITE_DENY` to cause the entire SQL + * statement to be rejected with an error. + * + * C Signature: + * + * int sqlite3_set_authorizer( + * sqlite3*, + * int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), + * void *pUserData + * ); + * + * See https://www.sqlite.org/c3ref/set_authorizer.html + */ + sqlite3_set_authorizer: ( + db: Database | WasmPointer, + xAuth: ( + cbArg: WasmPointer, + actionCode: number, + arg1: string | 0, + arg2: string | 0, + arg3: string | 0, + arg4: string | 0, + ) => number, + cbArg: WasmPointer, + ) => number; + + /** + * Registers a trace callback function `xCallback` against database connection + * `db`, using property mask `mask` and context pointer `cbArg`. If the + * `xCallback` callback is NULL or if the `mask` is zero, then tracing is + * disabled. The `mask argument should be the bitwise OR-ed combination of + * zero or more `SQLITE_TRACE`constants. The`xCallback`callback is invoked + * whenever any of the events identified by mask`mask occur. + * + * C Signature: + * + * int sqlite3_trace_v2( + * sqlite3*, + * unsigned uMask, + * int(*xCallback)(unsigned,void*,void*,void*), + * void *pCtx + * ); + * + * See https://www.sqlite.org/c3ref/trace_v2.html + */ + sqlite3_trace_v2: ( + db: Database | WasmPointer, + mask: number, + xCallback: ( + reason: number, + cbArg: WasmPointer, + arg1: WasmPointer, + arg2: WasmPointer, + ) => number, + ) => number; + + /** + * Causes the callback function `callback` to be invoked periodically during + * long running calls to `sqlite3_step()` and `sqlite3_prepare()` and similar + * for database connection `db`. An example use for this interface is to keep + * a GUI updated during a large query. + * + * C Signature: + * + * void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); + * + * See https://www.sqlite.org/c3ref/progress_handler.html + */ + sqlite3_progress_handler: ( + db: Database | WasmPointer, + nOps: number, + callback: ((cbArg: WasmPointer) => number) | WasmPointer, + cbArg: WasmPointer, ) => void; + + /** + * Open an SQLite database file as specified by the `filename` argument + * + * C Signature: + * + * int sqlite3_open( + * const char *filename, // Database filename (UTF-8) + * sqlite3 **ppDb // OUT: SQLite db handle + * ); + * + * See https://www.sqlite.org/c3ref/open.html + */ + sqlite3_open: (filename: string | WasmPointer, ppDb: WasmPointer) => number; + + /** + * Open an SQLite database file as specified by the `filename` argument + * + * C Signature: + * + * int sqlite3_open_v2( + * const char *filename, // Database filename (UTF-8) + * sqlite3 **ppDb, // OUT: SQLite db handle + * int flags, // Flags + * const char *zVfs // Name of VFS module to use + * ); + * + * See https://www.sqlite.org/c3ref/open.html + */ + sqlite3_open_v2: ( + filename: string | WasmPointer, + ppDb: WasmPointer, + flags: number, + vfs: string | WasmPointer, + ) => number; + + /** + * Checks if a database file `uri` was a URI that contained a specific query + * parameter `param`, and if so obtains the value of that query parameter. + * + * C Signature: + * + * const char *sqlite3_uri_parameter(sqlite3_filename z, const char *zParam) + * + * See https://www.sqlite.org/c3ref/uri_parameter.html + */ + sqlite3_uri_parameter: ( + uri: string | WasmPointer, + param: string | WasmPointer, + ) => string | null; + + /** + * Assumes that `param` is a boolean parameter and returns true (1) or false + * (0) according to the value of `param`. + * + * C Signature: + * + * int sqlite3_uri_boolean(sqlite3_filename z, const char *zParam, int bDefault) + * + * See https://www.sqlite.org/c3ref/uri_boolean.html + */ + sqlite3_uri_boolean: ( + uri: string | WasmPointer, + param: string | WasmPointer, + dflt: number, + ) => number; + + /** + * Converts the value of `paramName` into a 64-bit signed integer and returns + * that integer, or `defaultVal` if `paramName` does not exist. If the value + * of `paramName` is something other than an integer, then zero is returned. + * + * C Signature: + * + * sqlite3_int64 sqlite3_uri_int64(sqlite3_filename, const char*, sqlite3_int64); + * + * See https://www.sqlite.org/c3ref/uri_boolean.html + */ + sqlite3_uri_int64: ( + uri: string | WasmPointer, + paramName: string | WasmPointer, + defaultVal: BigInt, + ) => BigInt; + + /** + * Returns a pointer to the name (not the value) of the `idx`-th query + * parameter for filename `uri`. + * + * C Signature: + * + * const char *sqlite3_uri_key(sqlite3_filename z, int N) + * + * See https://www.sqlite.org/c3ref/uri_boolean.html + */ + sqlite3_uri_key: (uri: string | WasmPointer, idx: number) => string | null; + + /** + * If the most recent `sqlite3_*` API call associated with database connection + * `db` failed, then the `sqlite3_errcode(db)` interface returns the numeric + * result code or extended result code for that API call. + * + * C Signature: + * + * int sqlite3_errcode(sqlite3 *db); + * + * See https://www.sqlite.org/c3ref/errcode.html + */ + sqlite3_errcode: (db: Database | WasmPointer) => number; + + /** + * If the most recent `sqlite3_*` API call associated with database connection + * `db` failed, then the `sqlite3_extended_errcode(db)` interface returns the + * extended result code for that API call, even when extended result codes are + * disabled. + * + * C Signature: + * + * int sqlite3_extended_errcode(sqlite3 *db); + * + * See https://www.sqlite.org/c3ref/errcode.html + */ + sqlite3_extended_errcode: (db: Database | WasmPointer) => number; + + /** + * If the most recent `sqlite3_*` API call associated with database connection + * `db` failed, then the `sqlite3_errmsg(db)` interface returns English- + * language text that describes the error. + * + * C Signature: + * + * const char *sqlite3_errmsg(sqlite3*); + * + * See https://www.sqlite.org/c3ref/errcode.html + */ + sqlite3_errmsg: (db: Database | WasmPointer) => string; + + /** + * Returns the English-language text that describes the result code, + * + * C Signature: + * + * const char *sqlite3_errstr(int); + * + * See https://www.sqlite.org/c3ref/errcode.html + */ + sqlite3_errstr: (rc: number) => string; + + /** + * If the most recent error references a specific token in the input SQL, the + * `sqlite3_error_offset()` interface returns the byte offset of the start of + * that token. The byte offset returned by `sqlite3_error_offset()` assumes + * that the input SQL is UTF8. + * + * If the most recent error does not reference a specific token in the input + * SQL, then the sqlite3_error_offset() function returns -1. + * + * C Signature: + * + * int sqlite3_error_offset(sqlite3 *db); + * + * See https://www.sqlite.org/c3ref/errcode.html + */ + sqlite3_error_offset: (db: Database | WasmPointer) => number; + + /** + * This interface allows the size of various constructs to be limited on a + * connection by connection basis. The first parameter is the database + * connection whose limit is to be set or queried. The second parameter is one + * of the limit categories that define a class of constructs to be size + * limited. The third parameter is the new limit for that construct. + * + * C Signature: + * + * int sqlite3_limit(sqlite3*, int id, int newVal); + * + * See https://www.sqlite.org/c3ref/limit.html + */ + sqlite3_limit: ( + db: Database | WasmPointer, + id: + | CAPI['SQLITE_LIMIT_LENGTH'] + | CAPI['SQLITE_LIMIT_SQL_LENGTH'] + | CAPI['SQLITE_LIMIT_COLUMN'] + | CAPI['SQLITE_LIMIT_EXPR_DEPTH'] + | CAPI['SQLITE_LIMIT_COMPOUND_SELECT'] + | CAPI['SQLITE_LIMIT_VDBE_OP'] + | CAPI['SQLITE_LIMIT_FUNCTION_ARG'] + | CAPI['SQLITE_LIMIT_ATTACHED'] + | CAPI['SQLITE_LIMIT_LIKE_PATTERN_LENGTH'] + | CAPI['SQLITE_LIMIT_VARIABLE_NUMBER'] + | CAPI['SQLITE_LIMIT_TRIGGER_DEPTH'] + | CAPI['SQLITE_LIMIT_WORKER_THREADS'], + newVal: number, + ) => number; + + /** + * Compiles a prepared statement. + * + * C Signature: + * + * int sqlite3_prepare_v2( + * sqlite3 *db, + * const char *zSql, + * int nByte, + * sqlite3_stmt **ppStmt, + * const char **pzTail + * ); + * + * See https://www.sqlite.org/c3ref/prepare.html + * + * @param db Database handle + * @param sql SQL statement + * @param nByte Number of bytes in SQL statement (-1 for null terminated) + * @param ppStmt OUT: Statement handle + * @param pzTail OUT: Pointer to unused portion of SQL statement + */ + sqlite3_prepare_v2: ( + db: Database | WasmPointer, + sql: string | WasmPointer, + nByte: number, + ppStmt: WasmPointer, + pzTail: WasmPointer, + ) => number; + + /** + * Compiles a prepared statement. + * + * C Signature: + * + * int sqlite3_prepare_v2( + * sqlite3 *db, + * const char *zSql, + * int nByte, + * unsigned int prepFlags, + * sqlite3_stmt **ppStmt, + * const char **pzTail + * ); + * + * See https://www.sqlite.org/c3ref/prepare.html + * + * @param db Database handle + * @param sql SQL statement + * @param nByte Number of bytes in SQL statement (-1 for null terminated) + * @param prepFlags Zero or more SQLITE_PREPARE_* flags + * @param ppStmt OUT: Statement handle + * @param pzTail OUT: Pointer to unused portion of SQL statement + */ + sqlite3_prepare_v3( + db: Database | WasmPointer, + sql: Exclude, + nByte: -1, + prepFlags: number, + ppStmt: WasmPointer, + pzTail: null, + ): number; + sqlite3_prepare_v3( + db: Database | WasmPointer, + sql: WasmPointer, + nByte: number, + prepFlags: number, + ppStmt: WasmPointer, + pzTail: WasmPointer, + ): number; + + /** + * Returns a pointer to a copy of the UTF-8 SQL text used to create prepared + * statement `stmt` if `stmt` was created by `sqlite3_prepare_v2()` or + * `sqlite3_prepare_v3()`. + * + * C Signature: + * + * const char *sqlite3_sql(sqlite3_stmt *pStmt); + * + * See https://www.sqlite.org/c3ref/sql.html + */ + sqlite3_sql: (stmt: PreparedStatement | WasmPointer) => string; + + /** + * Returns a pointer to a UTF-8 string containing the SQL text of prepared + * statement `stmt` with bound parameters expanded. + * + * C Signature: + * + * const char *sqlite3_expanded_sql(sqlite3_stmt *pStmt); + * + * See https://www.sqlite.org/c3ref/expanded_sql.html + */ + sqlite3_expanded_sql: (stmt: PreparedStatement | WasmPointer) => string; + + /** + * Returns true (non-zero) if and only if the prepared statement `stmt` makes + * no direct changes to the content of the database file. + * + * C Signature: + * + * int sqlite3_stmt_readonly(sqlite3_stmt *pStmt); + * + * See https://www.sqlite.org/c3ref/stmt_readonly.html + */ + sqlite3_stmt_readonly: (stmt: PreparedStatement | WasmPointer) => number; + + /** + * Returns 1 if the prepared statement `stmt` is an `EXPLAIN` statement, or 2 + * if the statement `stmt` is an `EXPLAIN QUERY PLAN`. Returns 0 if `stmt` is + * an ordinary statement or a NULL pointer + * + * C Signature: + * + * int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt); + * + * See https://www.sqlite.org/c3ref/stmt_isexplain.html + */ + sqlite3_stmt_isexplain: (stmt: PreparedStatement | WasmPointer) => 0 | 1 | 2; + + /** + * Bind a `BLOB` value to a parameter in a prepared statement. + * + * C Signature: + * + * int sqlite3_bind_blob( + * sqlite3_stmt*, + * int, + * const void*, + * int n, + * void(*)(void*) + * + * ); + * + * See https://www.sqlite.org/c3ref/bind_blob.html + */ + sqlite3_bind_blob: ( + stmt: PreparedStatement | WasmPointer, + idx: number, + blob: + | WasmPointer + | string + | string[] + | Int8Array + | Uint8Array + | ArrayBuffer, + n: number, + dtor: + | (() => void) + | WasmPointer + | CAPI['SQLITE_STATIC'] + | CAPI['SQLITE_TRANSIENT'] + | CAPI['SQLITE_WASM_DEALLOC'], + ) => number; + + /** + * Bind a double precision floating point number to a parameter in a prepared + * statement. + * + * C Signature: + * + * int sqlite3_bind_double(sqlite3_stmt*, int, double); + * + * See https://www.sqlite.org/c3ref/bind_blob.html + */ + sqlite3_bind_double: ( + stmt: PreparedStatement | WasmPointer, + idx: number, + value: number, + ) => number; + + /** + * Bind an integer number to a parameter in a prepared statement. + * + * C Signature: + * + * int sqlite3_bind_int(sqlite3_stmt*, int, int); + * + * See https://www.sqlite.org/c3ref/bind_blob.html + */ + sqlite3_bind_int: ( + stmt: PreparedStatement | WasmPointer, + idx: number, + value: number, + ) => number; + + /** + * Bind a 64 bit integer number to a parameter in a prepared statement. + * + * C Signature: + * + * int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64); + * + * See https://www.sqlite.org/c3ref/bind_blob.html + */ + sqlite3_bind_int64: (stmt: WasmPointer, idx: number, value: BigInt) => number; + + /** + * Bind a `NULL` value to a parameter in a prepared statement. + * + * C Signature: + * + * int sqlite3_bind_null(sqlite3_stmt*, int); + * + * See https://www.sqlite.org/c3ref/bind_blob.html + */ + sqlite3_bind_null: ( + stmt: PreparedStatement | WasmPointer, + idx: number, + ) => number; + + /** + * Bind a `TEXT` value to a parameter in a prepared statement. + * + * C Signature: + * + * int sqlite3_bind_text( + * sqlite3_stmt*, + * int, + * const char*, + * int n, + * void(*)(void*) + * + * ); + * + * See https://www.sqlite.org/c3ref/bind_blob.html + */ + sqlite3_bind_text: ( + stmt: PreparedStatement | WasmPointer, + idx: number, + text: + | string + | WasmPointer + | string[] + | Int8Array + | Uint8Array + | ArrayBuffer, + n: number, + dtor: + | (() => void) + | WasmPointer + | CAPI['SQLITE_STATIC'] + | CAPI['SQLITE_TRANSIENT'] + | CAPI['SQLITE_WASM_DEALLOC'], + ) => number; + + /** + * Causes the `idx`-th parameter in prepared statement `stmt` to have an SQL + * value of `NULL`, but to also be associated with the pointer `ptr` of type + * `type`. `dtor` is either a `NULL pointer` or a pointer to a destructor + * function for `ptr`. SQLite will invoke the destructor `dtor` with a single + * argument of `ptr` when it is finished using `ptr`. The `type` parameter + * should be a static string, preferably a string literal. + * + * C Signature: + * + * int sqlite3_bind_pointer( + * sqlite3_stmt*, + * int, + * void*, + * const char*, + * void(*)(void*) + * ); + * + * See https://www.sqlite.org/c3ref/bind_blob.html + */ + sqlite3_bind_pointer: ( + stmt: PreparedStatement | WasmPointer, + idx: number, + ptr: WasmPointer, + type: string | WasmPointer, + dtor: + | (() => void) + | WasmPointer + | CAPI['SQLITE_STATIC'] + | CAPI['SQLITE_TRANSIENT'] + | CAPI['SQLITE_WASM_DEALLOC'], + ) => number; + + /** + * Used to find the number of SQL parameters in a prepared statement. SQL + * parameters are tokens of the form `?`, `?NNN`, `:AAA`, `$AAA`, or `@AAA` + * that serve as placeholders for values that are bound to the parameters at a + * later time. + * + * C Signature: + * + * int sqlite3_bind_parameter_count(sqlite3_stmt*); + * + * See https://www.sqlite.org/c3ref/bind_parameter_count.html + */ + sqlite3_bind_parameter_count: ( + stmt: PreparedStatement | WasmPointer, + ) => number; + + /** + * Return the index of an SQL parameter given its name. The index value + * returned is suitable for use as the second parameter to `sqlite3_bind()`. A + * zero is returned if no matching parameter is found. + * + * C Signature: + * + * int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); + * + * See https://www.sqlite.org/c3ref/bind_parameter_index.html + */ + sqlite3_bind_parameter_index: ( + stmt: PreparedStatement | WasmPointer, + name: string | WasmPointer, + ) => number; + + /** + * Use this routine to reset all host parameters to NULL. + * + * C Signature: + * + * int sqlite3_clear_bindings(sqlite3_stmt*); + * + * See https://www.sqlite.org/c3ref/clear_bindings.html + */ + sqlite3_clear_bindings: (db: Database | WasmPointer) => number; + + /** + * Returns the number of columns in the result set returned by the prepared + * statement. + * + * C Signature: + * + * int sqlite3_column_count(sqlite3_stmt *pStmt); + * + * See https://www.sqlite.org/c3ref/column_count.html + */ + sqlite3_column_count: (stmt: PreparedStatement | WasmPointer) => number; + + /** + * Returns the name assigned to a particular column in the result set of a + * `SELECT statement`. + * + * C Signature: + * + * const char *sqlite3_column_name(sqlite3_stmt*, int N); + * + * See https://www.sqlite.org/c3ref/column_name.html + */ + sqlite3_column_name: ( + stmt: PreparedStatement | WasmPointer, + colIdx: number, + ) => string; + + /** + * Returns the result of passing the result of + * `sqlite3_column_value(pStmt,iCol)` to `sqlite3_value_to_js()`. The 3rd + * argument of this function is ignored by this function except to pass it on + * as the second argument of `sqlite3_value_to_js()`. If the + * `sqlite3_column_value()` returns `NULL` (e.g. because the column index is + * out of range), this function returns `undefined`, regardless of the 3rd + * argument. If the 3rd argument is falsy and conversion fails, `undefined` + * will be returned. + */ sqlite3_column_js( stmt: PreparedStatement | WasmPointer, colIdx: number, throwIfCannotConvert?: true, - ): SqlValue; + ): SqlValue | undefined; sqlite3_column_js( stmt: PreparedStatement | WasmPointer, colIdx: number, throwIfCannotConvert: false, ): SqlValue | undefined; - sqlite3_preupdate_new_js: ( - db: Database | WasmPointer, + + /** + * After a prepared statement has been prepared using any of + * `sqlite3_prepare_v2()`, `sqlite3_prepare_v3()`, `sqlite3_prepare16_v2()`, + * or `sqlite3_prepare16_v3()` or one of the legacy interfaces + * `sqlite3_prepare()` or `sqlite3_prepare16()`, this function must be called + * one or more times to evaluate the statement. + * + * C Signature: + * + * int sqlite3_step(sqlite3_stmt*); + * + * See https://www.sqlite.org/c3ref/step.html + */ + sqlite3_step: (stmt: PreparedStatement | WasmPointer) => number; + + /** + * Returns the number of columns in the current row of the result set of + * prepared statement `stmt`. + * + * C Signature: + * + * int sqlite3_data_count(sqlite3_stmt *pStmt); + * + * See https://www.sqlite.org/c3ref/data_count.html + */ + sqlite3_data_count: (stmt: PreparedStatement | WasmPointer) => number; + + /** + * Get a BLOB result value from a column in the current result row. + * + * C Signature: + * + * const void *sqlite3_column_blob(sqlite3_stmt*, int iCol); + * + * See https://www.sqlite.org/c3ref/column_blob.html + */ + sqlite3_column_blob: ( + stmt: PreparedStatement | WasmPointer, colIdx: number, - ) => SqlValue; - sqlite3_preupdate_old_js: ( - db: Database | WasmPointer, + ) => WasmPointer; + + /** + * Get a double precision floating point result value from a column in the + * current result row. + * + * C Signature: + * + * double sqlite3_column_blob(sqlite3_stmt*, int iCol); + * + * See https://www.sqlite.org/c3ref/column_blob.html + */ + sqlite3_column_double: ( + stmt: PreparedStatement | WasmPointer, colIdx: number, - ) => SqlValue; - sqlite3changeset_new_js: ( - pChangeSetIter: WasmPointer, + ) => number; + + /** + * Get an integer result value from a column in the current result row. + * + * C Signature: + * + * int sqlite3_column_int(sqlite3_stmt*, int iCol); + * + * See https://www.sqlite.org/c3ref/column_blob.html + */ + sqlite3_column_int: ( + stmt: PreparedStatement | WasmPointer, colIdx: number, - ) => SqlValue; - sqlite3changeset_old_js: ( - pChangeSetIter: WasmPointer, + ) => number; + + /** + * Get a 64bit integer result value from a column in the current result row. + * + * C Signature: + * + * sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol); + * + * See https://www.sqlite.org/c3ref/column_blob.html + */ + sqlite3_column_int64: (db: Database | WasmPointer, colIdx: number) => BigInt; + + /** + * Get a TEXT result value from a column in the current result row. + * + * C Signature: + * + * const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol); + * + * See https://www.sqlite.org/c3ref/column_blob.html + */ + sqlite3_column_text: ( + stmt: PreparedStatement | WasmPointer, colIdx: number, - ) => SqlValue; + ) => string; + + /** + * Get a `sql_value*` result value from a column in the current result row. + * + * C Signature: + * + * const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol); + * + * See https://www.sqlite.org/c3ref/column_blob.html + */ + sqlite3_column_value: ( + stmt: PreparedStatement | WasmPointer, + colIdx: number, + ) => WasmPointer; + + /** + * Returns the initial data type of the result column in the current result + * row. + * + * C Signature: + * + * int sqlite3_column_bytes(sqlite3_stmt*, int iCol); + * + * See https://www.sqlite.org/c3ref/column_blob.html + */ + sqlite3_column_bytes: ( + stmt: PreparedStatement | WasmPointer, + colIdx: number, + ) => number; + + /** + * Get the length in bytes of a BLOB or TEXT column in the current result row. + * + * C Signature: + * + * int sqlite3_column_type(sqlite3_stmt*, int iCol); + * + * See https://www.sqlite.org/c3ref/column_blob.html + */ + sqlite3_column_type: ( + stmt: PreparedStatement | WasmPointer, + colIdx: number, + ) => number; + + /** + * The `sqlite3_finalize()` function is called to delete a prepared statement. + * If the most recent evaluation of the statement encountered no errors or if + * the statement is never been evaluated, then `sqlite3_finalize()` returns + * `SQLITE_OK`. If the most recent evaluation of statement `stmt` failed, then + * `sqlite3_finalize(stmt)` returns the appropriate error code or extended + * error code. + * + * C Signature: + * + * int sqlite3_finalize(sqlite3_stmt *pStmt); + * + * See https://www.sqlite.org/c3ref/finalize.html + */ + sqlite3_finalize: (stmt: PreparedStatement | WasmPointer) => number; + + /** + * Called to reset a [prepared statement] object back to its initial state, + * ready to be re-executed. Any SQL statement variables that had values bound + * to them using the `sqlite3_bind_*()` API retain their values. Use + * `sqlite3_clear_bindings()` to reset the bindings. + * + * C Signature: + * + * int sqlite3_reset(sqlite3_stmt *pStmt); + * + * See https://www.sqlite.org/c3ref/reset.html + */ + sqlite3_reset: (stmt: PreparedStatement | WasmPointer) => number; + + /** + * Add SQL function or aggregation or redefine the behavior of an existing SQL + * function or aggregation. + * + * C Signature: + * + * int sqlite3_create_function( + * sqlite3 *db, + * const char *zFunctionName, + * int nArg, + * int eTextRep, + * void *pApp, + * void (*xFunc)(sqlite3_context*,int,sqlite3_value**), + * void (*xStep)(sqlite3_context*,int,sqlite3_value**), + * void (*xFinal)(sqlite3_context*) + * ); + * + * See https://www.sqlite.org/c3ref/create_function.html + */ + sqlite3_create_function: ( + db: Database | WasmPointer, + functionName: string | WasmPointer, + nArg: number, + eTextRep: CAPI['SQLITE_UTF8'], + pApp: WasmPointer, + xFunc: + | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => SqlValue) + | WasmPointer, + xStep: + | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => void) + | WasmPointer, + xFinal: ((ctx: WasmPointer) => SqlValue) | WasmPointer, + ) => number; + + /** + * Add SQL function or aggregation or redefine the behavior of an existing SQL + * function or aggregation. + * + * C Signature: + * + * int sqlite3_create_function_v2( + * sqlite3 *db, + * const char *zFunctionName, + * int nArg, + * int eTextRep, + * void *pApp, + * void (*xFunc)(sqlite3_context*,int,sqlite3_value**), + * void (*xStep)(sqlite3_context*,int,sqlite3_value**), + * void (*xFinal)(sqlite3_context*), + * void(*xDestroy)(void*) + * ); + * + * See https://www.sqlite.org/c3ref/create_function.html + */ + sqlite3_create_function_v2: ( + db: Database | WasmPointer, + functionName: string | WasmPointer, + nArg: number, + eTextRep: CAPI['SQLITE_UTF8'], + pApp: WasmPointer, + xFunc: + | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => SqlValue) + | WasmPointer, + xStep: + | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => void) + | WasmPointer, + xFinal: ((ctx: WasmPointer) => SqlValue) | WasmPointer, + xDestroy: (() => void) | WasmPointer, + ) => number; + + /** + * Add SQL aggregate window function or redefine the behavior of an existing + * SQL aggregate window function. + * + * C Signature: + * + * int sqlite3_create_window_function( + * sqlite3 *db, + * const char *zFunctionName, + * int nArg, + * int eTextRep, + * void *pApp, + * void (*xStep)(sqlite3_context*,int,sqlite3_value**), + * void (*xFinal)(sqlite3_context*), + * void (*xValue)(sqlite3_context*), + * void (*xInverse)(sqlite3_context*,int,sqlite3_value**), + * void(*xDestroy)(void*) + * ); + * + * See https://www.sqlite.org/c3ref/create_function.html + */ + sqlite3_create_window_function: ( + db: Database | WasmPointer, + functionName: string | WasmPointer, + nArg: number, + eTextRep: CAPI['SQLITE_UTF8'], + pApp: WasmPointer, + xStep: + | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => SqlValue) + | WasmPointer, + xFinal: ((ctx: WasmPointer) => SqlValue) | WasmPointer, + xValue: ((ctx: WasmPointer) => void) | WasmPointer, + xInverse: + | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => void) + | WasmPointer, + xDestroy: (() => void) | WasmPointer, + ) => number; + + /** + * Extract a `BLOB` value from a protected `sqlite3_value` object. + * + * **Achtung:** The pointer returned from this function can be invalidated by + * subsequent calls to `sqlite3_value_bytes` or `sqlite3_value_text()`! + * + * C Signature: + * + * const void *sqlite3_value_blob(sqlite3_value*); + * + * See https://www.sqlite.org/c3ref/value_blob.html + */ + sqlite3_value_blob: (sqliteValue: WasmPointer) => WasmPointer; + + /** + * Extract a `REAL` value from a protected `sqlite3_value` object. + * + * C Signature: + * + * double sqlite3_value_double(sqlite3_value*); + * + * See https://www.sqlite.org/c3ref/value_blob.html + */ + sqlite3_value_double: (sqliteValue: WasmPointer) => number; + + /** + * Extract a `INTEGER` value from a protected `sqlite3_value` object. + * + * C Signature: + * + * int sqlite3_value_int(sqlite3_value*); + * + * See https://www.sqlite.org/c3ref/value_blob.html + */ + sqlite3_value_int: (sqliteValue: WasmPointer) => number; + + /** + * Extract a 64-bit `INTEGER` value from a protected `sqlite3_value` object. + * + * C Signature: + * + * sqlite3_int64 sqlite3_value_int64(sqlite3_value*); + * + * See https://www.sqlite.org/c3ref/value_blob.html + */ + sqlite3_value_int64: (sqliteValue: WasmPointer) => BigInt; + + /** + * Extract a pointer value from a protected `sqlite3_value` object. If the + * object was not initialized using `sqlite3_bind_pointer` or + * `sqlite3_result_pointer`, then this routine returns a NULL pointer. + * + * C Signature: + * + * void *sqlite3_value_pointer(sqlite3_value*, const char*); + * + * See https://www.sqlite.org/c3ref/value_blob.html + */ + sqlite3_value_pointer: ( + sqliteValue: WasmPointer, + type: string | WasmPointer, + ) => WasmPointer; + + /** + * Extract a `TEXT` value from a protected `sqlite3_value` object. + * + * **Achtung:** The pointer returned from this function can be invalidated by + * subsequent calls to `sqlite3_value_bytes()` or `sqlite3_value_text()`! + * + * C Signature: + * + * const unsigned char *sqlite3_value_text(sqlite3_value*); + * + * See https://www.sqlite.org/c3ref/value_blob.html + */ + sqlite3_value_text: (sqliteValue: WasmPointer) => string; + + /** + * Get the size of a `BLOB` or `TEXT` value in bytes from a protected + * `sqlite3_value` object. + * + * C Signature: + * + * int sqlite3_value_bytes(sqlite3_value*); + * + * See https://www.sqlite.org/c3ref/value_blob.html + */ + sqlite3_value_bytes: (sqliteValue: WasmPointer) => number; + + /** + * Get the default datatype of the value from a protected `sqlite3_value` + * object. + * + * C Signature: + * + * int sqlite3_value_type(sqlite3_value*); + * + * See https://www.sqlite.org/c3ref/value_blob.html + */ + sqlite3_value_type: (sqliteValue: WasmPointer) => number; + + /** + * Get the best numeric datatype of the value from a protected `sqlite3_value` + * object. + * + * C Signature: + * + * int sqlite3_value_numeric_type(sqlite3_value*); + * + * See https://www.sqlite.org/c3ref/value_blob.html + */ + sqlite3_value_numeric_type: (sqliteValue: WasmPointer) => number; + + /** + * Within the `xUpdate` method of a virtual table, the + * `sqlite3_value_nochange(sqliteValue)` interface returns true if and only if + * the column corresponding to `sqliteValue` is unchanged by the `UPDATE` + * operation that the `xUpdate` method call was invoked to implement and if + * and the prior `xColumn` method call that was invoked to extracted the value + * for that column returned without setting a result (probably because it + * queried `sqlite3_vtab_nochange()` and found that the column was + * unchanging). + * + * C Signature: + * + * int sqlite3_value_nochange(sqlite3_value*); + * + * See https://www.sqlite.org/c3ref/value_blob.html + */ + sqlite3_value_nochange: (sqliteValue: WasmPointer) => number; + + /** + * Returns non-zero if the value `sqliteValue` originated from one of the + * `sqlite3_bind()` interfaces. If `sqliteValue` comes from an SQL literal + * value, or a table column, or an expression, then + * `sqlite3_value_frombind(sqliteValue)` returns zero. + * + * C Signature: + * + * int sqlite3_value_frombind(sqlite3_value*); + * + * See https://www.sqlite.org/c3ref/value_blob.html + */ + sqlite3_value_frombind: (sqliteValue: WasmPointer) => number; + + /** + * Returns the subtype for an application-defined SQL function argument + * `sqliteValue`. The subtype information can be used to pass a limited amount + * of context from one SQL function to another. Use the + * `sqlite3_result_subtype()` routine to set the subtype for the return value + * of an SQL function. + * + * C Signature: + * + * int sqlite3_value_subtype(sqlite3_value*); + * + * See https://www.sqlite.org/c3ref/value_subtype.html + */ + sqlite3_value_subtype: (sqliteValue: WasmPointer) => number; + + /** + * Makes a copy of the `sqlite3_value` object `sqliteValue` and returns a + * pointer to that copy. The `sqlite3_value` returned is a protected + * `sqlite3_value` object even if the input is not. If `sqliteValue is a + * pointer value, then the result is a NULL value. + * + * C Signature: + * + * sqlite3_value *sqlite3_value_dup(sqlite3_value*); + * + * See https://www.sqlite.org/c3ref/value_dup.html + */ + sqlite3_value_dup: (sqliteValue: WasmPointer) => WasmPointer; + + /** + * Frees an `sqlite3_value` object previously obtained from + * `sqlite3_value_dup()`. + * + * C Signature: + * + * void sqlite3_value_free(sqlite3_value*); + * + * See https://www.sqlite.org/c3ref/value_dup.html + */ + sqlite3_value_free: (sqliteValue: WasmPointer) => void; + + /** + * Implementations of aggregate SQL functions use this routine to allocate + * memory for storing their state. + * + * C Signature: + * + * void *sqlite3_aggregate_context(sqlite3_context*, int nBytes); + * + * See https://www.sqlite.org/c3ref/aggregate_context.html + */ sqlite3_aggregate_context: (ctx: WasmPointer, nBytes: number) => WasmPointer; - sqlite3_bind_double: ( - stmt: PreparedStatement | WasmPointer, - idx: number, - value: number, - ) => number; - sqlite3_bind_int: ( - stmt: PreparedStatement | WasmPointer, - idx: number, - value: number, - ) => number; - sqlite3_bind_null: ( - stmt: PreparedStatement | WasmPointer, - idx: number, - ) => number; - sqlite3_bind_parameter_count: ( - stmt: PreparedStatement | WasmPointer, - ) => number; - sqlite3_bind_parameter_index: ( - stmt: PreparedStatement | WasmPointer, - name: string | WasmPointer, - ) => number; - sqlite3_bind_pointer: ( - stmt: PreparedStatement | WasmPointer, - idx: number, + + /** + * A thin wrapper around `sqlite3_aggregate_context()` which behaves the same + * except that if that function returns 0 and `nBytes` is truthy, it throws a + * `WasmAllocError`. If `nBytes` is falsy, it simply returns 0 if that + * function returns 0. That behavior is intended to assist in developing + * `xFinal()` implementations. + * + * See + * https://sqlite.org/wasm/doc/trunk/api-c-style.md#sqlite3_js_aggregate_context + */ + sqlite3_js_aggregate_context: ( + ctx: WasmPointer, + nBytes: number, + ) => WasmPointer; + + /** + * Returns a copy of the pointer that was the `pUserData` parameter (the 5th + * parameter) of the `sqlite3_create_function()` routine that originally + * registered the application defined function. + * + * C Signature: + * + * void *sqlite3_user_data(sqlite3_context*); + * + * See https://www.sqlite.org/c3ref/user_data.html + */ + sqlite3_user_data: (ctx: WasmPointer) => WasmPointer; + + /** + * Returns a copy of the pointer to the database connection (the 1st + * parameter) of the `sqlite3_create_function()` routine that originally + * registered the application defined function. + * + * C Signature: + * + * sqlite3 *sqlite3_context_db_handle(sqlite3_context*); + * + * See https://www.sqlite.org/c3ref/context_db_handle.html + */ + sqlite3_context_db_handle: (ctx: WasmPointer) => WasmPointer; + + /** + * Returns a pointer to the metadata associated by the + * `sqlite3_set_auxdata(ctx, n , pAux, xDelete)` function with the `n`th + * argument value to the application-defined function. `n` is zero for the + * left-most function argument. + * + * C Signature: + * + * void *sqlite3_get_auxdata(sqlite3_context*, int N); + * + * See https://www.sqlite.org/c3ref/get_auxdata.html + */ + sqlite3_get_auxdata: (ctx: WasmPointer, n: number) => WasmPointer; + + /** + * Saves `pAux` as metadata for the `n`-th argument of the application-defined + * function. + * + * C Signature: + * + * void sqlite3_set_auxdata( + * sqlite3_context*, + * int N, + * void*, + * void (*)(void*) + * ); + * + * See https://www.sqlite.org/c3ref/get_auxdata.html + */ + sqlite3_set_auxdata: ( + ctx: WasmPointer, + n: number, + pAux: WasmPointer, + xDelete: (() => void) | WasmPointer, + ) => void; + + /** + * Sets the result from an application-defined function to be the `BLOB` whose + * content is pointed to by the second parameter and which is `blobLen` bytes + * long. + * + * C Signature: + * + * void sqlite3_result_blob( + * sqlite3_context*, + * const void*, + * int, + * void(*)(void*) + * ); + * + * See https://www.sqlite.org/c3ref/result_blob.html + */ + sqlite3_result_blob: ( + ctx: WasmPointer, + blob: WasmPointer, + blobLen: number, + dtor: + | (() => void) + | WasmPointer + | CAPI['SQLITE_STATIC'] + | CAPI['SQLITE_TRANSIENT'] + | CAPI['SQLITE_WASM_DEALLOC'], + ) => void; + + /** + * Sets the result from an application-defined function to be a floating point + * value specified by its 2nd argument. + * + * C Signature: + * + * void sqlite3_result_double(sqlite3_context*, double); + * + * See https://www.sqlite.org/c3ref/result_blob.html + */ + sqlite3_result_double: (ctx: WasmPointer, value: number) => void; + + /** + * Cause the implemented SQL function to throw an exception. + * + * SQLite uses the string pointed to by the 2nd parameter as the text of an + * error message. + * + * C Signature: + * + * void sqlite3_result_error(sqlite3_context*, const char*, int); + * + * See https://www.sqlite.org/c3ref/result_blob.html + */ + sqlite3_result_error: ( + ctx: WasmPointer, + msg: string | WasmPointer, + msgLen: number, + ) => void; + + /** + * Causes SQLite to throw an error indicating that a string or BLOB is too + * long to represent. + * + * C Signature: + * + * void sqlite3_result_error_toobig(sqlite3_context*); + * + * See https://www.sqlite.org/c3ref/result_blob.html + */ + sqlite3_result_error_toobig: (ctx: WasmPointer) => void; + + /** + * Causes SQLite to throw an + * + * - Error indicating that a memory allocation failed. + * + * C Signature: + * + * void sqlite3_result_error_nomem(sqlite3_context*); + * + * See https://www.sqlite.org/c3ref/result_blob.html + */ + sqlite3_result_error_nomem: (ctx: WasmPointer) => void; + + /** + * Changes the error code returned by SQLite as a result of an error in a + * function. By default, the error code is `SQLITE_ERROR`. A subsequent call + * to `sqlite3_result_error()` resets the error code to `SQLITE_ERROR`. + * + * C Signature: + * + * void sqlite3_result_error_code(sqlite3_context*, int); + * + * See https://www.sqlite.org/c3ref/result_blob.html + */ + sqlite3_result_error_code: (ctx: WasmPointer, code: number) => void; + + /** + * Calls either `sqlite3_result_error_nomem()`, if `err` is-a + * `WasmAllocError`, or `sqlite3_result_error()`. In the latter case, the + * second arugment is coerced to a string to create the error message. + * + * See + * https://sqlite.org/wasm/doc/trunk/api-c-style.md#sqlite3_result_error_js + */ + sqlite3_result_error_js: (ctx: WasmPointer, err: Error) => void; + + /** + * Sets the return value of the application-defined function to be the 32-bit + * signed integer value given in the 2nd argument. + * + * C Signature: + * + * void sqlite3_result_int(sqlite3_context*, int); + * + * See https://www.sqlite.org/c3ref/result_blob.html + */ + sqlite3_result_int: (ctx: WasmPointer, value: number) => void; + + /** + * Sets the return value of the application-defined function to be the 64-bit + * signed integer value given in the 2nd argument. + * + * C Signature: + * + * void sqlite3_result_int64(sqlite3_context*, sqlite3_int64); + * + * See https://www.sqlite.org/c3ref/result_blob.html + */ + sqlite3_result_int64: (ctx: WasmPointer, value: BigInt) => void; + + /** + * Sets the return value of the application-defined function to be `NULL`. + * + * C Signature: + * + * void sqlite3_result_null(sqlite3_context*); + * + * See https://www.sqlite.org/c3ref/result_blob.html + */ + sqlite3_result_null: (ctx: WasmPointer) => void; + + /** + * Set the return value of the application-defined function to be a text + * string + * + * C Signature: + * + * void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*)); + * + * See https://www.sqlite.org/c3ref/result_blob.html + */ + sqlite3_result_text: ( + ctx: WasmPointer, + text: string | WasmPointer, + textLen: number, + dtor: + | (() => void) + | WasmPointer + | CAPI['SQLITE_STATIC'] + | CAPI['SQLITE_TRANSIENT'] + | CAPI['SQLITE_WASM_DEALLOC'], + ) => void; + + /** + * Sets the result to an SQL `NULL` value, just like + * `sqlite3_result_null(ctx)`, except that it also associates the + * host-language pointer `value` or `type` with that `NULL` value such that + * the pointer can be retrieved within an application-defined SQL function + * using `sqlite3_value_pointer()`. + * + * C Signature: + * + * void sqlite3_result_pointer(sqlite3_context*, void*,const char*,void(*)(void*)); + * + * See https://www.sqlite.org/c3ref/result_blob.html + */ + sqlite3_result_pointer: ( + ctx: WasmPointer, value: WasmPointer, type: string | WasmPointer, dtor: @@ -3409,15 +4995,162 @@ declare type CAPI = { | CAPI['SQLITE_STATIC'] | CAPI['SQLITE_TRANSIENT'] | CAPI['SQLITE_WASM_DEALLOC'], + ) => void; + + /** + * Set the result of the application-defined function to be a `BLOB` + * containing all zero bytes and `blobLen` bytes in size. + * + * C Signature: + * + * void sqlite3_result_zeroblob(sqlite3_context*, int n); + * + * See https://www.sqlite.org/c3ref/result_blob.html + */ + sqlite3_result_zeroblob: (ctx: WasmPointer, blobLen: number) => void; + + /** + * Set the result of the application-defined function to be a `BLOB` + * containing all zero bytes and `blobLen` bytes in size. + * + * C Signature: + * + * void sqlite3_result_zeroblob(sqlite3_context*, int n); + * + * See https://www.sqlite.org/c3ref/result_blob.html + */ + sqlite3_result_zeroblob64: (ctx: WasmPointer, blobLen: BigInt) => void; + + /** + * Causes the subtype of the result from the application-defined SQL function + * with `sqlite3_context` `ctx` to be the value `subtype`. Only the lower 8 + * bits of the `subtype` are preserved in current versions of SQLite; higher + * order bits are discarded. + * + * C Signature: + * + * void sqlite3_result_subtype(sqlite3_context*,unsigned int); + * + * See https://www.sqlite.org/c3ref/result_subtype.html + */ + sqlite3_result_subtype: (ctx: WasmPointer, subtype: number) => void; + + /** + * This acts as a proxy for one of the other `sqlite3_result_...()` routines, + * depending on the type of its 2nd argument: + * + * - If `(val instanceof Error)`, this function passes it to + * `sqlite3_result_error_js()`. + * - `null`: `sqlite3_result_null()` + * - `boolean`: `sqlite3_result_int()` with a value of 0 or 1. `- `number`: + * `sqlite3_result_int()`, `sqlite3_result_int64()`, or + * `sqlite3_result_double()`, depending on the range of the number and + * whether or not `int64` support is enabled. + * - `BigInt`: similar to number but will trigger an error if the value is too + * big to store in an `int64`. + * - `string`: `sqlite3_result_text() + * - `Uint8Array` or `Int8Array`: `sqlite3_result_blob()` + * - `undefined`: is a no-op provided to simplify certain use cases. + * + * On error, it calls `sqlite3_result_error()` with a description of the + * problem. + * + * See https://sqlite.org/wasm/doc/trunk/api-c-style.md#sqlite3_result_js + */ + sqlite3_result_js: ( + ctx: WasmPointer, + val: + | Error + | null + | boolean + | number + | BigInt + | string + | Uint8Array + | Int8Array + | undefined, + ) => void; + + /** + * Add a collation to a database connection. + * + * C Signature: + * + * int sqlite3_create_collation( + * sqlite3*, + * const char *zName, + * int eTextRep, + * void *pArg, + * int(*xCompare)(void*,int,const void*,int,const void*) + * ); + * + * See https://www.sqlite.org/c3ref/create_collation.html + */ + sqlite3_create_collation: ( + db: Database | WasmPointer, + zName: string, + eTextRep: CAPI['SQLITE_UTF8'], + pArg: WasmPointer, + xCompare: + | (( + pCtx: WasmPointer, + len1: number, + p1: WasmPointer, + len2: number, + p2: WasmPointer, + ) => number) + | WasmPointer, ) => number; - sqlite3_busy_handler: ( + + /** + * Add a collation to a database connection. + * + * C Signature: + * + * int sqlite3_create_collation_v2( + * sqlite3*, + * const char *zName, + * int eTextRep, + * void *pArg, + * int(*xCompare)(void*,int,const void*,int,const void*), + * void(*xDestroy)(void*) + * ); + * + * See https://www.sqlite.org/c3ref/create_collation.html + */ + sqlite3_create_collation_v2: ( db: Database | WasmPointer, - callback: ((cbArg: WasmPointer, nTries: number) => number) | WasmPointer, - cbArg: WasmPointer, + zName: string, + eTextRep: CAPI['SQLITE_UTF8'], + pArg: WasmPointer, + xCompare: + | (( + pCtx: WasmPointer, + len1: number, + p1: WasmPointer, + len2: number, + p2: WasmPointer, + ) => number) + | WasmPointer, + xDestroy: ((pCtx: WasmPointer) => void) | WasmPointer, ) => number; - sqlite3_busy_timeout: (db: Database | WasmPointer, ms: number) => number; - sqlite3_changes: (db: Database | WasmPointer) => number; - sqlite3_clear_bindings: (db: Database | WasmPointer) => number; + + /** + * To avoid having to register all collation sequences before a database can + * be used, a single callback function may be registered with the database + * connection to be invoked whenever an undefined collation sequence is + * required. + * + * C Signature: + * + * int sqlite3_collation_needed( + * sqlite3*, + * void*, + * void(*)(void*,sqlite3*,int eTextRep,const char*) + * ); + * + * See https://www.sqlite.org/c3ref/collation_needed.html + */ sqlite3_collation_needed: ( db: Database | WasmPointer, cbArg: WasmPointer, @@ -3430,87 +5163,409 @@ declare type CAPI = { ) => void) | WasmPointer, ) => number; - sqlite3_column_blob: ( - stmt: PreparedStatement | WasmPointer, - colIdx: number, - ) => WasmPointer; - sqlite3_column_bytes: ( - stmt: PreparedStatement | WasmPointer, - colIdx: number, - ) => number; - sqlite3_column_count: (stmt: PreparedStatement | WasmPointer) => number; - sqlite3_column_double: ( - stmt: PreparedStatement | WasmPointer, - colIdx: number, - ) => number; - sqlite3_column_int: ( - stmt: PreparedStatement | WasmPointer, - colIdx: number, - ) => number; - sqlite3_column_name: ( - stmt: PreparedStatement | WasmPointer, - colIdx: number, - ) => string; - sqlite3_column_text: ( - stmt: PreparedStatement | WasmPointer, - colIdx: number, + + /** + * Returns the database connection handle to which a prepared statement + * belongs. The database connection returned by `sqlite3_db_handle` is the + * same database connection that was the first argument to the + * `sqlite3_prepare_v2()` call (or its variants) that was used to create the + * statement in the first place. + * + * C Signature: + * + * sqlite3 *sqlite3_db_handle(sqlite3_stmt*); + * + * See https://www.sqlite.org/c3ref/db_handle.html + */ + sqlite3_db_handle: (stmt: PreparedStatement | WasmPointer) => WasmPointer; + + /** + * Return The Schema Name For A Database Connection + * + * C Signature: + * + * const char *sqlite3_db_name(sqlite3 *db, const char *zDbName); + * + * See https://www.sqlite.org/c3ref/db_name.html + */ + sqlite3_db_name: (db: Database | WasmPointer, dbIdx: number) => string; + + /** + * Return The Filename For A Database Connection + * + * C Signature: + * + * sqlite3_filename sqlite3_db_filename(sqlite3 *db, const char *zDbName); + * + * See https://www.sqlite.org/c3ref/db_filename.html + */ + sqlite3_db_filename: ( + db: Database | WasmPointer, + dbName: string | WasmPointer, ) => string; - sqlite3_column_type: ( - stmt: PreparedStatement | WasmPointer, - colIdx: number, - ) => number; - sqlite3_column_value: ( - stmt: PreparedStatement | WasmPointer, - colIdx: number, - ) => WasmPointer; + /** + * Determine the transaction state of a database + * + * C Signature: + * + * int sqlite3_txn_state(sqlite3*,const char *zSchema); + * + * See https://www.sqlite.org/c3ref/txn_state.html + */ + sqlite3_txn_state: ( + db: Database | WasmPointer, + schema: string | WasmPointer, + ) => + | CAPI['SQLITE_TXN_NONE'] + | CAPI['SQLITE_TXN_READ'] + | CAPI['SQLITE_TXN_WRITE'] + | -1; + + /** + * Registers a callback function to be invoked whenever a transaction is + * committed. Any callback set by a previous call to `sqlite3_commit_hook()` + * for the same database connection is overridden. + * + * C Signature: + * + * void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*); + * + * See https://www.sqlite.org/c3ref/commit_hook.html + */ sqlite3_commit_hook: ( db: Database | WasmPointer, hook: ((cbArg: WasmPointer) => number) | WasmPointer, cbArg: WasmPointer, - ) => void; - sqlite3_compileoption_get: (idx: number) => string; - sqlite3_compileoption_used: (optName: string) => number; - sqlite3_complete: (sql: string | WasmPointer) => number; - sqlite3_context_db_handle: (ctx: WasmPointer) => WasmPointer; - sqlite3_data_count: (stmt: PreparedStatement | WasmPointer) => number; - sqlite3_db_filename: ( + ) => WasmPointer; + + /** + * The `sqlite3_rollback_hook()` interface registers a callback function to be + * invoked whenever a transaction is rolled back. Any callback set by a + * previous call to `sqlite3_rollback_hook()` for the same database connection + * is overridden. + * + * C Signature: + * + * void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); + * + * See https://www.sqlite.org/c3ref/commit_hook.html + */ + sqlite3_rollback_hook: ( + db: Database | WasmPointer, + hook: ((cbArg: WasmPointer) => number) | WasmPointer, + cbArg: WasmPointer, + ) => WasmPointer; + + /** + * Registers a callback function with the database connection identified by + * the first argument to be invoked whenever a row is updated, inserted or + * deleted in a rowid table. Any callback set by a previous call to this + * function for the same database connection is overridden. + * + * C Signature: + * + * void *sqlite3_update_hook( + * sqlite3*, + * void(*)(void *,int ,char const *,char const *,sqlite3_int64), + * void* + * ); + * + * See https://www.sqlite.org/c3ref/update_hook.html + */ + sqlite3_update_hook: ( + db: Database | WasmPointer, + xUpdate: ( + userCtx: WasmPointer, + op: CAPI['SQLITE_UPDATE'] | CAPI['SQLITE_DELETE'] | CAPI['SQLITE_INSERT'], + dbName: string, + tableName: string, + newRowId: BigInt, + ) => void, + userCtx: WasmPointer, + ) => WasmPointer; + + /** + * Returns information about column `colName` of table `tblName` in database + * `dbName` on database connection `db`. The `sqlite3_table_column_metadata()` + * interface returns `SQLITE_OK` and fills in the non-NULL pointers in the + * final five arguments with appropriate values if the specified column + * exists. The `sqlite3_table_column_metadata()` interface returns + * `SQLITE_ERROR` if the specified column does not exist. + * + * C Signature: + * + * int sqlite3_table_column_metadata( + * sqlite3 *db, + * const char *zDbName, + * const char *zTableName, + * const char *zColumnName, + * char const **pzDataType, + * char const **pzCollSeq, + * int *pNotNull, + * int *pPrimaryKey, + * int *pAutoinc + * ); + * + * See https://www.sqlite.org/c3ref/table_column_metadata.html + * + * @param db Connection handle + * @param dbname Database name or NULL + * @param tblName Table name + * @param colName Column name + * @param pDataType OUTPUT: Declared data type + * @param pCollSeq OUTPUT: Collation sequence name + * @param pNotNull OUTPUT: True if NOT NULL constraint exists + * @param pPrimaryKey OUTPUT: True if column part of PK + * @param pAutoinc OUTPUT: True if column is auto-increment + */ + sqlite3_table_column_metadata: ( + db: Database | WasmPointer, + dbName: string | WasmPointer, + tblName: string | WasmPointer, + colName: string | WasmPointer, + pDataType: WasmPointer, + pCollSeq: WasmPointer, + pNotNull: WasmPointer, + pPrimaryKey: WasmPointer, + pAutoinc: WasmPointer, + ) => number; + + /** + * Automatically Load Statically Linked Extensions + * + * Causes the `xEntryPoint()` function to be invoked for each new database + * connection that is created. The idea here is that `xEntryPoint()` is the + * entry point for a statically linked SQLite extension that is to be + * automatically loaded into all new database connections. + * + * Even though the function prototype shows that `xEntryPoint()` takes no + * arguments and returns `void`, SQLite invokes `xEntryPoint()` with three + * arguments and expects an integer result as if the signature of the entry + * point where as follows: + * + * int xEntryPoint( + * sqlite3 *db, + * const char **pzErrMsg, + * const struct sqlite3_api_routines *pThunk + * ); + * + * C Signature: + * + * int sqlite3_auto_extension(void(*xEntryPoint)(void)); + * + * See https://www.sqlite.org/c3ref/auto_extension.html + */ + sqlite3_auto_extension: ( + xEntryPoint: + | (( + db: Database | WasmPointer, + pzErrMsg: WasmPointer, + pThunk: WasmPointer, + ) => number) + | WasmPointer, + ) => number; + + /** + * Cancel Automatic Extension Loading + * + * Unregisters the initialization routine `xEntryPoint` that was registered + * using a prior call to `sqlite3_auto_extension(xEntryPoint)`. + * + * C Signature: + * + * int sqlite3_cancel_auto_extension(void(*xEntryPoint)(void)); + * + * See https://www.sqlite.org/c3ref/cancel_auto_extension.html + */ + sqlite3_cancel_auto_extension: (xEntryPoint: WasmPointer) => number; + + /** + * Reset Automatic Extension Loading + * + * Disables all automatic extensions previously registered using + * `sqlite3_auto_extension()`. + * + * C Signature: + * + * void sqlite3_reset_auto_extension(void); + * + * See https://www.sqlite.org/c3ref/reset_auto_extension.html + */ + sqlite3_reset_auto_extension: () => void; + + /** + * Register A Virtual Table Implementation + * + * Used to register a new virtual table module name. Module names must be + * registered before creating a new virtual table using the module and before + * using a preexisting virtual table for the module. + * + * C Signature: + * + * int sqlite3_create_module( + * sqlite3 *db, + * const char *zName, + * const sqlite3_module *p, + * void *pClientData + * ); + * + * See https://www.sqlite.org/c3ref/create_module.html + */ + sqlite3_create_module: ( + db: Database | WasmPointer, + name: string, + module: WasmPointer | sqlite3_module, + clientData: WasmPointer, + ) => number; + + /** + * Register A Virtual Table Implementation + * + * Used to register a new virtual table module name. Module names must be + * registered before creating a new virtual table using the module and before + * using a preexisting virtual table for the module. + * + * C Signature: + * + * int sqlite3_create_module_v2( + * sqlite3 *db, + * const char *zName, + * const sqlite3_module *p, + * void *pClientData, + * void(*xDestroy)(void*) + * ); + * + * See https://www.sqlite.org/c3ref/create_module.html + */ + sqlite3_create_module_v2: ( + db: Database | WasmPointer, + name: string, + module: WasmPointer | sqlite3_module, + clientData: WasmPointer, + destroy?: () => void, + ) => number; + + /** + * Remove Unnecessary Virtual Table Implementations + * + * Removes all virtual table modules from database connection `db` except + * those named on list `azKeep`. The `azKeepp` parameter must be either NULL + * or a pointer to an array of pointers to strings where the array is + * terminated by a single NULL pointer. If the `azKeep` parameter is NULL, + * then all virtual table modules are removed. + * + * C Signature: + * + * int sqlite3_drop_modules( + * sqlite3 *db, + * const char **azKeep + * ); + * + * See https://www.sqlite.org/c3ref/drop_modules.html + */ + sqlite3_drop_modules: ( db: Database | WasmPointer, - dbName: string | WasmPointer, - ) => string; - sqlite3_db_handle: (stmt: PreparedStatement | WasmPointer) => WasmPointer; - sqlite3_db_name: (db: Database | WasmPointer, dbIdx: number) => string; - sqlite3_db_status: ( + azKeep: WasmPointer, + ) => number; + + /** + * Declare The Schema Of A Virtual Table + * + * The `xCreate` and `xConnect` methods of a virtual table module call this + * interface to declare the format (the names and datatypes of the columns) of + * the virtual tables they implement. + * + * C Signature: + * + * int sqlite3_declare_vtab(sqlite3*, const char *zSQL); + * + * See https://www.sqlite.org/c3ref/declare_vtab.html + */ + sqlite3_declare_vtab: ( db: Database | WasmPointer, - op: - | CAPI['SQLITE_DBSTATUS_LOOKASIDE_USED'] - | CAPI['SQLITE_DBSTATUS_CACHE_USED'] - | CAPI['SQLITE_DBSTATUS_SCHEMA_USED'] - | CAPI['SQLITE_DBSTATUS_STMT_USED'] - | CAPI['SQLITE_DBSTATUS_LOOKASIDE_HIT'] - | CAPI['SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE'] - | CAPI['SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL'] - | CAPI['SQLITE_DBSTATUS_CACHE_HIT'] - | CAPI['SQLITE_DBSTATUS_CACHE_MISS'] - | CAPI['SQLITE_DBSTATUS_CACHE_WRITE'] - | CAPI['SQLITE_DBSTATUS_DEFERRED_FKS'] - | CAPI['SQLITE_DBSTATUS_CACHE_USED_SHARED'] - | CAPI['SQLITE_DBSTATUS_CACHE_SPILL'] - | CAPI['SQLITE_DBSTATUS_MAX'], - pCur: WasmPointer, - pHighWater: WasmPointer, - resetFlag: number, + sql: string | WasmPointer, ) => number; - sqlite3_errcode: (db: Database | WasmPointer) => number; - sqlite3_errmsg: (db: Database | WasmPointer) => string; - sqlite3_error_offset: (db: Database | WasmPointer) => number; - sqlite3_errstr: (rc: number) => string; - sqlite3_expanded_sql: (stmt: PreparedStatement | WasmPointer) => string; - sqlite3_extended_errcode: (db: Database | WasmPointer) => number; - sqlite3_extended_result_codes: ( + + /** + * Overload A Function For A Virtual Table + * + * Virtual tables can provide alternative implementations of functions using + * the `xFindFunction` method of the virtual table module. But global versions + * of those functions must exist in order to be overloaded. + * + * This API makes sure a global version of a function with a particular name + * and number of parameters exists. If no such function exists before this API + * is called, a new function is created. The implementation of the new + * function always causes an exception to be thrown. So the new function is + * not good for anything by itself. Its only purpose is to be a placeholder + * function that can be overloaded by a virtual table. + * + * C Signature: + * + * int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg); + * + * See https://www.sqlite.org/c3ref/overload_function.html + */ + sqlite3_overload_function: ( db: Database | WasmPointer, - onoff: number, + funcName: string, + nArgs: number, + ) => number; + + /** + * Returns a pointer to a VFS given its name. Names are case sensitive. + * + * C Signature: + * + * sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName); + * + * See https://www.sqlite.org/c3ref/vfs_find.html + */ + sqlite3_vfs_find: (vfsName: string) => sqlite3_vfs; + + /** + * Register a new VFS. Becomes the default if the makeDflt parameter is set. + * + * C Signature: + * + * int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt); + * + * See https://www.sqlite.org/c3ref/vfs_find.html + */ + sqlite3_vfs_register: ( + vfs: sqlite3_vfs | WasmPointer | string, + makeDflt: number, ) => number; + + /** + * Unregister a VFS. If it is the default, another VFS is chosen as the + * default. + * + * C Signature: + * + * int sqlite3_vfs_unregister(sqlite3_vfs*); + * + * See https://www.sqlite.org/c3ref/vfs_find.html + */ + sqlite3_vfs_unregister: (vfs: sqlite3_vfs | WasmPointer | string) => number; + + /** + * Low-Level Control Of Database Files + * + * Makes a direct call to the `xFileControl` method for the + * `sqlite3_io_methods` object associated with a particular database + * identified by the second argument. The name of the database is `"main"` for + * the main database or `"temp"` for the `TEMP` database, or the name that + * appears after the `AS` keyword for databases that are added using the + * `ATTACH` SQL command. + * + * C Signature: + * + * int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*); + * + * See https://www.sqlite.org/c3ref/file_control.html + */ sqlite3_file_control: ( db: Database | WasmPointer, dbName: string | WasmPointer, @@ -3555,118 +5610,64 @@ declare type CAPI = { | CAPI['SQLITE_FCNTL_RESERVE_BYTES'] | CAPI['SQLITE_FCNTL_CKPT_START'] | CAPI['SQLITE_FCNTL_EXTERNAL_READER'] - | CAPI['SQLITE_FCNTL_CKSM_FILE'] - | CAPI['SQLITE_FCNTL_RESET_CACHE'], + | CAPI['SQLITE_FCNTL_CKSM_FILE'], arg: WasmPointer, ) => number; - sqlite3_finalize: (stmt: PreparedStatement | WasmPointer) => number; - sqlite3_free: (ptr: WasmPointer) => void; - sqlite3_get_auxdata: (ctx: WasmPointer, n: number) => WasmPointer; - sqlite3_initialize: () => number; + + /** + * Returns the number of distinct keywords understood by SQLite. + * + * C Signature: + * + * int sqlite3_keyword_count(void); + * + * See https://www.sqlite.org/c3ref/keyword_count.html + */ sqlite3_keyword_count: () => number; + + /** + * Finds the `i`-th keyword and makes `*pOut` point to that keyword expressed + * as UTF8 and writes the number of bytes in the keyword into `*pOutLen`. The + * string that `*pOut` points to is not zero-terminated. The + * `sqlite3_keyword_name(i, pOut, pOutLen)` routine returns `SQLITE_OK` if + * `pOutLen` is within bounds and `SQLITE_ERROR` if not. If either`pOut` or + * `pOutLen` are `NULL` or invalid pointers then calls to + * `sqlite3_keyword_name(i, pOut, pOutLen)` result in undefined behavior. + * + * C Signature: + * + * int sqlite3_keyword_name(int i, const char **pOut, int *pOutLen); + * + * See https://www.sqlite.org/c3ref/keyword_count.html + */ sqlite3_keyword_name: ( i: number, pOut: WasmPointer, pOutLen: WasmPointer, ) => number; - sqlite3_keyword_check: (name: string | WasmPointer, n: number) => number; - sqlite3_libversion: () => string; - sqlite3_libversion_number: () => number; - sqlite3_limit: ( - db: Database | WasmPointer, - id: number, - newVal: number, - ) => number; - sqlite3_malloc: (size: number) => WasmPointer; - sqlite3_open: (filename: string | WasmPointer, ppDb: WasmPointer) => number; - sqlite3_open_v2: ( - filename: string | WasmPointer, - ppDb: WasmPointer, - flags: number, - vfs: string | WasmPointer, - ) => number; - sqlite3_progress_handler: ( - db: Database | WasmPointer, - nOps: number, - callback: ((cbArg: WasmPointer) => number) | WasmPointer, - cbArg: WasmPointer, - ) => void; - sqlite3_realloc: (ptr: WasmPointer, size: number) => WasmPointer; - sqlite3_reset: (stmt: PreparedStatement | WasmPointer) => number; - sqlite3_result_blob: ( - ctx: WasmPointer, - blob: WasmPointer, - blobLen: number, - dtor: - | (() => void) - | WasmPointer - | CAPI['SQLITE_STATIC'] - | CAPI['SQLITE_TRANSIENT'] - | CAPI['SQLITE_WASM_DEALLOC'], - ) => void; - sqlite3_result_double: (ctx: WasmPointer, value: number) => void; - sqlite3_result_error: ( - ctx: WasmPointer, - msg: string | WasmPointer, - msgLen: number, - ) => void; - sqlite3_result_error_code: (ctx: WasmPointer, code: number) => void; - sqlite3_result_error_nomem: (ctx: WasmPointer) => void; - sqlite3_result_error_toobig: (ctx: WasmPointer) => void; - sqlite3_result_int: (ctx: WasmPointer, value: number) => void; - sqlite3_result_null: (ctx: WasmPointer) => void; - sqlite3_result_pointer: ( - ctx: WasmPointer, - value: WasmPointer, - type: string | WasmPointer, - dtor: - | (() => void) - | WasmPointer - | CAPI['SQLITE_STATIC'] - | CAPI['SQLITE_TRANSIENT'] - | CAPI['SQLITE_WASM_DEALLOC'], - ) => void; - sqlite3_result_subtype: (ctx: WasmPointer, subtype: number) => void; - sqlite3_result_text: ( - ctx: WasmPointer, - text: string | WasmPointer, - textLen: number, - dtor: - | (() => void) - | WasmPointer - | CAPI['SQLITE_STATIC'] - | CAPI['SQLITE_TRANSIENT'] - | CAPI['SQLITE_WASM_DEALLOC'], - ) => void; - sqlite3_result_zeroblob: (ctx: WasmPointer, blobLen: number) => void; + /** + * Checks to see whether or not the `n`-byte UTF8 identifier that `name` + * points to is a keyword, returning non-zero if it is and zero if not. + * + * C Signature: + * + * int sqlite3_keyword_check(const char *zName, int nName); + * + * See https://www.sqlite.org/c3ref/keyword_count.html + */ + sqlite3_keyword_check: (name: string | WasmPointer, n: number) => number; - sqlite3_rollback_hook: ( - db: Database | WasmPointer, - hook: ((cbArg: WasmPointer) => number) | WasmPointer, - cbArg: WasmPointer, - ) => void; - sqlite3_set_authorizer: ( - db: Database | WasmPointer, - xAuth: ( - cbArg: WasmPointer, - actionCode: number, - arg1: string | 0, - arg2: string | 0, - arg3: string | 0, - arg4: string | 0, - ) => number, - cbArg: WasmPointer, - ) => number; - sqlite3_set_auxdata: ( - ctx: WasmPointer, - n: number, - pAux: WasmPointer, - xDelete: (() => void) | WasmPointer, - ) => void; - sqlite3_shutdown: () => number; - sqlite3_sourceid: () => string; - sqlite3_sql: (stmt: PreparedStatement | WasmPointer) => string; + /** + * Used to retrieve runtime status information about the performance of + * SQLite, and optionally to reset various highwater marks. + * + * C Signature: + * + * int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag); + * + * See https://www.sqlite.org/c3ref/status.html + */ sqlite3_status: ( op: | CAPI['SQLITE_STATUS_MEMORY_USED'] @@ -3679,9 +5680,83 @@ declare type CAPI = { pHighwater: WasmPointer, resetFlag: number, ) => number; - sqlite3_step: (stmt: PreparedStatement | WasmPointer) => number; - sqlite3_stmt_isexplain: (stmt: PreparedStatement | WasmPointer) => number; - sqlite3_stmt_readonly: (stmt: PreparedStatement | WasmPointer) => number; + + /** + * Used to retrieve runtime status information about the performance of + * SQLite, and optionally to reset various highwater marks. + * + * C Signature: + * + * int sqlite3_status( + * int op, + * sqlite3_int64 *pCurrent, + * sqlite3_int64 *pHighwater, + * int resetFlag + * ); + * + * See https://www.sqlite.org/c3ref/status.html + */ + sqlite3_status64: ( + op: + | CAPI['SQLITE_STATUS_MALLOC_COUNT'] + | CAPI['SQLITE_STATUS_MALLOC_SIZE'] + | CAPI['SQLITE_STATUS_PARSER_STACK'] + | CAPI['SQLITE_STATUS_PAGECACHE_USED'] + | CAPI['SQLITE_STATUS_PAGECACHE_OVERFLOW'] + | CAPI['SQLITE_STATUS_PAGECACHE_SIZE'] + | CAPI['SQLITE_STATUS_MEMORY_USED'], + pCurrent: WasmPointer, + pHighwater: WasmPointer, + resetFlag: number, + ) => number; + + /** + * Used to retrieve runtime status information about a single database + * connection. + * + * C Signature: + * + * int sqlite3_db_status( + * sqlite3*, + * int op, + * int *pCur, + * int *pHiwtr, + * int resetFlg + * ); + * + * See https://www.sqlite.org/c3ref/db_status.html + */ + sqlite3_db_status: ( + db: Database | WasmPointer, + op: + | CAPI['SQLITE_DBSTATUS_LOOKASIDE_USED'] + | CAPI['SQLITE_DBSTATUS_CACHE_USED'] + | CAPI['SQLITE_DBSTATUS_SCHEMA_USED'] + | CAPI['SQLITE_DBSTATUS_STMT_USED'] + | CAPI['SQLITE_DBSTATUS_LOOKASIDE_HIT'] + | CAPI['SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE'] + | CAPI['SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL'] + | CAPI['SQLITE_DBSTATUS_CACHE_HIT'] + | CAPI['SQLITE_DBSTATUS_CACHE_MISS'] + | CAPI['SQLITE_DBSTATUS_CACHE_WRITE'] + | CAPI['SQLITE_DBSTATUS_DEFERRED_FKS'] + | CAPI['SQLITE_DBSTATUS_CACHE_USED_SHARED'] + | CAPI['SQLITE_DBSTATUS_CACHE_SPILL'] + | CAPI['SQLITE_DBSTATUS_MAX'], + pCur: WasmPointer, + pHighWater: WasmPointer, + resetFlag: number, + ) => number; + + /** + * Retrieve and reset counter values from a prepared statement. + * + * C Signature: + * + * int sqlite3_stmt_status(sqlite3_stmt*, int op, int resetFlg); + * + * See https://www.sqlite.org/c3ref/stmt_status.html + */ sqlite3_stmt_status: ( stmt: PreparedStatement | WasmPointer, op: @@ -3696,138 +5771,259 @@ declare type CAPI = { | CAPI['SQLITE_STMTSTATUS_MEMUSED'], resetFlag: number, ) => number; - sqlite3_strglob: ( - glob: string | WasmPointer, - str: string | WasmPointer, - ) => number; + + /** + * Compare the contents of two buffers containing UTF-8 strings in a + * case-independent fashion, using the same definition of "case independence" + * that SQLite uses internally when comparing identifiers. + * + * C Signature: + * + * int sqlite3_stricmp(const char *, const char *); + * + * See https://www.sqlite.org/c3ref/stricmp.html + */ sqlite3_stricmp: ( str1: string | WasmPointer, str2: string | WasmPointer, ) => number; - sqlite3_strlike: ( - glob: string | WasmPointer, - str: string | WasmPointer, - esc: number, - ) => number; + + /** + * Compare the contents of two buffers containing UTF-8 strings in a + * case-independent fashion, using the same definition of "case independence" + * that SQLite uses internally when comparing identifiers. + * + * C Signature: + * + * int sqlite3_strnicmp(const char *, const char *, int); + * + * See https://www.sqlite.org/c3ref/stricmp.html + */ sqlite3_strnicmp: ( str1: string | WasmPointer, str2: string | WasmPointer, n: number, ) => number; - sqlite3_table_column_metadata: ( - db: Database | WasmPointer, - dbName: string | WasmPointer, - tblName: string | WasmPointer, - colName: string | WasmPointer, - pDataType: WasmPointer, - pCollSeq: WasmPointer, - pNotNull: WasmPointer, - pPrimaryKey: WasmPointer, - pAutoinc: WasmPointer, + + /** + * Returns zero if and only if string `str` matches the `GLOB` pattern `glob`. + * The definition of `GLOB` pattern matching used in `sqlite3_strglob(glob, + * str)` is the same as for the `str GLOB glob` operator in the SQL dialect + * understood by SQLite. The function is case sensitive. + * + * C Signature: + * + * int sqlite3_strglob(const char *zGlob, const char *zStr); + * + * See https://www.sqlite.org/c3ref/strglob.html + */ + sqlite3_strglob: ( + glob: string | WasmPointer, + str: string | WasmPointer, ) => number; - sqlite3_total_changes: (db: Database | WasmPointer) => number; - sqlite3_trace_v2: ( - db: Database | WasmPointer, - mask: number, - xCallback: ( - reason: - | CAPI['SQLITE_TRACE_CLOSE'] - | CAPI['SQLITE_TRACE_PROFILE'] - | CAPI['SQLITE_TRACE_ROW'] - | CAPI['SQLITE_TRACE_STMT'], - cbArg: WasmPointer, - arg1: WasmPointer, - arg2: WasmPointer, - ) => number, + + /** + * Returns zero if and only if string `str` matches the `LIKE` pattern + * `likePat` with escape character `esc`. The definition of `LIKE` pattern + * matching used in `sqlite3_strlike(like, str, esc)` is the same as for the + * `X LIKE P ESCAPE E` operator in the SQL dialect understood by SQLite. For + * `X LIKE P` without the `ESCAPE` clause, set the `esc` parameter to 0. As + * with the `LIKE` operator, the function is case insensitive. + * + * C Signature: + * + * int sqlite3_strlike(const char *zGlob, const char *zStr, unsigned int cEsc); + * + * See https://www.sqlite.org/c3ref/strlike.html + */ + sqlite3_strlike: ( + likePat: string | WasmPointer, + str: string | WasmPointer, + esc: number, ) => number; - sqlite3_txn_state: ( + + /** + * Determine The Virtual Table Conflict Policy + * + * This function may only be called from within a call to the `xUpdate` method + * of a virtual table implementation for an `INSERT` or `UPDATE` operation. + * The value returned is one of `SQLITE_ROLLBACK`, `SQLITE_IGNORE`, + * `SQLITE_FAIL`, `SQLITE_ABORT`, or `SQLITE_REPLACE`, according to the `ON + * CONFLICT` mode of the SQL statement that triggered the call to the + * `xUpdate` method of the virtual table. + * + * C Signature: + * + * int sqlite3_vtab_on_conflict(sqlite3*); + * + * See https://www.sqlite.org/c3ref/vtab_on_conflict.html + */ + sqlite3_vtab_on_conflict: ( db: Database | WasmPointer, - schema: string | WasmPointer, ) => - | CAPI['SQLITE_TXN_NONE'] - | CAPI['SQLITE_TXN_READ'] - | CAPI['SQLITE_TXN_WRITE'] - | -1; - sqlite3_uri_boolean: ( - uri: string | WasmPointer, - param: string | WasmPointer, - dflt: number, - ) => number; - sqlite3_uri_key: (uri: string | WasmPointer, idx: number) => string; - sqlite3_uri_parameter: ( - uri: string | WasmPointer, - param: string | WasmPointer, - ) => string; - sqlite3_user_data: (ctx: WasmPointer) => WasmPointer; + | CAPI['SQLITE_ROLLBACK'] + | CAPI['SQLITE_IGNORE'] + | CAPI['SQLITE_FAIL'] + | CAPI['SQLITE_ABORT'] + | CAPI['SQLITE_REPLACE']; - sqlite3_value_blob: (sqliteValue: WasmPointer) => WasmPointer; - sqlite3_value_bytes: (sqliteValue: WasmPointer) => number; - sqlite3_value_double: (sqliteValue: WasmPointer) => number; - sqlite3_value_dup: (sqliteValue: WasmPointer) => WasmPointer; - sqlite3_value_free: (sqliteValue: WasmPointer) => void; - sqlite3_value_frombind: (sqliteValue: WasmPointer) => number; - sqlite3_value_int: (sqliteValue: WasmPointer) => number; - sqlite3_value_nochange: (sqliteValue: WasmPointer) => number; - sqlite3_value_numeric_type: (sqliteValue: WasmPointer) => number; - sqlite3_value_pointer: ( - sqliteValue: WasmPointer, - type: string | WasmPointer, - ) => WasmPointer; - sqlite3_value_subtype: (sqliteValue: WasmPointer) => number; - sqlite3_value_text: (sqliteValue: WasmPointer) => string; - sqlite3_value_type: (sqliteValue: WasmPointer) => number; - sqlite3_value_int64: (sqliteValue: WasmPointer) => BigInt; + /** + * Determine If Virtual Table Column Access Is For `UPDATE` + * + * If the routine is called within the `xColumn` method of a virtual table, + * then it might return true if the column is being fetched as part of an + * `UPDATE` operation during which the column value will not change. The + * virtual table implementation can use this hint as permission to substitute + * a return value that is less expensive to compute and that the corresponding + * `xUpdate` method understands as a "no-change" value. + * + * C Signature: + * + * int sqlite3_vtab_nochange(sqlite3_context*); + * + * See https://www.sqlite.org/c3ref/vtab_nochange.html + */ + sqlite3_vtab_nochange: (ctx: WasmPointer) => number; - sqlite3_vfs_find: (vfsName: string) => sqlite3_vfs; - sqlite3_vfs_register: ( - vfs: sqlite3_vfs | WasmPointer | string, - makeDflt: number, - ) => number; - sqlite3_vfs_unregister: (vfs: sqlite3_vfs | WasmPointer | string) => number; - sqlite3_bind_int64: (stmt: WasmPointer, idx: number, value: BigInt) => number; - sqlite3_changes64: (db: Database | WasmPointer) => BigInt; - sqlite3_column_int64: (db: Database | WasmPointer, colIdx: number) => BigInt; - sqlite3_create_module: ( - db: Database | WasmPointer, - name: string, - module: WasmPointer | sqlite3_module, - clientData: WasmPointer, - ) => number; - sqlite3_create_module_v2: ( - db: Database | WasmPointer, - name: string, - module: WasmPointer | sqlite3_module, - clientData: WasmPointer, - destroy?: () => void, - ) => number; - sqlite3_declare_vtab: ( - db: Database | WasmPointer, - sql: string | WasmPointer, - ) => number; - sqlite3_deserialize: ( - db: Database | WasmPointer, - schema: string | WasmPointer, - data: WasmPointer, - dbSize: number, - bufferSize: number, - flags: number, + /** + * Determine The Collation For a Virtual Table Constraint + * + * This function may only be called from within a call to the `xBestIndex` + * method of a virtual table. This function returns a pointer to a string that + * is the name of the appropriate collation sequence to use for text + * comparisons on the constraint identified by its arguments. + * + * C Signature: + * + * const char *sqlite3_vtab_collation(sqlite3_index_info*, int); + * + * See https://www.sqlite.org/c3ref/vtab_collation.html + */ + sqlite3_vtab_collation: ( + indexInfo: sqlite3_index_info | WasmPointer, + constraintIdx: number, + ) => string; + + /** + * Determine if a virtual table query is DISTINCT + * + * This API may only be used from within an `xBestIndex method` of a virtual + * table implementation. The result of calling this interface from outside of + * `xBestIndex()` is undefined and probably harmful. + * + * C Signature: + * + * int sqlite3_vtab_distinct(sqlite3_index_info*); + * + * See https://www.sqlite.org/c3ref/vtab_distinct.html + */ + sqlite3_vtab_distinct: ( + indexInfo: sqlite3_index_info | WasmPointer, ) => number; - sqlite3_drop_modules: ( - db: Database | WasmPointer, - azKeep: WasmPointer, + + /** + * Identify and handle `IN` constraints in `xBestIndex`. + * + * This interface may only be used from within an `xBestIndex()` method of a + * virtual table implementation. The result of invoking this interface from + * any other context is undefined and probably harmful. + * + * C Signature: + * + * int sqlite3_vtab_in(sqlite3_index_info*, int iCons, int bHandle); + * + * See https://www.sqlite.org/c3ref/vtab_in.html + */ + sqlite3_vtab_in: ( + indexInfo: sqlite3_index_info | WasmPointer, + iCons: number, + bhandle: number, ) => number; - sqlite3_last_insert_rowid: (db: Database | WasmPointer) => BigInt; - sqlite3_malloc64: (numBytes: BigInt) => WasmPointer; - sqlite3_msize: (ptr: WasmPointer) => BigInt; - sqlite3_overload_function: ( - db: Database | WasmPointer, - funcName: string, - nArgs: number, + + /** + * Find all elements on the right-hand side of an IN constraint. + * + * On success, sets `ppOut` to point to the first value on the RHS of the IN + * constraint. + * + * This interface may only be used from within an `xBestIndex()` method of a + * virtual table implementation. The result of invoking this interface from + * any other context is undefined and probably harmful. + * + * C Signature: + * + * int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut); + * + * See https://www.sqlite.org/c3ref/vtab_in_first.html + */ + sqlite3_vtab_in_first: (sqlValue: WasmPointer, ppOut: WasmPointer) => number; + + /** + * Find all elements on the right-hand side of an IN constraint. + * + * On success, sets `ppOut` to point to the next value on the RHS of the IN + * constraint. + * + * This interface may only be used from within an `xBestIndex()` method of a + * virtual table implementation. The result of invoking this interface from + * any other context is undefined and probably harmful. + * + * C Signature: + * + * int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut); + * + * See https://www.sqlite.org/c3ref/vtab_in_first.html + */ + sqlite3_vtab_in_next: (sqlValue: WasmPointer, ppOut: WasmPointer) => number; + + /** + * Constraint values in `xBestIndex()` + * + * ^When the function is invoked from within the `xBestIndex` method of a + * virtual table implementation, with `indexInfo` being a copy of the + * `sqlite3_index_info` object pointer passed into `xBestIndex` and + * `constraintIdx` being a 0-based index into `indexInfo->aConstraint[]`, then + * this routine attempts to set `*ppOut` to the value of the right-hand + * operand of that constraint if the right-hand operand is known. + * + * This interface may only be used from within an `xBestIndex()` method of a + * virtual table implementation. The result of invoking this interface from + * any other context is undefined and probably harmful. + * + * C Signature: + * + * int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal); + * + * See https://www.sqlite.org/c3ref/vtab_rhs_value.html + */ + sqlite3_vtab_rhs_value: ( + indexInfo: sqlite3_index_info | WasmPointer, + constraintIdx: number, + ppOut: WasmPointer, ) => number; - sqlite3_preupdate_blobwrite: (db: Database | WasmPointer) => number; - sqlite3_preupdate_count: (db: Database | WasmPointer) => number; - sqlite3_preupdate_depth: (db: Database | WasmPointer) => number; + /** + * Registers a callback function hat is invoked prior to each `INSERT`, + * `UPDATE`, and `DELETE` operation on a database table. + * + * C Signature: + * + * void *sqlite3_preupdate_hook( + * sqlite3 *db, + * void(*xPreUpdate)( + * void *pCtx, + * sqlite3 *db, + * int op, + * char const *zDb, + * char const *zName, + * sqlite3_int64 iKey1, + * sqlite3_int64 iKey2 + * ), + * void* + * ); + * + * See https://www.sqlite.org/c3ref/preupdate_hook.html + */ sqlite3_preupdate_hook: ( db: Database | WasmPointer, xPreUpdate: ( @@ -3840,116 +6036,888 @@ declare type CAPI = { newRowid: BigInt, ) => void, ) => void; + + /** + * Writes into `sqlValue` a pointer to a protected `sqlite3_value` that + * contains the value of the `colIdx`th column of the table row before it is + * updated. The `colIdx` parameter must be between 0 and one less than the + * number of columns or the behavior will be undefined. This must only be used + * within `SQLITE_UPDATE` and `SQLITE_DELETE` preupdate callbacks; if it is + * used by an `SQLITE_INSERT` callback then the behavior is undefined. The + * `sqlite3_value` that `sqlValue` points to will be destroyed when the + * preupdate callback returns. + * + * C Signature: + * + * int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **); + * + * See https://www.sqlite.org/c3ref/preupdate_hook.html + */ + sqlite3_preupdate_old: ( + db: Database | WasmPointer, + colIdx: number, + sqlValue: WasmPointer, + ) => number; + + /** + * Thin wrapper around `sqlite3_preupdate_old()` , which fetch the + * `sqlite3_value*` from the column specified by the 2nd argument and then + * returns the result of passing it to `sqlite3_value_to_js()`. Throws on + * error, including when the underlying functions return non-0. + * + * See https://sqlite.org/wasm/doc/trunk/api-c-style.md#pre-update-ext + */ + sqlite3_preupdate_old_js: ( + db: Database | WasmPointer, + colIdx: number, + ) => SqlValue; + + /** + * Returns the number of columns in the row that is being inserted, updated, + * or deleted. + * + * C Signature: + * + * int sqlite3_preupdate_count(sqlite3 *); + * + * See https://www.sqlite.org/c3ref/preupdate_hook.html + */ + sqlite3_preupdate_count: (db: Database | WasmPointer) => number; + + /** + * Returns 0 if the preupdate callback was invoked as a result of a direct + * insert, update, or delete operation; or 1 for inserts, updates, or deletes + * invoked by top-level triggers; or 2 for changes resulting from triggers + * called by top-level triggers; and so forth. + * + * C Signature: + * + * int sqlite3_preupdate_depth(sqlite3 *); + * + * See https://www.sqlite.org/c3ref/preupdate_hook.html + */ + sqlite3_preupdate_depth: (db: Database | WasmPointer) => number; + + /** + * Writes into `sqlValue` a pointer to a protected `sqlite3_value` that + * contains the value of the `colIdx`th column of the table row after it is + * updated. The `colidx` parameter must be between 0 and one less than the + * number of columns or the behavior will be undefined. This must only be used + * within `SQLITE_INSERT` and `SQLITE_UPDATE` preupdate callbacks; if it is + * used by an `SQLITE_DELETE` callback then the behavior is undefined. The + * `sqlite3_value` that `sqlValue` points to will be destroyed when the + * preupdate callback returns. + * + * C Signature: + * + * int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **); + * + * See https://www.sqlite.org/c3ref/preupdate_hook.html + */ sqlite3_preupdate_new: ( db: Database | WasmPointer, colIdx: number, sqlValues: WasmPointer, ) => number; - sqlite3_preupdate_old: ( + + /** + * Thin wrapper around `sqlite3_preupdate_new()` , which fetch the + * `sqlite3_value*` from the column specified by the 2nd argument and then + * returns the result of passing it to `sqlite3_value_to_js()`. Throws on + * error, including when the underlying functions return non-0. + * + * See https://sqlite.org/wasm/doc/trunk/api-c-style.md#pre-update-ext + */ + sqlite3_preupdate_new_js: ( db: Database | WasmPointer, colIdx: number, - sqlValues: WasmPointer, - ) => number; + ) => SqlValue; - sqlite3_realloc64: (ptr: WasmPointer, numBytes: BigInt) => WasmPointer; - sqlite3_result_int64: (ctx: WasmPointer, value: BigInt) => void; - sqlite3_result_zeroblob64: (ctx: WasmPointer, blobLen: BigInt) => void; + /** + * When the `sqlite3_blob_write()` API is used to update a blob column, the + * pre-update hook is invoked with `SQLITE_DELETE`. This is because the in + * this case the new values are not available. In this case, when a callback + * made with `op==SQLITE_DELETE` is actually a write using the + * `sqlite3_blob_write()` API, the `sqlite3_preupdate_blobwrite()` returns the + * index of the column being written. In other cases, where the pre-update + * hook is being invoked for some other reason, including a regular `DELETE`, + * `sqlite3_preupdate_blobwrite()` returns -1. + * + * C Signature: + * + * int sqlite3_preupdate_blobwrite(sqlite3 *); + * + * See https://www.sqlite.org/c3ref/preupdate_hook.html + */ + sqlite3_preupdate_blobwrite: (db: Database | WasmPointer) => number; + + /** + * Returns a pointer to memory that is a serialization of the `schema` + * database on database connection `db`. If `piSize` is not a NULL pointer, + * then the size of the database in bytes is written into `*piSize`. + * + * For an ordinary on-disk database file, the serialization is just a copy of + * the disk file. For an in-memory database or a `"TEMP"` database, the + * serialization is the same sequence of bytes which would be written to disk + * if that database where backed up to disk. + * + * C Signature: + * + * unsigned char *sqlite3_serialize( + * sqlite3 *db, + * const char *zSchema, + * sqlite3_int64 *piSize, + * unsigned int mFlags + * ); + * + * See https://www.sqlite.org/c3ref/serialize.html + */ sqlite3_serialize: ( db: Database | WasmPointer, schema: string | WasmPointer, piSize: WasmPointer, - flags: number, + flags: 0 | CAPI['SQLITE_SERIALIZE_NOCOPY'], ) => WasmPointer; - sqlite3_set_last_insert_rowid: ( + + /** + * Causes the database connection `db` to disconnect from database `schema` + * and then reopen `schema` as an in-memory database based on the + * serialization contained in `data`. The serialized database `data` is + * `dbSize` bytes in size. `bufferSize` is the size of the buffer `data`, + * which might be larger than `dbSize`. If `bufferSize` is larger than + * `dbSize`, and the `SQLITE_DESERIALIZE_READONLY` bit is not set in `flags`, + * then SQLite is permitted to add content to the in-memory database as long + * as the total size does not exceed `bufferSize` bytes. + * + * **ACHTUNG:** There are severe caveats regarding memory allocations when + * using this function in JavaScript. See + * https://sqlite.org/wasm/doc/trunk/api-c-style.md#sqlite3_deserialize for + * more details + * + * C Signature: + * + * int sqlite3_deserialize( + * sqlite3 *db, + * const char *zSchema, + * unsigned char *pData, + * sqlite3_int64 szDb, + * sqlite3_int64 szBuf, + * unsigned mFlags + * ); + * + * See https://www.sqlite.org/c3ref/deserialize.html + */ + sqlite3_deserialize: ( db: Database | WasmPointer, - rowid: BigInt, - ) => void; - sqlite3_status64: ( - op: - | CAPI['SQLITE_STATUS_MALLOC_COUNT'] - | CAPI['SQLITE_STATUS_MALLOC_SIZE'] - | CAPI['SQLITE_STATUS_PARSER_STACK'] - | CAPI['SQLITE_STATUS_PAGECACHE_USED'] - | CAPI['SQLITE_STATUS_PAGECACHE_OVERFLOW'] - | CAPI['SQLITE_STATUS_PAGECACHE_SIZE'] - | CAPI['SQLITE_STATUS_MEMORY_USED'], - pCurrent: WasmPointer, - pHighwater: WasmPointer, - resetFlag: number, + schema: string | WasmPointer, + data: WasmPointer, + dbSize: number, + bufferSize: number, + flags: number, ) => number; - sqlite3_total_changes64: (db: Database | WasmPointer) => BigInt; - sqlite3_update_hook: ( + + /** + * Create a new session object attached to database handle `db`. If + * successful, a pointer to the new object is written to `*ppSession` and + * `SQLITE_OK` is returned. If an error occurs, `*ppSession` is set to NULL + * and an SQLite error code (e.g. `SQLITE_NOMEM`) is returned. + * + * C Signature: + * + * int sqlite3session_create( + * sqlite3 *db, + * const char *zDb, + * sqlite3_session **ppSession + * ); + * + * See https://www.sqlite.org/session/sqlite3session_create.html + */ + sqlite3session_create: ( db: Database | WasmPointer, - xUpdate: ( - userCtx: WasmPointer, - op: CAPI['SQLITE_UPDATE'] | CAPI['SQLITE_DELETE'] | CAPI['SQLITE_INSERT'], - dbName: string, - tableName: string, - newRowId: BigInt, - ) => void, - userCtx: WasmPointer, + dbName: string, + ppSession: WasmPointer, + ) => number; + + /** + * Delete a session object previously allocated using + * `sqlite3session_create()`. Once a session object has been deleted, the + * results of attempting to use `pSession` with any other session module + * function are undefined. + * + * C Signature: + * + * void sqlite3session_delete(sqlite3_session * pSession); + * + * See https://www.sqlite.org/session/sqlite3session_delete.html + */ + sqlite3session_delete: (pSession: WasmPointer) => number; + + /** + * This method is used to configure a session object after it has been + * created. At present the only valid values for the second parameter are + * `SQLITE_SESSION_OBJCONFIG_SIZE` and `SQLITE_SESSION_OBJCONFIG_ROWID`. + * + * C Signature: + * + * int sqlite3session_object_config(sqlite3_session*, int op, void *pArg); + * + * See https://www.sqlite.org/session/sqlite3session_object_config.html + */ + sqlite3session_object_config: (pSession: WasmPointer, op: number) => number; + + /** + * Enable or disable the recording of changes by a session object. When + * enabled, a session object records changes made to the database. When + * disabled - it does not. A newly created session object is enabled. + * + * C Signature: + * + * int sqlite3session_enable(sqlite3_session *pSession, int bEnable); + * + * See https://www.sqlite.org/session/sqlite3session_enable.html + */ + sqlite3session_enable: (pSession: WasmPointer, bEnable: number) => number; + + /** + * Set Or Clear the Indirect Change Flag + * + * Each change recorded by a session object is marked as either direct or + * indirect. A change is marked as indirect if either: + * + * - The session object "indirect" flag is set when the change is made, or + * - The change is made by an SQL trigger or foreign key action instead of + * directly as a result of a users SQL statement. + * + * If a single row is affected by more than one operation within a session, + * then the change is considered indirect if all operations meet the criteria + * for an indirect change above, or direct otherwise. + * + * This function is used to set, clear or query the session object indirect + * flag. If the second argument passed to this function is zero, then the + * indirect flag is cleared. If it is greater than zero, the indirect flag is + * set. Passing a value less than zero does not modify the current value of + * the indirect flag, and may be used to query the current state of the + * indirect flag for the specified session object. + * + * C Signature: + * + * int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect); + * + * See https://www.sqlite.org/session/sqlite3session_indirect.html + */ + sqlite3session_indirect: (pSession: WasmPointer, bIndirect: number) => number; + + /** + * Attach A Table To A Session Object + * + * If argument `tableName` is not NULL, then it is the name of a table to + * attach to the session object passed as the first argument. All subsequent + * changes made to the table while the session object is enabled will be + * recorded. See documentation for `sqlite3session_changeset()` for further + * details. + * + * C Signature: + * + * int sqlite3session_attach( + * sqlite3_session *pSession, + * const char *zTab + * ); + * + * See https://www.sqlite.org/session/sqlite3session_attach.html + */ + sqlite3session_attach: (pSession: WasmPointer, tableName: string) => number; + + /** + * Set a table filter on a Session Object. + * + * The second argument `xFilter` is the "filter callback". For changes to rows + * in tables that are not attached to the Session object, the filter is called + * to determine whether changes to the table's rows should be tracked or not. + * If `xFilter` returns 0, changes are not tracked. Note that once a table is + * attached, `xFilter` will not be called again. + * + * C Signature: + * + * int sqlite3session_table_filter( + * sqlite3_session *pSession, + * int(*xFilter)(void *pCtx, const char *zTab), + * void *pCtx + * ); + * + * See https://www.sqlite.org/session/sqlite3session_table_filter.html + */ + sqlite3session_table_filter: ( + pSession: WasmPointer, + xFilter: ((pCtx: WasmPointer, tableName: string) => number) | WasmPointer, + pCtx: WasmPointer, ) => void; - sqlite3_uri_int64: ( - uri: string | WasmPointer, - paramName: string | WasmPointer, - defaultVal: BigInt, - ) => BigInt; - sqlite3_vtab_collation: ( - indexInfo: sqlite3_index_info | WasmPointer, - constraintidx: number, - ) => string; - sqlite3_vtab_distinct: ( - indexInfo: sqlite3_index_info | WasmPointer, + /** + * Generate A Changeset From A Session Object + * + * Obtain a changeset containing changes to the tables attached to the session + * object passed as the first argument. If successful, set `*ppChangeset` to + * point to a buffer containing the changeset and `*pnChangeset` to the size + * of the changeset in bytes before returning `SQLITE_OK`. If an error occurs, + * set both `*ppChangeset` and `*pnChangeset` to zero and return an SQLite + * error code. + * + * C Signature: + * + * int sqlite3session_changeset( + * sqlite3_session *pSession, + * int *pnChangeset, + * void **ppChangeset + * ); + * + * See https://www.sqlite.org/session/sqlite3session_changeset.html + */ + sqlite3session_changeset: ( + pSession: WasmPointer, + pnChangeset: WasmPointer, + ppChangeset: WasmPointer, + ) => number; + + /** + * Return An Upper-limit For The Size Of The Changeset. + * + * By default, this function always returns 0. For it to return a useful + * result, the `sqlite3_session` object must have been configured to enable + * this API using `sqlite3session_object_config()` with the + * `SQLITE_SESSION_OBJCONFIG_SIZE` verb. + * + * C Signature: + * + * int sqlite3session_changeset_size(sqlite3_session *pSession); + * + * See https://www.sqlite.org/session/sqlite3session_changeset_size.html + */ + sqlite3session_changeset_size: (pSession: WasmPointer) => number; + + /** + * Load The Difference Between Tables Into A Session + * + * If it is not already attached to the session object passed as the first + * argument, this function attaches table `zTbl` in the same manner as the + * `sqlite3session_attach()` function. If `zTbl` does not exist, or if it does + * not have a primary key, this function is a no-op (but does not return an + * error). + * + * C Signature: + * + * int sqlite3session_diff( + * sqlite3_session *pSession, + * const char *zFromDb, + * const char *zTbl + * char **pzErrMsg + * ); + * + * See https://www.sqlite.org/session/sqlite3session_diff.html + */ + sqlite3session_diff: ( + pSession: WasmPointer, + fromDb: string, + tableName: string, + pzErrMsg: WasmPointer, + ) => number; + + /** + * Generate A Patchset From A Session Object + * + * The differences between a patchset and a changeset are that: + * + * - `DELETE` records consist of the primary key fields only. The original + * values of other fields are omitted. + * - The original values of any modified fields are omitted from `UPDATE` + * records. + * + * A patchset blob may be used with up to date versions of all + * `sqlite3changeset_xxx` API functions except for + * `sqlite3changeset_invert()`, which returns `SQLITE_CORRUPT` if it is passed + * a patchset. Similarly, attempting to use a patchset blob with old versions + * of the `sqlite3changeset_xxx` APIs also provokes an `SQLITE_CORRUPT` + * error. + * + * C Signature: + * + * int sqlite3session_patchset( + * sqlite3_session *pSession, + * int *pnPatchset, + * void **ppPatchset + * ); + * + * See https://www.sqlite.org/session/sqlite3session_patchset.html + */ + sqlite3session_patchset: ( + pSession: WasmPointer, + pnPatchset: WasmPointer, + ppPatchset: WasmPointer, + ) => number; + + /** + * Test if a changeset has recorded any changes. + * + * Return non-zero if no changes to attached tables have been recorded by the + * session object passed as the first argument. Otherwise, if one or more + * changes have been recorded, return zero. + * + * C Signature: + * + * int sqlite3session_isempty(sqlite3_session *pSession); + * + * See https://www.sqlite.org/session/sqlite3session_isempty.html + */ + sqlite3session_isempty: (pSession: WasmPointer) => number; + + /** + * Query for the amount of heap memory used by a session object. + * + * This API returns the total amount of heap memory in bytes currently used by + * the session object passed as the only argument. + * + * C Signature: + * + * int sqlite3session_memory_used(sqlite3_session *); + * + * See https://www.sqlite.org/session/sqlite3session_memory_used.html + */ + sqlite3session_memory_used: (pSession: WasmPointer) => number; + + /** + * Create an iterator used to iterate through the contents of a changeset. If + * successful, `*ppIter` is set to point to the iterator handle and + * `SQLITE_OK` is returned. Otherwise, if an error occurs, `*ppIter` is set to + * zero and an SQLite error code is returned. + * + * C Signature: + * + * int sqlite3changeset_start( + * sqlite3_changeset_iter **ppIter, + * int nChangeset, + * void *pChangeset + * ); + * + * See https://www.sqlite.org/c3ref/changeset_start.html + * + * @param ppIter OUT: new changeset iterator handle + * @param nChangeSet Size of changeset blob in bytes + * @param pChangeset Pointer to blob containing changeset + */ + sqlite3changeset_start: ( + ppIter: WasmPointer, + nChangeset: number, + pChangeset: WasmPointer, + ) => number; + + /** + * Create an iterator used to iterate through the contents of a changeset. If + * successful, `*ppIter` is set to point to the iterator handle and + * `SQLITE_OK` is returned. Otherwise, if an error occurs, `*ppIter` is set to + * zero and an SQLite error code is returned. + * + * C Signature: + * + * int sqlite3changeset_start_v2( + * sqlite3_changeset_iter **ppIter, + * int nChangeset, + * void *pChangeset, + * int flags + * ); + * + * See https://www.sqlite.org/c3ref/changeset_start.html + * + * @param ppIter OUT: new changeset iterator handle + * @param nChangeSet Size of changeset blob in bytes + * @param pChangeset Pointer to blob containing changeset + * @param flags `SESSION_CHANGESTART_*` flags + */ + sqlite3changeset_start_v2: ( + ppIter: WasmPointer, + nChangeset: number, + pChangeset: WasmPointer, + flags: number, + ) => number; + + /** + * Advance A Changeset Iterator + * + * This function may only be used with iterators created by the function + * `sqlite3changeset_start()`. If it is called on an iterator passed to a + * conflict-handler callback by `sqlite3changeset_apply()`, `SQLITE_MISUSE` is + * returned and the call has no effect. + * + * C Signature: + * + * int sqlite3changeset_next(sqlite3_changeset_iter *pIter); + * + * See https://www.sqlite.org/c3ref/changeset_next.html + */ + sqlite3changeset_next: (pIter: WasmPointer) => number; + + /** + * Obtain The Current Operation From A Changeset Iterator + * + * C Signature: + * + * int sqlite3changeset_op( + * sqlite3_changeset_iter *pIter, + * const char **pzTab, + * int *pnCol, + * int *pOp, + * int *pbIndirect + * ); + * + * @param pIter Iterator object + * @param pzTab OUT: Pointer to table name + * @param pnCol OUT: Pointer to number of columns in table + * @param pOp OUT: Pointer to operation code (SQLITE_INSERT, SQLITE_DELETE or + * SQLITE_UPDATE) + * @param pbIndirect OUT: True for an 'indirect' change + */ + sqlite3changeset_op: ( + pIter: WasmPointer, + pzTab: WasmPointer, + pnCol: WasmPointer, + pOp: WasmPointer, + pbIndirect: WasmPointer, + ) => number; + + /** + * Obtain The Primary Key Definition Of A Table + * + * For each modified table, a changeset includes the following: + * + * - The number of columns in the table, and + * - Which of those columns make up the tables `PRIMARY KEY`. + * + * This function is used to find which columns comprise the `PRIMARY KEY` of + * the table modified by the change that iterator pIter currently points to. + * + * C Signature: + * + * int sqlite3changeset_pk( + * sqlite3_changeset_iter *pIter, + * const char **pabPK, + * int *pnCol + * ); + * + * See https://www.sqlite.org/c3ref/changeset_pk.html + * + * @param pIter Iterator object + * @param pabPK Array of boolean - true for PK cols + * @param pnCol Number of entries in output array + */ + sqlite3changeset_pk: ( + pIter: WasmPointer, + pabPK: WasmPointer, + pnCol: WasmPointer, + ) => number; + + /** + * Obtain old.* Values From A Changeset Iterator + * + * C Signature: + * + * int sqlite3changeset_old( + * sqlite3_changeset_iter *pIter, + * int iVal, + * sqlite3_value **ppValue + * ); + * + * See https://www.sqlite.org/c3ref/changeset_old.html + * + * @param pIter Changeset iterator + * @param colNum Column number + * @param ppValue OUT: Old value (or NULL pointer) + */ + sqlite3changeset_old: ( + pIter: WasmPointer, + colNum: number, + ppValue: WasmPointer, + ) => number; + + /** + * Thin wrapper around `sqlite3changeset_old()`, which fetches the + * `sqlite3_value*` from the column specified by the 2nd argument and then + * return the result of passing it to `sqlite3_value_to_js()`. Throws on + * error, including when the underlying function returns non-0. + * + * See https://sqlite.org/wasm/doc/trunk/api-c-style.md#session-api-ext + */ + sqlite3changeset_old_js: ( + pChangeSetIter: WasmPointer, + colIdx: number, + ) => SqlValue; + + /** + * Obtain new.* Values From A Changeset Iterator + * + * C Signature: + * + * int sqlite3changeset_new( + * sqlite3_changeset_iter *pIter, + * int iVal, + * sqlite3_value **ppValue + * ); + * + * See https://www.sqlite.org/c3ref/changeset_new.html + * + * @param pIter Changeset iterator + * @param colNum Column number + * @param ppValue OUT: New value (or NULL pointer) + */ + sqlite3changeset_new: ( + pIter: WasmPointer, + colNum: number, + ppValue: WasmPointer, ) => number; - sqlite3_vtab_in: ( - indexInfo: sqlite3_index_info | WasmPointer, - iCons: number, - bhandle: number, + + /** + * Thin wrapper around `sqlite3changeset_new()`, which fetches the + * `sqlite3_value*` from the column specified by the 2nd argument and then + * return the result of passing it to `sqlite3_value_to_js()`. Throws on + * error, including when the underlying function returns non-0. If + * `sqlite3changeset_new()` returns 0 but sets the output value to NULL, this + * function returns the undefined value, which is never a valid conversion + * from an `sqlite3_value`, so is unambiguous. + * + * See https://sqlite.org/wasm/doc/trunk/api-c-style.md#session-api-ext + */ + sqlite3changeset_new_js: ( + pChangeSetIter: WasmPointer, + colIdx: number, + ) => SqlValue | undefined; + + /** + * Obtain Conflicting Row Values From A Changeset Iterator + * + * C Signature: + * + * int sqlite3changeset_conflict( + * sqlite3_changeset_iter *pIter, + * int iVal, + * sqlite3_value **ppValue + * ); + * + * See https://www.sqlite.org/c3ref/changeset_conflict.html + * + * @param pIter Changeset iterator + * @param colNum Column number + * @param ppValue OUT: Value from conflicting row + */ + sqlite3changeset_conflict: ( + pIter: WasmPointer, + colNum: number, + ppValue: WasmPointer, ) => number; - sqlite3_vtab_in_first: ( - sqlValue: WasmPointer, - outValues: WasmPointer, + + /** + * Determine The Number Of Foreign Key Constraint Violations + * + * C Signature: + * + * int sqlite3changeset_fk_conflicts( + * sqlite3_changeset_iter *pIter, + * int *pnOut + * ); + * + * See https://www.sqlite.org/c3ref/changeset_fk_conflicts.html + * + * @param pIter Changeset iterator + * @param pnOut OUT: Number of FK constraint violations + */ + sqlite3changeset_fk_conflicts: ( + pIter: WasmPointer, + pnOut: WasmPointer, ) => number; - sqlite3_vtab_in_next: ( - sqlValue: WasmPointer, - outValues: WasmPointer, + + /** + * This function is used to finalize an iterator allocated with + * `sqlite3changeset_start()`. + * + * C Signature: + * + * int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter); + * + * See https://www.sqlite.org/c3ref/changeset_finalize.html + */ + sqlite3changeset_finalize: (pIter: WasmPointer) => number; + + /** + * This function is used to "invert" a changeset object. Applying an inverted + * changeset to a database reverses the effects of applying the uninverted + * changeset. Specifically: + * + * - Each `DELETE` change is changed to an `INSERT`, and + * - Each `INSERT` change is changed to a `DELETE`, and + * - For each `UPDATE` change, the `old.*` and `new.*` values are exchanged. + * + * This function does not change the order in which changes appear within the + * changeset. It merely reverses the sense of each individual change. + * + * If successful, a pointer to a buffer containing the inverted changeset is + * stored in `*ppOut`, the size of the same buffer is stored in `*pnOut`, and + * `SQLITE_OK` is returned. If an error occurs, both `*pnOut` and `*ppOut` are + * zeroed and an SQLite error code returned. + * + * C Signature: + * + * int sqlite3changeset_invert( + * int nIn, + * void *pIn, + * int *pnOut, + * void **ppOut + * ); + * + * See https://www.sqlite.org/c3ref/changeset_invert.html + * + * @param nIn Size of input changeset blob in bytes + * @param pIn Pointer to input changeset blob + * @param pnOut OUT: Size of output changeset blob in bytes + * @param ppOut OUT: Pointer to output changeset blob + */ + sqlite3changeset_invert: ( + nIn: number, + pIn: WasmPointer, + pnOut: WasmPointer, + ppOut: WasmPointer, ) => number; - sqlite3_vtab_nochange: (ctx: WasmPointer) => number; - sqlite3_vtab_on_conflict: (db: Database | WasmPointer) => number; - sqlite3_vtab_rhs_value: ( - indexInfo: sqlite3_index_info | WasmPointer, - constraintIdx: number, - outValues: WasmPointer, + + /** + * Concatenate Two Changeset Objects + * + * This function is used to concatenate two changesets, A and B, into a single + * changeset. The result is a changeset equivalent to applying changeset A + * followed by changeset B. * This function combines the two input changesets + * using an `sqlite3_changegroup` object. + * + * C Signature: + * + * int sqlite3changeset_concat( + * int nA, + * void *pA, + * int nB, + * void *pB, + * int *pnOut, + * void **ppOut + * ); + * + * See https://www.sqlite.org/c3ref/changeset_concat.html + * + * @param nA Number of bytes in buffer pA + * @param pA Pointer to buffer containing changeset A + * @param nB Number of bytes in buffer pB + * @param pB Pointer to buffer containing changeset B + * @param pnOut OUT: Size of output changeset blob in bytes + * @param ppOut OUT: Pointer to output changeset blob + */ + sqlite3changeset_concat: ( + nA: number, + pA: WasmPointer, + nB: number, + pB: WasmPointer, + pnOut: WasmPointer, + ppOut: WasmPointer, ) => number; + /** + * Create A New Changegroup Object + * + * C Signature: + * + * int sqlite3changegroup_new(sqlite3_changegroup **ppOut); + * + * See https://www.sqlite.org/c3ref/changegroup_new.html + */ + sqlite3changegroup_new: (ppOut: WasmPointer) => number; + + /** + * Add all changes within the changeset (or patchset) in buffer `pData` (size + * `nData` bytes) to the changegroup. + * + * C Signature: + * + * int sqlite3changegroup_add( + * sqlite3_changegroup *p, + * int nData, + * void *pData + * ); + * + * See https://www.sqlite.org/c3ref/changegroup_add.html + */ sqlite3changegroup_add: ( changeGrp: WasmPointer, nData: number, - data: WasmPointer, - ) => number; - sqlite3changegroup_add_strm: ( - changeGrp: WasmPointer, - xInput: ( - pIn: WasmPointer, - pData: WasmPointer, - pnData: WasmPointer, - ) => number, - pIn: WasmPointer, + pData: WasmPointer, ) => number; - sqlite3changegroup_delete: (changeGrp: WasmPointer) => number; - sqlite3changegroup_new: (ppOut: WasmPointer) => number; + + /** + * Obtain a buffer containing a changeset (or patchset) representing the + * current contents of the changegroup. If the inputs to the changegroup were + * themselves changesets, the output is a changeset. Or, if the inputs were + * patchsets, the output is also a patchset. + * + * C Signature: + * + * int sqlite3changegroup_output( + * sqlite3_changegroup *p, + * int *pnData, + * void **ppData + * ); + * + * See https://www.sqlite.org/c3ref/changegroup_output.html + */ sqlite3changegroup_output: ( changeGrp: WasmPointer, pnData: WasmPointer, ppData: WasmPointer, ) => number; - sqlite3changegroup_output_strm: ( - changeGrp: WasmPointer, - xOutput: (pOut: WasmPointer, pData: WasmPointer, nData: number) => number, - pOut: WasmPointer, - ) => number; + /** + * Delete a Changegroup Object + * + * C Signature: + * + * void sqlite3changegroup_delete(sqlite3_changegroup * p); + * + * See https://www.sqlite.org/c3ref/changegroup_delete.html + */ + sqlite3changegroup_delete: (changeGrp: WasmPointer) => number; + + /** + * Apply a changeset or patchset to a database. This function attempts to + * update the `"main"` database attached to handle `db` with the changes found + * in the changeset passed via the second and third arguments. + * + * The fourth argument (`xFilter`) passed to this function is the "filter + * callback". If it is not NULL, then for each table affected by at least one + * change in the changeset, the filter callback is invoked with the table name + * as the second argument, and a copy of the context pointer passed as the + * sixth argument as the first. If the "filter callback" returns zero, then no + * attempt is made to apply any changes to the table. Otherwise, if the return + * value is non-zero or the `xFilter` argument to is NULL, all changes related + * to the table are attempted. + * + * C Signature: + * + * int sqlite3changeset_apply( + * sqlite3 *db, + * int nChangeset, + * void *pChangeset, + * int(*xFilter)(void *pCtx, const char *zTab), + * int (*xConflict)(void *pCtx, int eConflict, sqlite3_changeset_iter *p), + * void *pCtx + * ); + * + * See https://www.sqlite.org/c3ref/changeset_apply.html + * + * @param db Apply change to `"main"` db of this handle + * @param nChangeset Size of changeset blob in bytes + * @param pChangeset Pointer to changeset blob + * @param xFilter Filter function + * @param xConflict Conflict handler function + * @param pCtx Context pointer passed to filter and conflict functions + */ sqlite3changeset_apply: ( db: Database | WasmPointer, nChangeset: number, @@ -3959,6 +6927,7 @@ declare type CAPI = { | (( pCtx: WasmPointer, eConflict: number /* TODO: Can be more specific? */, + pIter: WasmPointer, ) => | CAPI['SQLITE_CHANGESET_OMIT'] | CAPI['SQLITE_CHANGESET_ABORT'] @@ -3966,21 +6935,47 @@ declare type CAPI = { | WasmPointer, pCtx: WasmPointer, ) => number; - sqlite3changeset_apply_strm: ( - db: Database | WasmPointer, - xInput: - | ((pIn: WasmPointer, pData: WasmPointer, pnData: WasmPointer) => number) - | WasmPointer, - pIn: WasmPointer, - xFilter: ((pCtx: WasmPointer, tableName: string) => number) | WasmPointer, - xConflict: - | (( - pCtx: WasmPointer, - eConflict: number /* TODO: Can be more specific? */, - ) => number) - | WasmPointer, - pCtx: WasmPointer, - ) => number; + + /** + * Apply a changeset or patchset to a database. This function attempts to + * update the `"main"` database attached to handle `db` with the changes found + * in the changeset passed via the second and third arguments. + * + * The fourth argument (`xFilter`) passed to this function is the "filter + * callback". If it is not NULL, then for each table affected by at least one + * change in the changeset, the filter callback is invoked with the table name + * as the second argument, and a copy of the context pointer passed as the + * sixth argument as the first. If the "filter callback" returns zero, then no + * attempt is made to apply any changes to the table. Otherwise, if the return + * value is non-zero or the `xFilter` argument to is NULL, all changes related + * to the table are attempted. + * + * C Signature: + * + * int sqlite3changeset_apply_v2( + * sqlite3 *db, + * int nChangeset, + * void *pChangeset, + * int(*xFilter)(void *pCtx, const char *zTab), + * int (*xConflict)(void *pCtx, int eConflict, sqlite3_changeset_iter *p), + * void *pCtx, + * void **ppRebase, + * int *pnRebase, + * int flags + * ); + * + * See https://www.sqlite.org/c3ref/changeset_apply.html + * + * @param db Apply change to `"main"` db of this handle + * @param nChangeset Size of changeset blob in bytes + * @param pChangeset Pointer to changeset blob + * @param xFilter Filter function + * @param xConflict Conflict handler function + * @param pCtx Context pointer passed to filter and conflict functions + * @param ppRebase OUT: Pointer to rebase data + * @param pnRebase OUT: Size of rebase data in bytes + * @param flags `SESSION_CHANGESETAPPLY_*` flags + */ sqlite3changeset_apply_v2: ( db: Database | WasmPointer, nChangeset: number, @@ -3990,6 +6985,7 @@ declare type CAPI = { | (( pCtx: WasmPointer, eConflict: number /* TODO: Can be more specific? */, + pIter: WasmPointer, ) => | CAPI['SQLITE_CHANGESET_OMIT'] | CAPI['SQLITE_CHANGESET_ABORT'] @@ -4000,6 +6996,75 @@ declare type CAPI = { pnRebase: WasmPointer, flags: number, ) => number; + + /** + * Streaming version of `sqlite3changeset_apply()`. + * + * C Signature: + * + * int sqlite3changeset_apply_strm( + * sqlite3 *db, + * int(*xInput)(void *pIn, void *pData, int *pnData), + * void *pIn, + * int(*xFilter)(void *pCtx, const char *zTab), + * int (*xConflict)(void *pCtx, int eConflict, sqlite3_changeset_iter *p), + * void *pCtx + * ); + * + * See https://www.sqlite.org/session/sqlite3changegroup_add_strm.html + * + * @param db Apply change to `"main"` db of this handle + * @param xInput Input function + * @param pIn First arg for xInput + * @param xFilter Filter function + * @param xConflict Conflict handler function + * @param pCtx First argumet for xFilter and xConflict + */ + sqlite3changeset_apply_strm: ( + db: Database | WasmPointer, + xInput: + | ((pIn: WasmPointer, pData: WasmPointer, pnData: WasmPointer) => number) + | WasmPointer, + pIn: WasmPointer, + xFilter: ((pCtx: WasmPointer, tableName: string) => number) | WasmPointer, + xConflict: + | (( + pCtx: WasmPointer, + eConflict: number /* TODO: Can be more specific? */, + ) => number) + | WasmPointer, + pCtx: WasmPointer, + ) => number; + + /** + * Streaming version of `sqlite3changeset_apply_v2()`. + * + * C Signature: + * + * int sqlite3changeset_apply_v2_strm( + * sqlite3 *db, + * int(*xInput)(void *pIn, void *pData, int *pnData), + * void *pIn, + * int(*xFilter)(void *pCtx, const char *zTab), + * int (*xConflict)(void *pCtx, int eConflict, sqlite3_changeset_iter *p), + * void *pCtx, + * void **ppRebase, + * int *pnRebase, + * int flags + * ); + * + * See https://www.sqlite.org/session/sqlite3changegroup_add_strm.html + * + * @param db Apply change to `"main"` db of this handle + * @param xInput Input function + * @param pIn First arg for xInput + * @param xFilter Filter function + * @param xConflict Conflict handler function + * @param pCtx First argumet for xFilter and xConflict + * @param ppRebase OUT: Pointer to rebase data + * @param pnRebase OUT: Size of rebase data in bytes + * @param flags `SESSION_CHANGESETAPPLY_*` flags + */ sqlite3changeset_apply_v2_strm: ( db: Database | WasmPointer, xInput: @@ -4018,14 +7083,23 @@ declare type CAPI = { pnRebase: WasmPointer, flags: number, ) => number; - sqlite3changeset_concat: ( - nA: number, - pA: WasmPointer, - nB: number, - pB: WasmPointer, - pnOut: WasmPointer, - ppOut: WasmPointer, - ) => number; + + /** + * Streaming version of `sqlite3changeset_concat()`. + * + * C Signature: + * + * int sqlite3changeset_concat_strm( + * int(*xInputA)(void *pIn, void *pData, int *pnData), + * void *pInA, + * int(*xInputB)(void *pIn, void *pData, int *pnData), + * void *pInB, + * int(*xOutput)(void *pOut, void *pData, int nData), + * void *pOut + * ); + * + * See https://www.sqlite.org/session/sqlite3changegroup_add_strm.html + */ sqlite3changeset_concat_strm: ( xInputA: | ((pIn: WasmPointer, pData: WasmPointer, pnData: WasmPointer) => number) @@ -4035,65 +7109,50 @@ declare type CAPI = { | ((pIn: WasmPointer, pData: WasmPointer, pnData: WasmPointer) => number) | WasmPointer, pInB: WasmPointer, - xOutput: - | ((pOut: WasmPointer, pData: WasmPointer, nData: number) => number) - | WasmPointer, - pOut: WasmPointer, - ) => number; - sqlite3changeset_conflict: ( - pIter: WasmPointer, - colNum: number, - ppValue: WasmPointer, - ) => number; - sqlite3changeset_finalize: (pIter: WasmPointer) => number; - sqlite3changeset_fk_conflicts: ( - pIter: WasmPointer, - pnOut: WasmPointer, - ) => number; - sqlite3changeset_invert: ( - nIn: number, - pIn: WasmPointer, - pnOut: WasmPointer, - ppOut: WasmPointer, - ) => number; - sqlite3changeset_invert_strm: ( - xInput: - | ((pIn: WasmPointer, pData: WasmPointer, pnData: WasmPointer) => number) - | WasmPointer, - pIn: WasmPointer, - xOutput: - | ((pOut: WasmPointer, pData: WasmPointer, nData: number) => number) - | WasmPointer, - pOut: WasmPointer, - ) => number; - sqlite3changeset_new: ( - pIter: WasmPointer, - colNum: number, - ppValue: WasmPointer, - ) => number; - sqlite3changeset_next: (pIter: WasmPointer) => number; - sqlite3changeset_old: ( - pIter: WasmPointer, - colNum: number, - ppValue: WasmPointer, - ) => number; - sqlite3changeset_op: ( - pIter: WasmPointer, - pzTab: WasmPointer, - pnCol: WasmPointer, - pOp: WasmPointer, - pbIndirect: WasmPointer, - ) => number; - sqlite3changeset_pk: ( - pIter: WasmPointer, - pabPK: WasmPointer, - pnCol: WasmPointer, + xOutput: + | ((pOut: WasmPointer, pData: WasmPointer, nData: number) => number) + | WasmPointer, + pOut: WasmPointer, ) => number; - sqlite3changeset_start: ( - ppIter: WasmPointer, - nChangeset: number, - pChangeset: WasmPointer, + + /** + * Streaming version of `sqlite3changeset_invert()`. + * + * C Signature: + * + * int sqlite3changeset_invert_strm( + * int(*xInput)(void *pIn, void *pData, int *pnData), + * void *pIn, + * int(*xOutput)(void *pOut, void *pData, int nData), + * void *pOut + * ); + * + * See https://www.sqlite.org/session/sqlite3changegroup_add_strm.html + */ + sqlite3changeset_invert_strm: ( + xInput: + | ((pIn: WasmPointer, pData: WasmPointer, pnData: WasmPointer) => number) + | WasmPointer, + pIn: WasmPointer, + xOutput: + | ((pOut: WasmPointer, pData: WasmPointer, nData: number) => number) + | WasmPointer, + pOut: WasmPointer, ) => number; + + /** + * Streaming version of `sqlite3changeset_start()`. + * + * C Signature: + * + * int sqlite3changeset_start_strm( + * sqlite3_changeset_iter **pp, + * int(*xInput)(void *pIn, void *pData, int *pnData), + * void *pIn + * ); + * + * See https://www.sqlite.org/session/sqlite3changegroup_add_strm.html + */ sqlite3changeset_start_strm: ( ppIter: WasmPointer, xInput: @@ -4101,12 +7160,21 @@ declare type CAPI = { | WasmPointer, pIn: WasmPointer, ) => number; - sqlite3changeset_start_v2: ( - ppIter: WasmPointer, - nChangeset: number, - pChangeset: WasmPointer, - flags: number, - ) => number; + + /** + * Streaming version of `sqlite3changeset_start_v2()`. + * + * C Signature: + * + * int sqlite3changeset_start_v2_strm( + * sqlite3_changeset_iter **pp, + * int(*xInput)(void *pIn, void *pData, int *pnData), + * void *pIn, + * int flags + * ); + * + * See https://www.sqlite.org/session/sqlite3changegroup_add_strm.html + */ sqlite3changeset_start_v2_strm: ( ppIter: WasmPointer, xInput: @@ -4116,13 +7184,19 @@ declare type CAPI = { flags: number, ) => number; - sqlite3session_attach: (pSession: WasmPointer, tableName: string) => number; - sqlite3session_changeset: ( - pSession: WasmPointer, - pnChangeset: WasmPointer, - ppChangeset: WasmPointer, - ) => number; - sqlite3session_changeset_size: (pSession: WasmPointer) => number; + /** + * Streaming version of `sqlite3session_changeset()`. + * + * C Signature: + * + * int sqlite3session_changeset_strm( + * sqlite3_session *pSession, + * int(*xOutput)(void *pOut, void *pData, int nData), + * void *pOut + * ); + * + * See https://www.sqlite.org/session/sqlite3changegroup_add_strm.html + */ sqlite3session_changeset_strm: ( pSession: WasmPointer, xOutput: @@ -4130,31 +7204,20 @@ declare type CAPI = { | WasmPointer, pOut: WasmPointer, ) => number; - sqlite3session_config: ( - op: CAPI['SQLITE_SESSION_CONFIG_STRMSIZE'], - pArg: WasmPointer, - ) => number; - sqlite3session_create: ( - db: Database | WasmPointer, - dbName: string, - ppSession: WasmPointer, - ) => number; - sqlite3session_diff: ( - pSession: WasmPointer, - fromDb: string, - tableName: string, - pzErrMsg: WasmPointer, - ) => number; - sqlite3session_enable: (pSession: WasmPointer, bEnable: number) => number; - sqlite3session_indirect: (pSession: WasmPointer, bIndirect: number) => number; - sqlite3session_isempty: (pSession: WasmPointer) => number; - sqlite3session_memory_used: (pSession: WasmPointer) => number; - sqlite3session_object_config: (pSession: WasmPointer, op: number) => number; - sqlite3session_patchset: ( - pSession: WasmPointer, - pnPatchset: WasmPointer, - ppPatchset: WasmPointer, - ) => number; + + /** + * Streaming version of `sqlite3session_patchset()`. + * + * C Signature: + * + * int sqlite3session_patchset_strm( + * sqlite3_session *pSession, + * int(*xOutput)(void *pOut, void *pData, int nData), + * void *pOut + * ); + * + * See https://www.sqlite.org/session/sqlite3changegroup_add_strm.html + */ sqlite3session_patchset_strm: ( pSession: WasmPointer, xOutput: @@ -4162,12 +7225,185 @@ declare type CAPI = { | WasmPointer, pOut: WasmPointer, ) => number; - sqlite3session_table_filter: ( - pSession: WasmPointer, - xFilter: ((pCtx: WasmPointer, tableName: string) => number) | WasmPointer, - pCtx: WasmPointer, + + /** + * Streaming version of `sqlite3changegroup_add()`. + * + * C Signature: + * + * int sqlite3changegroup_add_strm( + * sqlite3_changegroup *p, + * int(*xInput)(void *pIn, void *pData, int *pnData), + * void *pIn + * ); + * + * See https://www.sqlite.org/session/sqlite3changegroup_add_strm.html + */ + sqlite3changegroup_add_strm: ( + changeGrp: WasmPointer, + xInput: ( + pIn: WasmPointer, + pData: WasmPointer, + pnData: WasmPointer, + ) => number, + pIn: WasmPointer, + ) => number; + + /** + * Streaming version of `sqlite3changegroup_output()`. + * + * C Signature: + * + * int sqlite3changegroup_output_strm( + * sqlite3_changegroup *p, + * int(*xOutput)(void *pOut, void *pData, int nData), + * void *pOut + * ); + * + * See https://www.sqlite.org/session/sqlite3changegroup_add_strm.html + */ + sqlite3changegroup_output_strm: ( + changeGrp: WasmPointer, + xOutput: (pOut: WasmPointer, pData: WasmPointer, nData: number) => number, + pOut: WasmPointer, + ) => number; + + /** + * Used to make global configuration changes to the sessions module in order + * to tune it to the specific needs of the application. + * + * C Signature: + * + * int sqlite3session_config( + * int op, + * void *pArg + * ); + * + * See https://www.sqlite.org/session/sqlite3session_config.html + */ + sqlite3session_config: ( + op: CAPI['SQLITE_SESSION_CONFIG_STRMSIZE'], + pArg: WasmPointer, + ) => number; + + /** + * If the wasm environment has a WASMFS/OPFS-backed persistent storage + * directory, its path is returned by this function. If it does not then it + * returns "" (noting that "" is a falsy value). + */ + sqlite3_wasmfs_opfs_dir: () => string; + + /** + * Returns true if sqlite3.capi.sqlite3_wasmfs_opfs_dir() is a non-empty + * string and the given name starts with (that string + '/'), else returns + * false. + */ + sqlite3_wasmfs_filename_is_persistent: (name: string) => boolean; + + /** + * Given an `sqlite3*`, an `sqlite3_vfs` name, and an optional db name + * (defaults to `"main"`), returns a truthy value (see below) if that db + * handle uses that VFS, else returns false. If `pDb` is falsy then the 3rd + * argument is ignored and this function returns a truthy value if the default + * VFS name matches that of the 2nd argument. Results are `undefined` if `pDb` + * is truthy but refers to an invalid pointer. The 3rd argument specifies the + * database name of the given database connection to check, defaulting to the + * main db. + * + * To permit safe use of this function from APIs which may be called via the C + * stack (like SQL UDFs), this function does not throw: if bad arguments cause + * a conversion error when passing into wasm-space, false is returned. + * + * See https://sqlite.org/wasm/doc/trunk/api-c-style.md#sqlite3_js_db_uses_vfs + */ + sqlite3_js_db_uses_vfs: ( + db: Database | WasmPointer, + vfsName: string, + dbName: string, + ) => boolean; + + /** Returns an array of the names of all currently-registered sqlite3 VFSes. */ + sqlite3_js_vfs_list: () => string[]; + + /** + * A convenience wrapper around `sqlite3_serialize()` which serializes the + * given `sqlite3*` pointer or `sqlite3.oo1.DB` instance to a `Uint8Array`. + * + * See https://sqlite.org/wasm/doc/trunk/api-c-style.md#sqlite3_js_db_export + * + * @param schema The schema to serialize. It may be a WASM C-string pointer or + * a JS string. If it is falsy, it defaults to `"main"`. + * @returns A `Uint8Array`. If the schema is empty, an empty array is + * returned. + * @throws A description of the problem. + */ + sqlite3_js_db_export: ( + db: Database | WasmPointer, + schema?: string | WasmPointer, + ) => Uint8Array; + + /** + * Given a `sqlite3*` and a database name (JS string or WASM C-string pointer, + * which may be 0), returns a pointer to the `sqlite3_vfs` responsible for it. + * If the given db name is null/0, or not provided, then `"main"` is assumed. + */ + sqlite3_js_db_vfs: ( + db: Database | WasmPointer, + dbName?: string | WasmPointer, + ) => WasmPointer; + + /** + * Given one of the `SQLITE_...` constant values, this function returns the + * string form of that constant, or undefined if no match is found, noting + * that some constants available in the C API are not exported to WASM because + * they simply are not used there. + */ + sqlite3_js_rc_str: (rc: number) => string; + + /** @deprecated Use `sqlite3_js_posix_create_file` or `OpfsDb#importDb` instead */ + sqlite3_js_vfs_create_file: ( + vfs: string | WasmPointer | sqlite3_vfs, + name: string | WasmPointer, + data: undefined | WasmPointer | Uint8Array | ArrayBuffer, + dataLen?: number, ) => void; + /** + * Given a `sqlite3_value*`, this function attempts to convert it to an + * equivalent JS value with as much fidelity as feasible and return it. + * + * By default it throws if it cannot determine any sensible conversion. If + * passed a falsy second argument, it instead returns undefined if no suitable + * conversion is found. Note that there is no conversion from SQL to JS which + * results in the undefined value. It always throws a WasmAllocError if + * allocating memory for a conversion fails. + */ + sqlite3_value_to_js( + sqliteValue: WasmPointer, + throwIfCannotConvert?: true, + ): SqlValue; + sqlite3_value_to_js( + sqliteValue: WasmPointer, + throwIfCannotConvert: false, + ): SqlValue | undefined; + + /** + * Requires a C-style array of `sqlite3_value*` objects and the number of + * entries in that array. Returns a JS array containing the results of passing + * each C array entry to `sqlite3_value_to_js()`. The 3rd argument to this + * function is passed on as the 2nd argument to that one. + */ + sqlite3_values_to_js( + numVals: number, + sqliteValues: WasmPointer, + throwIfCannotConvert?: true, + ): SqlValue[]; + sqlite3_values_to_js( + numVals: number, + sqliteValues: WasmPointer, + throwIfCannotConvert: false, + ): (SqlValue | undefined)[]; + SQLITE_ACCESS_EXISTS: 0; SQLITE_ACCESS_READWRITE: 1; SQLITE_ACCESS_READ: 2; @@ -4208,7 +7444,7 @@ declare type CAPI = { SQLITE_RECURSIVE: 33; SQLITE_STATIC: 0; SQLITE_TRANSIENT: -1; - SQLITE_WASM_DEALLOC: 1; + SQLITE_WASM_DEALLOC: WasmPointer; SQLITE_CHANGESETSTART_INVERT: 2; SQLITE_CHANGESETAPPLY_NOSAVEPOINT: 1; SQLITE_CHANGESETAPPLY_INVERT: 2; @@ -4533,7 +7769,7 @@ declare type CAPI = { SQLITE_DETERMINISTIC: 2048; SQLITE_DIRECTONLY: 524288; SQLITE_INNOCUOUS: 2097152; - SQLITE_VERSION_NUMBER: 3043000; + SQLITE_VERSION_NUMBER: number; SQLITE_VERSION: string; SQLITE_SOURCE_ID: string; SQLITE_SERIALIZE_NOCOPY: 1; @@ -4566,65 +7802,4 @@ declare type CAPI = { SQLITE_ROLLBACK: 1; SQLITE_FAIL: 3; SQLITE_REPLACE: 5; - sqlite3_js_rc_str: (rc: number) => string; - sqlite3_close_v2: (db: Database | WasmPointer) => number; - sqlite3session_delete: (pSession: WasmPointer) => number; - sqlite3_create_collation_v2: ( - db: Database | WasmPointer, - zName: string, - eTextRep: CAPI['SQLITE_UTF8'], - pArg: WasmPointer, - xCompare: - | (( - pCtx: WasmPointer, - len1: number, - p1: WasmPointer, - len2: number, - p2: WasmPointer, - ) => number) - | WasmPointer, - xDestroy: ((pCtx: WasmPointer) => void) | WasmPointer, - ) => number; - sqlite3_create_collation: ( - db: Database | WasmPointer, - zName: string, - eTextRep: CAPI['SQLITE_UTF8'], - pArg: WasmPointer, - xCompare: - | (( - pCtx: WasmPointer, - len1: number, - p1: WasmPointer, - len2: number, - p2: WasmPointer, - ) => number) - | WasmPointer, - ) => number; - sqlite3_config( - op: - | CAPI['SQLITE_CONFIG_COVERING_INDEX_SCAN'] - | CAPI['SQLITE_CONFIG_MEMSTATUS'] - | CAPI['SQLITE_CONFIG_SMALL_MALLOC'] - | CAPI['SQLITE_CONFIG_SORTERREF_SIZE'] - | CAPI['SQLITE_CONFIG_STMTJRNL_SPILL'] - | CAPI['SQLITE_CONFIG_URI'], - arg: number, - ): number; - sqlite3_config( - op: CAPI['SQLITE_CONFIG_LOOKASIDE'], - arg1: number, - arg2: number, - ): number; - sqlite3_config(op: CAPI['SQLITE_CONFIG_MEMDB_MAXSIZE'], arg: BigInt): number; - sqlite3_auto_extension: ( - xEntryPoint: - | (( - db: Database | WasmPointer, - pzErrMsg: WasmPointer, - pThunk: WasmPointer, - ) => number) - | WasmPointer, - ) => number; - sqlite3_cancel_auto_extension: (xEntryPoint: WasmPointer) => number; - sqlite3_reset_auto_extension: () => void; }; From 1cf8e337e988970f83b691a4c91c72b1b9207da7 Mon Sep 17 00:00:00 2001 From: Johannes Baiter Date: Wed, 30 Aug 2023 23:30:30 +0200 Subject: [PATCH 09/12] Add new types from SQLite 3.43 --- index.d.ts | 229 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 228 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 9e8d4aa..1c29b89 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1255,6 +1255,131 @@ declare class OpfsDatabase extends Database { ): Promise; } +declare class OpfsSAHPoolDatabase extends OpfsDatabase { + constructor(filename: string); +} + +type SAHPoolUtil = { + OpfsSAHPoolDb: typeof OpfsSAHPoolDatabase; + + /** + * Adds `numEntries` entries to the current pool. + * + * This change is persistent across sessions so should not be called + * automatically at each app startup (but see `reserveMinimumCapacity()`). Its + * returned Promise resolves to the new capacity. Because this operation is + * necessarily asynchronous, the C-level VFS API cannot call this on its own + * as needed. + */ + addCapacity: (numEntries: number) => Promise; + + /** + * Synchronously reads the contents of the given file into a `Uint8Array` and + * returns it. + * + * This will throw if the given name is not currently in active use or on I/O + * error. Note that the given name is not visible directly in OPFS (or, if it + * is, it's not from this VFS). The reason for that is that this VFS manages + * name-to-file mappings in a roundabout way in order to maintain its list of + * SAHs. + */ + exportFile: (filename: string) => Promise; + + /** + * Returns the number of files currently contained in the SAH pool. + * + * The default capacity is only large enough for one or two databases and + * their associated temp files. + */ + getCapacity: () => number; + + /** + * Returns the number of files from the pool currently allocated to VFS slots. + * + * This is not the same as the files being "opened". + */ + getFileCount: () => number; + + /** + * Returns an array of the names of the files currently allocated to VFS + * slots. + * + * This list is the same length as `getFileCount()`. + */ + getFilenames: () => string[]; + + /** + * Imports the contents of an SQLite database, provided as a byte array or + * ArrayBuffer, under the given name, overwriting any existing content. + * + * Throws if the pool has no available file slots, on I/O error, or if the + * input does not appear to be a database. In the latter case, only a cursory + * examination is made. + * + * Note that this routine is only for importing database files, not arbitrary + * files, the reason being that this VFS will automatically clean up any + * non-database files so importing them is pointless. + * + * On a write error, the handle is removed from the pool and made available + * for re-use. + * + * On success, the number of bytes written is returned. + */ + importDb: (name: string, data: Uint8Array | ArrayBuffer) => Promise; + + /** + * Removes up to `numEntries` entries from the pool, with the caveat that it + * can only remove currently-unused entries. + * + * It returns a Promise which resolves to the number of entries actually + * removed. + */ + reduceCapacity: (numEntries: number) => Promise; + + /** + * Unregisters the VFS and removes its directory from OPFS (which means all + * client content is destroyed). After calling this, the VFS may no longer be + * used and there is currently no way to re-add it aside from reloading the + * current JavaScript context. + * + * Results are undefined if a database is currently in use with this VFS. + * + * The returned Promise resolves to true if it performed the removal and false + * if the VFS was not installed. + * + * If the VFS has a multi-level directory, e.g. "/foo/bar/baz", only the + * bottom-most directory is removed because this VFS cannot know for certain + * whether the higher-level directories contain data which should be removed. + */ + removeVfs: () => Promise; + + /** + * If the current capacity is less than `minCapacity`, the capacity is + * increased to `minCapacity`, else this returns with no side effects. + * + * The resulting Promise resolves to the new capacity. + */ + reserveMinimumCapacity: (minCapacity: number) => Promise; + + /** + * If a virtual file exists with the given name, disassociates it from the + * pool and returns true, else returns false without side effects. Results are + * undefined if the file is currently in active use. Recall that names need to + * use absolute paths (starting with a slash). + */ + unlink: (filename: string) => boolean; + + /** The SQLite VFS name under which this pool's VFS is registered. */ + vfsName: string; + + /** + * Clears all client-defined state of all SAHs and makes all of them available + * for re-use by the pool. Results are undefined if any such handles are + * currently in use, e.g. by an sqlite3 db. + */ + wipeFiles: () => Promise; +}; + /** Exception class for reporting WASM-side allocation errors. */ declare class WasmAllocError extends Error { constructor(message: string); @@ -1752,6 +1877,65 @@ declare type Sqlite3Static = { */ initWorker1API(): void; + installOpfsSAHPoolVfs(opts: { + /** + * If truthy (default=false) contents and filename mapping are removed from + * each SAH it is acquired during initalization of the VFS, leaving the + * VFS's storage in a pristine state. Use this only for databases which need + * not survive a page reload. + */ + clearOnInit?: boolean; + + /** + * (default=6) Specifies the default capacity of the VFS. + * + * This should not be set unduly high because the VFS has to open (and keep + * open) a file for each entry in the pool. This setting only has an effect + * when the pool is initially empty. It does not have any effect if a pool + * already exists. Note that this number needs to be at least twice the + * number of expected database files (to account for journal files) and may + * need to be even higher than three times the number of databases plus one, + * depending on the value of the `TEMP_STORE` pragma and how the databases + * are used. + */ + initialCapacity?: number; + + /** + * (default="."+options.name) Specifies the OPFS directory name in which to + * store metadata for the VFS. + * + * Only one instance of this VFS can use the same directory concurrently. + * Using a different directory name for each application enables different + * engines in the same HTTP origin to co-exist, but their data are invisible + * to each other. Changing this name will effectively orphan any databases + * stored under previous names. This option may contain multiple path + * elements, e.g. "/foo/bar/baz", and they are created automatically. In + * practice there should be no driving need to change this. + * + * **ACHTUNG:** all files in this directory are assumed to be managed by the + * VFS. Do not place other files in this directory, as they may be deleted + * or otherwise modified by the VFS. + */ + directory?: string; + + /** + * (default="opfs-sahpool") sets the name to register this VFS under. + * + * Normally this should not be changed, but it is possible to register this + * VFS under multiple names so long as each has its own separate directory + * to work from. The storage for each is invisible to all others. The name + * must be a string compatible with `sqlite3_vfs_register()` and friends and + * suitable for use in URI-style database file names. + * + * **ACHTUNG:** if a custom name is provided, a custom directory must also + * be provided if any other instance is registered with the default + * directory. No two instances may use the same directory. If no directory + * is explicitly provided then a directory name is synthesized from the name + * option. + */ + name?: string; + }): Promise; + WasmAllocError: WasmAllocError; SQLite3Error: SQLite3Error; @@ -7368,6 +7552,44 @@ declare type CAPI = { dataLen?: number, ) => void; + /** + * Clears all kvvfs-owned state and returns the number of records it deleted + * (one record per database page). + */ + sqlite3_js_kvvfs_clear: (which?: string) => void; + + /** Returns an estimate of how many bytes of storage are used by kvvfs. */ + sqlite3_js_kvvfs_size: (which?: string) => number; + + /** + * If the current environment supports the POSIX file APIs, this routine + * creates (or overwrites) the given file using those APIs. This is primarily + * intended for use in Emscripten-based builds where the POSIX APIs are + * transparently proxied by an in-memory virtual filesystem. It may behave + * differently in other environments. + * + * The first argument must be either a JS string or WASM C-string holding the + * filename. Note that this routine does not create intermediary directories + * if the filename has a directory part. + * + * The 2nd argument may either a valid WASM memory pointer, an ArrayBuffer, or + * a Uint8Array. The 3rd must be the length, in bytes, of the data array to + * copy. If the 2nd argument is an ArrayBuffer or Uint8Array and the 3rd is + * not a positive integer then the 3rd defaults to the array's byteLength + * value. + * + * Results are undefined if data is a WASM pointer and dataLen is exceeds + * data's bounds. + * + * Throws if any arguments are invalid or if creating or writing to the file + * fails. + */ + sqlite3_js_posix_create_file: ( + filename: string | WasmPointer, + data: Uint8Array | ArrayBuffer | WasmPointer, + dataLen?: number, + ) => void; + /** * Given a `sqlite3_value*`, this function attempts to convert it to an * equivalent JS value with as much fidelity as feasible and return it. @@ -7444,10 +7666,11 @@ declare type CAPI = { SQLITE_RECURSIVE: 33; SQLITE_STATIC: 0; SQLITE_TRANSIENT: -1; - SQLITE_WASM_DEALLOC: WasmPointer; + SQLITE_WASM_DEALLOC: 1; SQLITE_CHANGESETSTART_INVERT: 2; SQLITE_CHANGESETAPPLY_NOSAVEPOINT: 1; SQLITE_CHANGESETAPPLY_INVERT: 2; + SQLITE_CHANGESETAPPLY_IGNORENOOP: 4; SQLITE_CHANGESET_DATA: 1; SQLITE_CHANGESET_NOTFOUND: 2; SQLITE_CHANGESET_CONFLICT: 3; @@ -7507,6 +7730,8 @@ declare type CAPI = { SQLITE_DBCONFIG_ENABLE_VIEW: 1015; SQLITE_DBCONFIG_LEGACY_FILE_FORMAT: 1016; SQLITE_DBCONFIG_TRUSTED_SCHEMA: 1017; + SQLITE_DBCONFIG_STMT_SCANSTATUS: 1018; + SQLITE_DBCONFIG_REVERSE_SCANORDER: 1019; SQLITE_DBCONFIG_MAX: 1019; SQLITE_DBSTATUS_LOOKASIDE_USED: 0; SQLITE_DBSTATUS_CACHE_USED: 1; @@ -7567,6 +7792,7 @@ declare type CAPI = { SQLITE_FCNTL_CKPT_START: 39; SQLITE_FCNTL_EXTERNAL_READER: 40; SQLITE_FCNTL_CKSM_FILE: 41; + SQLITE_FCNTL_RESET_CACHE: 42; SQLITE_LOCK_NONE: 0; SQLITE_LOCK_SHARED: 1; SQLITE_LOCK_RESERVED: 2; @@ -7799,6 +8025,7 @@ declare type CAPI = { SQLITE_VTAB_CONSTRAINT_SUPPORT: 1; SQLITE_VTAB_INNOCUOUS: 2; SQLITE_VTAB_DIRECTONLY: 3; + SQLITE_VTAB_USES_ALL_SCHEMAS: 4; SQLITE_ROLLBACK: 1; SQLITE_FAIL: 3; SQLITE_REPLACE: 5; From a22372df0f02d30f0ce011c9407c10563f21f869 Mon Sep 17 00:00:00 2001 From: Johannes Baiter Date: Wed, 30 Aug 2023 23:43:09 +0200 Subject: [PATCH 10/12] Add SqliteClient class to type definitions --- index.d.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/index.d.ts b/index.d.ts index 1c29b89..b233f30 100644 --- a/index.d.ts +++ b/index.d.ts @@ -8030,3 +8030,17 @@ declare type CAPI = { SQLITE_FAIL: 3; SQLITE_REPLACE: 5; }; + +export class SqliteClient { + dbFile: string; + sqliteWorkerPath: string; + + constructor(dFile: string, sqliteWorkerPath: string); + + init(): Promise; + + executeSql( + sqlStatement: string, + bindParameters: SqlValue[], + ): Promise; +} From bf4b0e0e9b30c0b187af63eafcb95e4c2acffe4c Mon Sep 17 00:00:00 2001 From: Johannes Baiter Date: Sun, 1 Oct 2023 13:55:35 +0200 Subject: [PATCH 11/12] Fix function parameter types for create_function and wrappers --- index.d.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/index.d.ts b/index.d.ts index b233f30..651e317 100644 --- a/index.d.ts +++ b/index.d.ts @@ -548,7 +548,7 @@ declare type FunctionOptions = { declare type ScalarFunctionOptions = FunctionOptions & { /** Scalar function to be defined. */ - xFunc: (ctxPtr: number, ...args: any[]) => any; + xFunc: (ctxPtr: number, ...args: SqlValue[]) => SqlValue; }; declare type AggregateFunctionOptions = FunctionOptions & { @@ -970,11 +970,11 @@ declare class Database { */ createFunction( name: string, - func: (ctxPtr: number, ...args: any[]) => SqlValue, + func: (ctxPtr: number, ...values: SqlValue[]) => SqlValue, ): this; createFunction( name: string, - func: (ctxPtr: number, ...args: any[]) => void, + func: (ctxPtr: number, ...values: SqlValue[]) => void, options: FunctionOptions, ): this; createFunction( @@ -4636,10 +4636,10 @@ declare type CAPI = { eTextRep: CAPI['SQLITE_UTF8'], pApp: WasmPointer, xFunc: - | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => SqlValue) + | ((ctx: WasmPointer, ...values: SqlValue[]) => SqlValue) | WasmPointer, xStep: - | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => void) + | ((ctx: WasmPointer, ...values: SqlValue[]) => void) | WasmPointer, xFinal: ((ctx: WasmPointer) => SqlValue) | WasmPointer, ) => number; @@ -4671,10 +4671,10 @@ declare type CAPI = { eTextRep: CAPI['SQLITE_UTF8'], pApp: WasmPointer, xFunc: - | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => SqlValue) + | ((ctx: WasmPointer, ...values: SqlValue[]) => SqlValue) | WasmPointer, xStep: - | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => void) + | ((ctx: WasmPointer, ...values: SqlValue[]) => void) | WasmPointer, xFinal: ((ctx: WasmPointer) => SqlValue) | WasmPointer, xDestroy: (() => void) | WasmPointer, @@ -4708,12 +4708,12 @@ declare type CAPI = { eTextRep: CAPI['SQLITE_UTF8'], pApp: WasmPointer, xStep: - | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => SqlValue) + | ((ctx: WasmPointer, ...values: SqlValue[]) => SqlValue) | WasmPointer, xFinal: ((ctx: WasmPointer) => SqlValue) | WasmPointer, xValue: ((ctx: WasmPointer) => void) | WasmPointer, xInverse: - | ((ctx: WasmPointer, nArg: number, args: WasmPointer) => void) + | ((ctx: WasmPointer, ...values: SqlValue[]) => void) | WasmPointer, xDestroy: (() => void) | WasmPointer, ) => number; From 375bdbae54438801aa663bd71f6bd3923d415d85 Mon Sep 17 00:00:00 2001 From: Johannes Baiter Date: Sun, 1 Oct 2023 23:33:46 +0200 Subject: [PATCH 12/12] Improvements to TypeScript types (thanks @sampbarrow) - Use `readonly T[]` argument types where possible - Fix typo in first `xWrapped` overload - Include `BigInt` in `SqlValue` union type --- index.d.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/index.d.ts b/index.d.ts index 651e317..7f527ad 100644 --- a/index.d.ts +++ b/index.d.ts @@ -3,6 +3,7 @@ declare type SqlValue = | string | number | null + | BigInt | Uint8Array | Int8Array | ArrayBuffer; @@ -17,7 +18,7 @@ declare type SQLiteDataType = /** Specifies parameter bindings. */ declare type BindingSpec = - | SqlValue[] + | readonly SqlValue[] | { [paramName: string]: SqlValue } /** Assumed to have binding index `1` */ | SqlValue; @@ -45,7 +46,7 @@ declare type FlexibleString = * string literals with the backtick syntax, it is frequently convenient to * write out longer SQL constructs as arrays. */ - | string[]; + | readonly string[]; /** * Prepared statements are created solely through the {@link Database#prepare} @@ -2995,16 +2996,16 @@ declare type WASM_API = { * calls, however, this variant is arguably more efficient because it will * hypothetically free the wrapper function quickly. */ - xCallWrappe( + xCallWrapped( functionName: string, resultType: string, - argTypes: string[], + argTypes: readonly string[], ...args: any[] ): any; xCallWrapped( functionName: string, resultType: string, - argTypes: string[], + argTypes: readonly string[], args: any[], ): any; @@ -3200,12 +3201,12 @@ declare type WASM_API = { xWrap( functionName: string, resultType: string | undefined, - ...argTypes: string[] + ...argTypes: readonly string[] ): Function; xWrap( functionName: string, resultType: string | undefined, - argTypes: string[], + argTypes: readonly string[], ): Function; /* -------------------------------------------------------------------------- @@ -4214,7 +4215,7 @@ declare type CAPI = { blob: | WasmPointer | string - | string[] + | readonly string[] | Int8Array | Uint8Array | ArrayBuffer, @@ -4305,7 +4306,7 @@ declare type CAPI = { text: | string | WasmPointer - | string[] + | readonly string[] | Int8Array | Uint8Array | ArrayBuffer,