Skip to content

BetterSqlite3

src/BetterSqlite3.res
type any = String(string) | Boolean(bool) | Number(float)

src/BetterSqlite3.res:2:12


src/BetterSqlite3.res
type parameters =
| Array(array<any>)
| Record(RescriptCore.Dict.t<any>)

src/BetterSqlite3.res:3:12


src/BetterSqlite3.res:1:8


src/BetterSqlite3.res
type database = {
memory: bool,
readonly: bool,
name: string,
open_: bool,
inTransaction: bool,
}

src/BetterSqlite3.res:6:1


src/BetterSqlite3.res
type statement<'a>

src/BetterSqlite3.res:14:1


src/BetterSqlite3.res
type transaction = {
default: Utils.parameters => unknown,
deferred: Utils.parameters => unknown,
immediate: Utils.parameters => unknown,
exclusive: Utils.parameters => unknown,
}

src/BetterSqlite3.res:15:1


src/BetterSqlite3.res
type t = database

src/BetterSqlite3.res:23:3


src/BetterSqlite3.res
type options = {
readonly?: bool,
fileMustExist?: bool,
timeout?: int,
verbose?: string => unit,
}

src/BetterSqlite3.res:24:3


src/BetterSqlite3.res
type optionsBackupProgress = {
totalPages: int,
remainingPages: int,
}

src/BetterSqlite3.res:34:3


src/BetterSqlite3.res
let make: (string, ~options: options=?) => t

src/BetterSqlite3.res:42:7


src/BetterSqlite3.res
let prepareUnknown: (database, string) => statement<unknown>

Creates a new prepared Statement from the given SQL string.

src/BetterSqlite3.res:45:7


src/BetterSqlite3.res
let prepare: (database, string, 'a) => statement<'a>

Creates a new prepared Statement from the given SQL string.

src/BetterSqlite3.res:47:7


src/BetterSqlite3.res
let transaction: (database, 'a => unit) => transaction

Creates a function that always runs inside a transaction. When the function is invoked, it will begin a new transaction. When the function returns, the transaction will be committed. If an exception is thrown, the transaction will be rolled back (and the exception will propagate as usual).

src/BetterSqlite3.res:50:7


src/BetterSqlite3.res
let pragma: (t, string) => unit

Executes the given PRAGMA.

src/BetterSqlite3.res:53:7


src/BetterSqlite3.res
let pragmaWithResult: (t, string, 'result) => array<'result>

Executes the given PRAGMA and returns its result. The return value will be an array of result rows. Each row is represented by an object whose keys correspond to column names.

src/BetterSqlite3.res:55:7


src/BetterSqlite3.res
let pragmaWithSimpleResult: (t, string, 'result) => 'result

Executes the given PRAGMA and returns its result. Since most PRAGMA statements return a single value, the simple option is provided to make things easier. When simple is true, only the first column of the first row will be returned.

src/BetterSqlite3.res:57:7


src/BetterSqlite3.res
type optionsBackup = {progress: unit => int}

You can monitor the progress of the backup by setting the progress option to a callback function. That function will be invoked every time the backup makes progress, providing an object with two properties:

.totalPages: the total number of pages in the source database (and thus, the number of pages that the backup will have when completed) at the time of this progress report.
.remainingPages: the number of pages that still must be transferred before the backup is complete.

src/BetterSqlite3.res:69:3


src/BetterSqlite3.res
let backup: (database, string) => promise<unit>

Initiates a backup of the database, returning a promise for when the backup is complete. If the backup fails, the promise will be rejected with an Error.

src/BetterSqlite3.res:71:7


src/BetterSqlite3.res
let backupWithOptions: (database, string, optionsBackup) => promise<unit>

src/BetterSqlite3.res:72:7


src/BetterSqlite3.res
let function: (database, string, array<Utils.any> => 'result) => unit

Registers a user-defined function so that it can be used by SQL statements.

src/BetterSqlite3.res:79:7


src/BetterSqlite3.res
type optionsAggregate<'n, 'collect, 'result> = {
start: unit => 'collect,
step: ('collect, 'n) => 'collect,
result?: 'collect => 'result,
}

src/BetterSqlite3.res:85:3


src/BetterSqlite3.res
let aggregate: (
database,
string,
optionsAggregate<'n, 'collect, 'result>,
) => promise<unit>

Registers a user-defined aggregate function.

src/BetterSqlite3.res:91:7


src/BetterSqlite3.res
type optionsTable = {
columns: array<string>,
parameters?: array<string>,
rows: option<array<string>> => RescriptCore.Dict.t<
Utils.any,
>,
}

src/BetterSqlite3.res:97:3


src/BetterSqlite3.res
let table: (database, string, optionsTable) => unit

Registers a virtual table. Virtual tables can be queried just like real tables, except their results do not exist in the database file; instead, they are calculated on-the-fly by a generator function in JavaScript.

src/BetterSqlite3.res:103:7


src/BetterSqlite3.res
let exec: (database, string) => unit

Executes the given SQL string. Unlike prepared statements, this can execute strings that contain multiple SQL statements. This function performs worse and is less safe than using prepared statements. You should only use this method when you need to execute SQL from an external source (usually a file). If an error occurs, execution stops and further statements are not executed. You must rollback changes manually.

src/BetterSqlite3.res:110:7


src/BetterSqlite3.res
let close: database => unit

Closes the database connection. After invoking this method, no statements can be created or executed.

src/BetterSqlite3.res:113:7


src/BetterSqlite3.res:1:1


src/BetterSqlite3.res
type t<'a> = statement<'a>

An object representing a single SQL statement.

src/BetterSqlite3.res:118:3


src/BetterSqlite3.res
type infoResult = {changes: int, lastInsertRowid: int}

The info object has two properties:

info.changes: the total number of rows that were inserted, updated, or deleted by this operation. Changes made by foreign key actions or trigger programs do not count.
info.lastInsertRowid: the rowid of the last row inserted into the database (ignoring those caused by trigger programs). If the current statement did not insert any rows into the database, this number should be completely ignored.

src/BetterSqlite3.res:126:3


src/BetterSqlite3.res
let run: (statement<unknown>, Utils.parameters) => infoResult

Executes the prepared statement. When execution completes it returns an info object describing any changes made.
If execution of the statement fails, an Error is thrown.
You can specify bind parameters, which are only bound for the given execution.

src/BetterSqlite3.res:135:7


src/BetterSqlite3.res
let get: (statement<'result>, Utils.parameters) => option<'result>

Executes the prepared statement. When execution completes it returns an object that represents the first row retrieved by the query. The object's keys represent column names.

If the statement was successful but found no data, undefined is returned. If execution of the statement fails, an Error is thrown.

You can specify bind parameters, which are only bound for the given execution.

src/BetterSqlite3.res:144:7


src/BetterSqlite3.res
let all: (statement<'result>, Utils.parameters) => array<'result>

Similar to .get(), but instead of only retrieving one row all matching rows will be retrieved. The return value is an array of row objects.

If no rows are found, the array will be empty. If execution of the statement fails, an Error is thrown.

You can specify bind parameters, which are only bound for the given execution.

src/BetterSqlite3.res:153:7


src/BetterSqlite3.res
let iterate: (
statement<'result>,
Utils.parameters,
) => RescriptCore.Iterator.t<'result>

Similar to .all(), but instead of returning every row together, an iterator is returned so you can retrieve the rows one by one. If you plan on retrieving every row anyways, .all() will perform slightly better.

If execution of the statement fails, an Error is thrown and the iterator is closed.

You can specify bind parameters, which are only bound for the given execution.

src/BetterSqlite3.res:162:7


src/BetterSqlite3.res
let pluck: statement<'result> => statement<'result>

Causes the prepared statement to only return the value of the first column of any rows that it retrieves, rather than the entire row object.

src/BetterSqlite3.res:168:7


src/BetterSqlite3.res
let expand: statement<'result> => statement<'result>

Causes the prepared statement to return data namespaced by table. Each key in a row object will be a table name, and each corresponding value will be a nested object that contains the associated column data. This is useful when performing a JOIN between two tables that have overlapping column names. If a result column is an expression or subquery, it will be available within the special $ namespace.

src/BetterSqlite3.res:171:7


src/BetterSqlite3.res
let raw: statement<'result> => statement<array<Utils.any>>

Causes the prepared statement to return rows as arrays instead of objects. This is primarily used as a performance optimization when retrieving a very high number of rows. Column names can be recovered by using the .columns() method.

src/BetterSqlite3.res:174:7


src/BetterSqlite3.res
type columnDefinition = {
name: string,
column: option<string>,
table: option<string>,
database: option<string>,
type_: option<string>,
}

src/BetterSqlite3.res:176:3


src/BetterSqlite3.res
let columns: statement<'result> => array<columnDefinition>

This method is primarily used in conjunction with raw mode. It returns an array of objects, where each object describes a result column of the prepared statement.

src/BetterSqlite3.res:185:7


src/BetterSqlite3.res:116:8