method

sqlite.Statement.run

...params: ParamsType

Execute the prepared statement.

@param params

optional values to bind to the statement. If omitted, the statement is run with the last bound values or no parameters if there are none.

@returns

A Changes object with changes and lastInsertRowid properties

const insert = db.prepare("INSERT INTO users (name) VALUES (?)");
insert.run("Alice");
// => { changes: 1, lastInsertRowid: 1 }
insert.run("Bob");
// => { changes: 1, lastInsertRowid: 2 }

const update = db.prepare("UPDATE users SET name = ? WHERE id = ?");
update.run("Charlie", 1);
// => { changes: 1, lastInsertRowid: 2 }

The following types can be used when binding parameters:

JavaScript typeSQLite type
stringTEXT
numberINTEGER or REAL
booleanINTEGER (1 or 0)
Uint8ArrayBLOB
BufferBLOB
bigintINTEGER
nullNULL

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 run or exec call inserted, updated, or deleted itself.

    Rows that a trigger or a foreign key action such as ON DELETE CASCADE changes do not count. Database.run with several statements in one string reports their sum.

  • lastInsertRowid: number | bigint

    The rowid of the most recently inserted row.

    If safeIntegers is true, this is a bigint. Otherwise, it is a number.