bungibindies/bun/sqlite

Bun:sqlite module

Types

The Database type is an instance of a database collection.

pub type Database

The RunResult type is an object with two properties: lastInsertRowid and changes. It is emitted by the run function.

pub type RunResult {
  RunResult(last_insert_row_id: Int, changes: Int)
}

Constructors

  • RunResult(last_insert_row_id: Int, changes: Int)

A Statement is a prepared query, which means it’s been parsed and compiled into an efficient binary form. It can be executed multiple times in a performant way.

pub type Statement

Functions

pub fn all(
  statement: Statement,
  params: ParamArray,
) -> Array(Dynamic)

all

  • Sqlite

Use .all() to run a query and get back the results as an array of objects.

pub fn close(db: Database) -> Nil

close()

  • Sqlite

Use .close() to close the database connection.

pub fn get(statement: Statement, params: ParamArray) -> Dynamic

get

  • Sqlite

Use .get() to run a query and get back the first result as an object.

pub fn new(to: String) -> Database

bun:sqlite.Database -> New()

  • Sqlite

Create a new database connection

pub fn prepare(db: Database, query: String) -> Statement

bun:sqlite.Statement -> prepare()

  • Sqlite

Use the db.prepare() method on your Database instance to prepare a SQL query. The result is a Statement instance that will NOT be cached on the Database instance. _The query will not be executed.

Note — Use the .query() method to prepare a query with caching it on the Database instance.

pub fn query(db: Database, query: String) -> Statement

bun:sqlite.Database -> query()

  • Sqlite

Use the db.query() method on your Database instance to prepare a SQL query. The result is a Statement instance that will be cached on the Database instance. _The query will not be executed.

Note — Use the .prepare() method to prepare a query without caching it on the Database instance.

pub fn run(statement: Statement, params: ParamArray) -> RunResult

bun:sqlite.run()

  • Sqlite

Use .run() to run a query and get back a RunResult. This is useful for schema-modifying queries (e.g. CREATE TABLE) or bulk write operations.

Internally, this calls sqlite3_reset and calls sqlite3_step once. Stepping through all the rows is not necessary when you don’t care about the results. The lastInsertRowid property returns the ID of the last row inserted into the database. The changes property is the number of rows affected by the query.

Search Document