Mrun
Bun

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 DECIMAL
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 changed by the last run or exec call.

  • lastInsertRowid: number | bigint

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