method
sqlite.Database.run
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 string can hold several statements, separated by ;. They run in order, and the first one gets the bindings. The first statement that fails throws, and the statements after it do not run.
The following types can be used when binding parameters:
| JavaScript type | SQLite type |
|---|---|
string | TEXT |
number | INTEGER or REAL |
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
The SQL query to run
Optional bindings for the query
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.
- changes: number
The number of rows that the last
runorexeccall inserted, updated, or deleted itself.Rows that a trigger or a foreign key action such as
ON DELETE CASCADEchanges do not count. Database.run with several statements in one string reports their sum. - lastInsertRowid: number | bigint
The
rowidof the most recently inserted row.If
safeIntegersistrue, this is abigint. Otherwise, it is anumber.