Skip to main content
A Statement object holds a compiled SQL statement. It can be executed multiple times with different bound parameters without recompiling the SQL. Obtain a statement by calling db.prepare(sql):
const stmt = db.prepare('SELECT * FROM users WHERE id = ?');

stmt.run(...bindParameters)

Executes the statement and returns an info object. Primarily used for INSERT, UPDATE, and DELETE statements.
const info = await stmt.run(42);
console.log(info.changes);        // number of rows modified
console.log(info.lastInsertRowid); // rowid of the last inserted row
bindParameters
any[]
Positional parameter values to bind. Each ? placeholder in the SQL is replaced in order.
Returns { changes: number, lastInsertRowid: number }
changes
number
Number of rows inserted, updated, or deleted by the statement.
lastInsertRowid
number
The rowid of the last row inserted into the database. This value is connection-scoped and reflects the most recent INSERT on the same connection, not necessarily from this statement.

stmt.get(...bindParameters)

Executes the statement and returns the first result row as a plain object, or undefined if no rows were returned.
const user = await stmt.get(1);
console.log(user); // { id: 1, name: 'Alice' } or undefined
bindParameters
any[]
Positional parameter values to bind.
Returns object | undefined — a row object whose properties correspond to column names, or undefined when no row matches.

stmt.all(...bindParameters)

Executes the statement and returns all result rows as an array of objects.
const rows = await stmt.all();
for (const row of rows) {
  console.log(row.id, row.name);
}
bindParameters
any[]
Positional parameter values to bind.
Returns object[] — an array of row objects. Returns an empty array when no rows match.

stmt.iterate(...bindParameters)

Executes the statement and returns a synchronous iterator over the result rows. Useful for processing large result sets without loading all rows into memory at once.
const iter = stmt.iterate();
for (const row of iter) {
  console.log(row.id, row.name);
}
bindParameters
any[]
Positional parameter values to bind.
Returns Iterator<object> — an iterator that yields one row object per step.

stmt.bind_at(index, value)

Binds a single value at a 1-based parameter index. Used when building bind parameters incrementally.
index
number
required
The 1-based index of the parameter to bind.
value
any
required
The value to bind. Accepted types: null, number, BigInt, string, boolean, Buffer, Uint8Array.

stmt.parameter_count()

Returns the number of bind parameters in the statement. Returns number

stmt.parameter_name(index)

Returns the name of the parameter at the given 1-based index, or null for anonymous (?) parameters.
index
number
required
The 1-based parameter index.
Returns string | null

stmt.reset()

Resets the statement back to its initial state so it can be re-executed.

stmt.raw(toggle?)

Switches the presentation mode to raw (array) mode. In raw mode, rows are returned as arrays rather than objects.
toggle
boolean
default:"true"
Pass false to revert to expanded (object) mode.

stmt.pluck(toggle?)

Switches the presentation mode to pluck mode. In pluck mode, only the value of the first column is returned per row.
toggle
boolean
default:"true"
Pass false to revert to expanded mode.

stmt.safeIntegers(toggle?)

Controls whether 64-bit integer columns are returned as BigInt (safe mode) or number (default).
toggle
boolean
default:"true"
Pass false to disable safe integers for this statement.

stmt.columns()

Returns an array of column descriptor objects for the result set. Returns Array<{ name: string, type: string | null, column: null, table: null, database: null }>

stmt.finalize()

Finalizes the statement, releasing all associated resources. The statement cannot be used after this call.

Row object

By default, rows are returned as plain JavaScript objects with one property per column:
// Given: SELECT id, name FROM users
// Row object:
{ id: 1, name: 'Alice' }
Integer columns wider than 53 bits are returned as number by default, which may lose precision. Use stmt.safeIntegers(true) or db.defaultSafeIntegers(true) to receive them as BigInt instead. Blob columns are returned as Buffer in Node.js and as Uint8Array in browser/WASM environments.

stmt.bind(...bindParameters)

Permanently binds parameters to the statement. After calling bind(), the statement can be executed without passing parameters each time.
bindParameters
...any
Parameters to permanently bind to the statement. Uses the same format as other execution methods.
Returns this — for chaining.
const stmt = db.prepare('SELECT * FROM users WHERE id = ?');
stmt.bind(1);
const user = stmt.get(); // no need to pass params again

Unsupported methods

The following better-sqlite3 Statement methods are not yet implemented.
MethodStatus
stmt.expand(toggle?)Not supported
stmt.timed(toggle?)Not supported

Build docs developers (and LLMs) love