Bind value to prepared statement
This convenience function calls the appropriate bind_*
function
based on the type of value
. Note that binding indices begin with 1.
prepared statement pointer
binding index
SQLITE_OK
(throws exception on error)
Bind a collection of values to a statement
This convenience function binds values from either an array or object to a prepared statement with placeholder parameters.
Array example using numbered parameters (numbering is implicit in this example):
const sql = 'INSERT INTO tbl VALUES (?, ?, ?)';
for await (const stmt of sqlite3.statements(db, sql) {
sqlite3.bind_collection(stmt, [42, 'hello', null]);
...
}
Object example using named parameters (':', '@', or '$' prefixes are allowed):
const sql = 'INSERT INTO tbl VALUES (?, ?, ?)';
for await (const stmt of sqlite3.statements(db, sql) {
sqlite3.bind_collection(stmt, {
'@foo': 42,
'@bar': 'hello',
'@baz': null,
});
...
}
Note that SQLite bindings are indexed beginning with 1, but when
binding values from an array a
the values begin with a[0]
.
prepared statement pointer
SQLITE_OK
(throws exception on error)
Call the appropriate column_*
function based on the column type
The type is determined by calling column_type, which may
not match the type declared in CREATE TABLE
. Note that if the column
value is a blob then as with column_blob
the result may be invalid
after the next SQLite call; copy if it needs to be retained.
Integer values are returned as Number if within the min/max safe integer bounds, otherwise they are returned as BigInt.
prepared statement pointer
column index
column value
Extract a column value from a row after a prepared statment step
The contents of the returned buffer may be invalid after the
next SQLite call. Make a copy of the data (e.g. with .slice()
)
if longer retention is required.
prepared statement pointer
column index
column value
Extract a column value from a row after a prepared statment step
prepared statement pointer
column index
column value
Extract a column value from a row after a prepared statment step
prepared statement pointer
column index
column value
Extract a column value from a row after a prepared statment step
prepared statement pointer
column index
column value
Get names for all columns of a prepared statement
This is a convenience function that calls column_count and column_name.
array of column names
Extract a column value from a row after a prepared statment step
prepared statement pointer
column index
column value
Create or redefine SQL functions
The application data passed is ignored. Use closures instead.
If any callback function returns a Promise, that function must
be declared async
, i.e. it must allow use of await
.
database pointer
number of function arguments
text encoding (and other flags)
application data (ignored)
Optional
xFunc: ((context, values) => void | Promise<void>)Optional
xStep: ((context, values) => void | Promise<void>)Optional
xFinal: ((context) => void | Promise<void>)SQLITE_OK
(throws exception on error)
One-step query execution interface
The implementation of this function uses row, which makes a copy of blobs and returns BigInt for integers outside the safe integer bounds for Number.
database pointer
queries
Optional
callback: ((row, columns) => void)called for each output row
Promise resolving to SQLITE_OK
(rejects on error)
Destroy a prepared statement object compiled by statements
with the unscoped
option set to true
This function does not throw on error.
prepared statement pointer
Promise resolving to SQLITE_OK
or error status
Opening a new database connection.
Note that this function differs from the C API in that it returns the Promise-wrapped database pointer (instead of a result code).
Optional
iFlags: numberSQLite.SQLITE_OPEN_CREATE | SQLite.SQLITE_OPEN_READWRITE
(0x6) if omitted
Optional
zVfs: stringVFS name
Promise-wrapped database pointer.
Specify callback to be invoked between long-running queries
The application data passed is ignored. Use closures instead.
If any callback function returns a Promise, that function must
be declared async
, i.e. it must allow use of await
.
database pointer
target number of database operations between handler invocations
Convenience function to call result_*
based of the type of value
context pointer
Get all column data for a row from a prepared statement step
This convenience function will return a copy of any blob, unlike column_blob which returns a value referencing volatile WASM memory with short validity. Like column, it will return a BigInt for integers outside the safe integer bounds for Number.
prepared statement pointer
row data
Register a callback function that is invoked to authorize certain SQL statement actions.
database pointer
SQL statement iterator
This function manages statement compilation by creating an async
iterator that yields a prepared statement handle on each iteration.
It is typically used with a for await
loop (in an async function),
like this:
// Compile one statement on each iteration of this loop.
for await (const stmt of sqlite3.statements(db, sql)) {
// Bind parameters here if using SQLite placeholders.
// Execute the statement with this loop.
while (await sqlite3.step(stmt) === SQLite.SQLITE_ROW) {
// Collect row data here.
}
// Change bindings, reset, and execute again if desired.
}
By default, the lifetime of a yielded prepared statement is managed
automatically by the iterator, ending at the end of each iteration.
finalize should not be called on a statement provided by
the iterator unless the unscoped
option is set to true
(that
option is provided for applications that wish to manage statement
lifetimes manually).
If using the iterator manually, i.e. by calling its next
method, be sure to call the return
method if iteration
is abandoned before completion (for await
and other implicit
traversals provided by Javascript do this automatically)
to ensure that all allocated resources are released.
database pointer
Optional
options: SQLitePrepareOptionsRegister an update hook
The callback is invoked whenever a row is updated, inserted, or deleted in a rowid table on this connection.
database pointer
updateType is one of:
Extract a value from sqlite3_value
This is a convenience function that calls the appropriate value_*
function based on its type. Note that if the value is a blob then as
with value_blob
the result may be invalid after the next SQLite call.
Integer values are returned as Number if within the min/max safe integer bounds, otherwise they are returned as BigInt.
sqlite3_value
pointer
value
Register a new Virtual File System.
VFS object
Optional
makeDefault: booleanSQLITE_OK
(throws exception on error)
Generated using TypeDoc
Javascript wrappers for the SQLite C API (plus a few convenience functions)
Function signatures have been slightly modified to be more Javascript-friendly. For the C functions that return an error code, the corresponding Javascript wrapper will throw an exception with a
code
property on an error.Note that a few functions return a Promise in order to accomodate either a synchronous or asynchronous SQLite build, generally those involved with opening/closing a database or executing a statement.
To create an instance of the API, follow these steps:
See
https://sqlite.org/c3ref/funclist.html