run

Bun

Symbol

Database.run

run<ParamsType extends SQLQueryBindings[]>(sql: string, ...bindings: ParamsType[]): Changes

Execute a SQL query without returning any results.

This does not cache the query, so if you want to run a query multiple times, you should use prepare instead.

Under the hood, this calls sqlite3_prepare_v3 followed by sqlite3_step and sqlite3_finalize.

The following types can be used when binding parameters:

JavaScript typeSQLite type
stringTEXT
numberINTEGER or DECIMAL
booleanINTEGER (1 or 0)
Uint8ArrayBLOB
BufferBLOB
bigintINTEGER
nullNULL
@param sql

The SQL query to run

@param bindings

Optional bindings for the query

@returns

Database instance

db.run("CREATE TABLE foo (bar TEXT)");
db.run("INSERT INTO foo VALUES (?)", ["baz"]);

Useful for queries like:

  • CREATE TABLE
  • INSERT INTO
  • UPDATE
  • DELETE FROM
  • DROP TABLE
  • PRAGMA
  • ATTACH DATABASE
  • DETACH DATABASE
  • REINDEX
  • VACUUM
  • EXPLAIN ANALYZE
  • CREATE INDEX
  • CREATE TRIGGER
  • CREATE VIEW
  • CREATE VIRTUAL TABLE
  • CREATE TEMPORARY TABLE

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.