method
sqlite.Database.run
sql: string,
...bindings: ParamsType[]
Execute a SQL query without returning any results.
This does not cache the query. To run a query multiple times, use prepare instead.
Internally, this calls sqlite3_prepare_v3 followed by sqlite3_step and sqlite3_finalize.
The following types can be used when binding parameters:
| JavaScript type | SQLite type |
|---|---|
string | TEXT |
number | INTEGER or DECIMAL |
boolean | INTEGER (1 or 0) |
Uint8Array | BLOB |
Buffer | BLOB |
bigint | INTEGER |
null | NULL |
Useful for queries like:
CREATE TABLEINSERT INTOUPDATEDELETE FROMDROP TABLEPRAGMAATTACH DATABASEDETACH DATABASEREINDEXVACUUMEXPLAIN ANALYZECREATE INDEXCREATE TRIGGERCREATE VIEWCREATE VIRTUAL TABLECREATE TEMPORARY TABLE
@param sql
The SQL query to run
@param bindings
Optional bindings for the query
@returns
A Changes object with changes and lastInsertRowid properties
db.run("CREATE TABLE foo (bar TEXT)");
db.run("INSERT INTO foo VALUES (?)", ["baz"]);
// => { changes: 1, lastInsertRowid: 1 }Referenced types
interface Changes
An object representing the changes made to the database since the last run or exec call.
- lastInsertRowid: number | bigint
The
rowidof the most recently inserted row.If
safeIntegersistrue, this is abigint. Otherwise, it is anumber.