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):
stmt.run(...bindParameters)
Executes the statement and returns an info object. Primarily used for INSERT, UPDATE, and DELETE statements.
Positional parameter values to bind. Each
? placeholder in the SQL is replaced in order.{ changes: number, lastInsertRowid: number }
Number of rows inserted, updated, or deleted by the statement.
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.
Positional parameter values to bind.
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.
Positional parameter values to bind.
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.
Positional parameter values to bind.
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.
The 1-based index of the parameter to bind.
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.
The 1-based parameter index.
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.
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.
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).
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: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.
Parameters to permanently bind to the statement. Uses the same format as other execution methods.
this — for chaining.
Unsupported methods
The following
better-sqlite3 Statement methods are not yet implemented.| Method | Status |
|---|---|
stmt.expand(toggle?) | Not supported |
stmt.timed(toggle?) | Not supported |