Library
Module
Module type
Parameter
Class
Class type
module Data = Sqlite3.Data
module Rc = Sqlite3.Rc
type db = Sqlite3.db
exception RcError of Rc.t
Exception raised by most of the functions below when a Sqlite failure occurs, with the corresponding error code.
exception Type_error of Data.t
Exception raised when the declared Ty.t
does not match the actual result returned by Sqlite.
type t = db
Alias for the DB connection
val check_ret_exn : Rc.t -> unit
Check return code.
val err_string : ('a, Rc.t) Stdlib.result -> ('a, string) Stdlib.result
Turn the error into a string using Rc.to_string
val setup_timeout : ?ms:int -> t -> unit
on "busy", wait ms
milliseconds before failing.
val with_db :
?mode:[ `NO_CREATE | `READONLY ] ->
?mutex:[ `FULL | `NO ] ->
?cache:[ `PRIVATE | `SHARED ] ->
?vfs:string ->
?timeout:int ->
string ->
(t -> 'a) ->
'a
Temporarily open a DB connection. Parameters follow Sqlite3.db_open
.
module Ty : sig ... end
Values representing types to pass to a statement, or to extract from a row
A Cursor is a special iterator over Sqlite rows of results. It should be consumed quickly as it will not survive the call to exec
, exec_raw
, etc.
module Cursor : sig ... end
val with_stmt : t -> string -> f:(Sqlite3.stmt -> 'a) -> 'a
Locally make a statement out of the given string, then cleanup when f
returns.
Run the query purely for its side effects, without any parameter. If you need to parametrize this with user inputs, use exec_raw
or exec_raw_args
or exec_no_cursor
to use a safe parametrized statement instead of builtin a string that is vulnerable to SQL injections.
Same as exec_raw
but uses check_ret_exn
to unwrap errors.
val exec_raw_args :
t ->
string ->
Sqlite3.Data.t array ->
f:(Data.t array Cursor.t -> 'b) ->
('b, Rc.t) Stdlib.result
Similar to exec_raw
but also takes an array of parameters that will fill the ?
placeholders of the prepare statement.
val exec_raw_args_exn :
t ->
string ->
Sqlite3.Data.t array ->
f:(Data.t array Cursor.t -> 'b) ->
'b
Same as exec_raw_args
but uses check_ret_exn
to unwrap errors.
val exec :
t ->
string ->
ty:(('a, ('res, Rc.t) Stdlib.result) Ty.t * ('b, 'c) Ty.t * 'b) ->
f:('c Cursor.t -> 'res) ->
'a
Typesafe alternative to exec_raw_args
.
val exec_exn :
t ->
string ->
ty:(('a, 'res) Ty.t * ('b, 'c) Ty.t * 'b) ->
f:('c Cursor.t -> 'res) ->
'a
Same as exec
but uses check_ret_exn
to unwrap the result.
val exec_no_params :
t ->
string ->
ty:(('b, 'c) Ty.t * 'b) ->
f:('c Cursor.t -> 'res) ->
('res, Rc.t) Stdlib.result
Same as exec
but without parameters. ty
only takes two arguments: the type description for result rows, and a function to map rows to 'c
Same as exec_no_params_exn
but uses check_ret_exn
to unwrap the result.
Perform a query that doesn't return any result.
Same as exec_no_cursor_exn
but uses check_ret_exn
to unwrap the result.
transact db f
runs f db
within a transaction (begin/commit/rollback). Useful to perform a batch of insertions or updates, as Sqlite doesn't write very fast.