bungibindies/bun/sqlite
Bun:sqlite
module
Types
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)
Values
pub fn all(
statement: Statement,
params: Array(Dynamic),
) -> Array(Dynamic)
pub fn close(db: Database) -> Nil
pub fn exec(db: Database, query: String) -> RunResult
- Sqlite
Use the db.exec()
method on your Database
instance to execute a SQL query. The result is a RunResult
instance.
pub fn get(
statement: Statement,
params: Array(Dynamic),
) -> Dynamic
pub fn new(to: String) -> Database
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 theDatabase
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 theDatabase
instance.
pub fn run(
statement: Statement,
params: Array(Dynamic),
) -> RunResult
- 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.