API reference › @evolu/sqlite-wasm

Modules

ModuleDescription
c-apiSQLite's C API as the wasm exports it: the C-named functions, the SQLITE_* constants, and the struct layouts.

Interfaces

InterfaceDescription
OpfsDirectoryHandleThe part of FileSystemDirectoryHandle the pool uses.
OpfsFileHandleThe part of FileSystemFileHandle the pool uses.
OpfsNameErrorError returned when a string is not a valid OpfsName.
OpfsRootAccess to the OPFS root, which navigator.storage provides in a dedicated worker.
OpfsRootDepDependency wrapper for OpfsRoot.
OpfsSyncAccessHandleThe part of FileSystemSyncAccessHandle the pool uses.
SahPoolA pool of sync access handles, and the VFS SQLite opens its files with, on which File and EncryptedFile databases open.
SahPoolAlreadyOpenErrorThis instance has a pool in the directory open, or is opening one. A retry succeeds once that pool is disposed or its open failed.
SahPoolFileNotFoundErrorThe pool has no file with the path.
SahPoolFullErrorNo slot of the pool is free for a new file, which xOpen records when it fails with SQLITE_CANTOPEN.
SahPoolHeldErrorAnother context or instance holds a slot of the pool. The pool wrote nothing, and a retry succeeds once the slot is released.
SahPoolInvalidPathErrorA name xOpen, xDelete or xAccess cannot map to a pool path, because the suffix SQLite appends would land in its query, fragment or host, which would map a database and its journal to the same file. xOpen also records it for a path that would not fit a slot's header, or a database's path whose super-journal's path would not.
SahPoolOptionsOptions for openSahPool.
SahPoolSetupErrorOPFS failed while the pool was being set up, or its VFS could not be registered.
SqliteCodecFailureThe first failure Evolu's codec recorded for the main database of a File or EncryptedFile connection since the top-level operation started. It has no method or path, because the codec records a failure of the database's journal on the database.
SqliteDatabaseAn open SQLite database. Disposing it while one of its operations runs, as from a callback, throws.
SqliteEmptySqlErrorThe SQL contains no statement, only whitespace or comments.
SqliteEncryptedDatabaseThe result of createEncryptedSqliteDatabase.
SqliteEncryptedFileDatabaseOptionsA database file on a SahPool that Evolu's codec encrypts, in the format of SQLite3 Multiple Ciphers' sqlcipher scheme.
SqliteEncryptionUnsupportedErrorWhat Evolu's codec refuses because it cannot keep a database encrypted, or because a database keyed through SQL would stay plaintext. For an encrypted database, a read or write that is not a whole page, a page 1 that would change the page size or the reserved bytes, as a VACUUM that changes the page size writes it, turning secure_delete off, or the hot journal of one opened without its key, which fails with SQLITE_CANTOPEN and stays for the key. For any database on a pool, the keying pragmas, such as PRAGMA key, and a page 1 that says WAL.
SqliteErrorAn error SQLite reported.
SqliteFileDatabaseOptionsAn unencrypted database file on a SahPool.
SqliteInvalidSqlTextErrorThe SQL is text SQLite would read as other SQL, so it fails before SQLite sees it: it contains a NUL character, which SQLite reads SQL only up to, so it would silently ignore the rest, or a lone surrogate, which UTF-8 cannot encode, so it would run with U+FFFD in its place.
SqliteMemoryDatabaseOptionsAn in-memory database on the default VFS, which never touches OPFS. Temporary tables and indexes stay in memory in every mode.
SqliteMultipleStatementsErrorThe SQL contains more than one statement.
SqliteNoMemErrorsqlite3_malloc returned NULL.
SqlitePageAuthenticationErrorA page of an encrypted database or its journal that failed to authenticate, because the key is wrong or the page was altered or cut short, as Evolu's codec records it.
SqliteParameterCountErrorA run supplied a different number of parameters than the SQL has, or SqliteDatabase.exec, which supplies none, met a statement with parameters.
SqliteRandomSourceErrorThe random source failed while Evolu's codec encrypted a page, so the write failed with SQLITE_IOERR_WRITE. What the source threw went to the instance's ReportDefect.
SqliteRunResultThe result of SqliteStatement.run.
SqliteScratchReusable memory for output parameters and bind values, allocated once per database instead of once per call.
SqliteShortWriteErrorA write that stored fewer or more bytes than requested.
SqliteStatementA prepared statement. Running or disposing it during its own run, as from a callback, throws.
SqliteVfsFailureA failure a pool's method recorded before returning an error code.
SqliteVfsIoErrorThe storage of a pool failed outside SQLite, as when SahPool.unlink deletes a file.
SqliteVfsPathErrorError returned when a string is not a valid SqliteVfsPath.
SqliteWasmA loaded SQLite wasm instance.
SqliteWasmBuildMismatchErrorThe binary's sqliteWasmBuildHash differs, so it is not the build the generated code describes.
SqliteWasmCompileErrorThe source could not be fetched, compiled or instantiated, its memory could not be allocated, its static constructors failed, or the module that installs the default VFS's methods could not be compiled.
SqliteWasmDepDependency wrapper for SqliteWasm.
SqliteWasmFunctionA JavaScript function to install into the function table.
SqliteWasmFunctionsFunctions installed by installWasmFunctions.
SqliteWasmInitializeErrorsqlite3_initialize failed, or allocating, finding or registering the default VFS did, for example when out of memory.
SqliteWasmUnknownImportErrorThe binary declares imports the loader does not implement.
SubtleCryptoDepWebCrypto, which derives legacy keys.

Type Aliases

Type AliasDescription
CStringPtrA NUL-terminated UTF-8 string.
NullPtrThe C NULL pointer.
OpfsNameThe name of a file or directory in OPFS, a valid file name of the File System Standard on every platform in one spelling: not empty, not . or .., without / or ``, which is a path separator on Windows, without NUL or a lone surrogate, and in Unicode NFC.
SahPoolErrorWhy openSahPool failed.
SqliteBackupPtrAn online backup from one connection's database to another's, sqlite3_backup*.
SqliteCodecErrorWhat Evolu's codec found wrong.
SqliteContextPtrThe context of an application-defined function call, sqlite3_context*.
SqliteDatabaseOptionsHow to open a database.
SqliteDbPtrAn open database connection, sqlite3*.
SqliteDestructorThe destructor argument of sqlite3_bind_text, sqlite3_bind_blob, sqlite3_result_text and sqlite3_result_blob.
SqliteExecErrorWhy SqliteDatabase.exec failed.
SqliteFailureA failure the pool or Evolu's codec recorded, which SqliteError carries.
SqliteFilenamePtrA database filename SQLite created, sqlite3_filename, as xOpen receives it.
SqliteFilePtrA file SQLite opened through a VFS, sqlite3_file*.
SqliteFunctionPtrA C function pointer, which in wasm is an index into the function table, not a memory address.
SqliteIndexInfoPtrThe query planner's exchange with a virtual table's xBestIndex, sqlite3_index_info*.
SqliteKeyDerivationWhich key opened an encrypted database: the raw key, or the key 2.2.4 derived from it because of a bug in SQLite3 Multiple Ciphers, which deriveLegacySqliteKey describes.
SqliteOperationThe operation a SqliteError comes from.
SqliteOwnedCStringPtrA NUL-terminated UTF-8 string in memory allocated with sqlite3_malloc, which the holder frees with sqlite3_free.
SqliteOwnedPtrMemory allocated with sqlite3_malloc.
SqliteOwnedValuePtrA protected value copied with sqlite3_value_dup, which the holder frees with sqlite3_value_free.
SqlitePrepareErrorWhy SqliteDatabase.prepare failed.
SqliteRunErrorWhy SqliteStatement.run failed.
SqliteStmtPtrA prepared statement, sqlite3_stmt*.
SqliteValuePtrA dynamically typed SQL value, sqlite3_value*, such as a column value or an argument of an application-defined function.
SqliteVfsMethodA VFS or I/O method that can record a SqliteVfsFailure.
SqliteVfsPathThe canonical path of a database file on a SahPool, such as /evolu1.db, one spelling per file, as SahPool.getPaths lists it.
SqliteVfsPtrA VFS struct, sqlite3_vfs*.
SqliteWasmErrorWhy createSqliteWasm failed.
SqliteWasmSourceThe wasm binary, compiled or not.
WasmPtrAn address in the wasm heap.

Variables

VariableDescription
maxInt32The largest C int.
maxSqliteInt64The largest SQLite INTEGER, 2^63 - 1.
minSqliteInt64The smallest SQLite INTEGER, -2^63.
OpfsNameThe name of a file or directory in OPFS, a valid file name of the File System Standard on every platform in one spelling: not empty, not . or .., without / or ``, which is a path separator on Windows, without NUL or a lone surrogate, and in Unicode NFC.
sahPoolDefaultCapacityThe number of slots setup ensures: a database, its journal, and spares.
sahPoolDigestV2FlagThe flag that marks a header digest as version 2.
sahPoolHeaderCorpusSizeThe size of the path and flags, which the digest covers.
sahPoolHeaderDigestOffsetWhere the header's digest, two platform-endian u32 values, starts.
sahPoolHeaderFlagsOffsetWhere the header's big-endian u32 flags start, after the path.
sahPoolHeaderPathSizeThe bytes reserved for the NUL-padded path at the start of the header.
sahPoolHeaderSizeThe size of a slot's header, where the file's data starts.
sahPoolMaxDatabasePathSizeThe longest path of a database a pool opens, in UTF-8 bytes, 498. SQLite names the other files of a database by appending a suffix to its path, at most the 12 bytes of a super-journal's -mjXXXXXX9XX, and each path must fit a slot's header with its NUL, as opfs-sahpool requires, which allows 510 bytes.
sahPoolOpaqueDirectoryNameThe pool subdirectory that holds the slots. Renaming it orphans them.
sahPoolPersistentFileTypesThe file types that persist across sessions: SQLITE_OPEN_MAIN_DB, SQLITE_OPEN_MAIN_JOURNAL, SQLITE_OPEN_SUPER_JOURNAL and SQLITE_OPEN_WAL, combined. A slot with another type is freed at setup.
SqliteVfsPathThe canonical path of a database file on a SahPool, such as /evolu1.db, one spelling per file, as SahPool.getPaths lists it.
sqliteWasmUrlThe URL of the wasm binary the package ships, to load with createSqliteWasm.

Functions

FunctionDescription
allocCStringCopies a string into new memory as a NUL-terminated UTF-8 C string, which the caller frees with sqlite3_free.
allocWasmAllocates at least one byte with sqlite3_malloc, so a zero-length value keeps a non-NULL address.
computeSahPoolDigestComputes the digest of a header's first sahPoolHeaderCorpusSize bytes, as opfs-sahpool does.
copyWasmBytesCopies bytes out of wasm memory into a new ArrayBuffer, so the result can be transferred to another worker.
createEncryptedSqliteDatabaseOpens an EncryptedFile database on a pool, falling back to the key @evolu/sqlite-wasm 2.2.4 derived.
createSqliteDatabaseOpens a database.
createSqliteScratchCreates a SqliteScratch.
createSqliteWasmLoads the wasm, following the steps in the module documentation.
deriveLegacySqliteKeyDerives the key @evolu/sqlite-wasm 2.2.4 used: PBKDF2-HMAC-SHA512 with 256000 iterations and a 32-byte output, over the UTF-8 text x' followed by the key in lowercase hex and ', salted with the database's first 16 bytes.
initializeSqliteWasmInitializes the library as loading steps 6 and 7 do, for use after sqlite3_shutdown and sqlite3_config.
installWasmFunctionsInstalls functions into the function table.
isInt32Whether a number is a 32-bit integer, which binds with sqlite3_bind_int without a BigInt.
isSqliteInt64Whether a bigint fits a SQLite INTEGER.
openSahPoolOpens the pool in a directory, registering its VFS on first use.
readCStringDecodes a NUL-terminated C string, such as an error message or a column name.
readUtf8Decodes UTF-8 of a known byte length, such as a text column, keeping a leading byte order mark and embedded NUL characters.
sqliteResultCodeToPrimaryReturns the primary result code of a result code, its low 8 bits, such as SQLITE_CONSTRAINT for SQLITE_CONSTRAINT_NOTNULL. A primary result code returns itself.
writeUtf8Encodes a string as UTF-8 into existing memory and returns the byte length, without a NUL terminator.
writeWasmBytesCopies bytes into wasm memory.

References

SqlitePrimaryResultCode

Re-exports SqlitePrimaryResultCode


SqliteResultCode

Re-exports SqliteResultCode