Library
Module
Module type
Parameter
Class
Class type
module Error : sig ... end
module Param : sig ... end
module Row : sig ... end
val with_conn :
host:string ->
db:string ->
user:string ->
password:string ->
?port:int ->
(t -> 'a Async_kernel.Deferred.t) ->
'a Async_kernel.Deferred.t
Opens a connection, runs the callback, then closes the connection. Don't try to use the DB handle outside of the callback, since it will have been closed automatically.
val execute :
?params:Mssql__.Db_field.t option list ->
t ->
string ->
Row.t list Async_kernel.Deferred.t
Executes an SQL query, handling parameter quoting for you. Do not use sprintf
to generate queries; instead pass parameters like this:
let params = [ Some (Mssql.Param.String "look no ' sql injection\x00!") ] in
Mssql.execute ~params "SELECT $1"
Returns a single result set and throws an exception if the result has more than one result set.
val execute_unit :
?params:Mssql__.Db_field.t option list ->
t ->
string ->
unit Async_kernel.Deferred.t
Like execute
but asserts that the result set will be empty.
val execute_single :
?params:Mssql__.Db_field.t option list ->
t ->
string ->
Row.t option Async_kernel.Deferred.t
Like execute
but asserts that the result set will return a maximum of 1 row.
val execute_multi_result :
?params:Mssql__.Db_field.t option list ->
t ->
string ->
Row.t list list Async_kernel.Deferred.t
Like execute
but returns all result sets. Useful for running multiple queries at once.
val execute_many :
params:Mssql__.Db_field.t option list list ->
t ->
string ->
Row.t list list Async_kernel.Deferred.t
List execute
except runs multiple identical queries at the same time, with different parameters. Takes a list of param lists and returns a list of results sets, as if you called List.map params ~f:(fun params -> execute ~params db query)
val begin_transaction : t -> unit Async_kernel.Deferred.t
Begin a transaction
val commit : t -> unit Async_kernel.Deferred.t
Commit the current transaction
val rollback : t -> unit Async_kernel.Deferred.t
Rollback the current transaction
with_transaction t f
runs f
in a transaction. If the function returns normally, the transaction will be commited. If the function throws an exception, the transaction will be rolled back and the exception will be re-raised.
Note regarding the t
argument to the callback: There is logic to ensure that queries outside of the transaction are blocked until the transaction finishes, so you *must* use the t
passed in the callback, not the original handle inside of the transaction. To prevent deadlocks, an exception will be thrown if you use the external DB handle inside of with_transaction.
val with_transaction_or_error :
t ->
(t -> 'a Async_kernel.Deferred.Or_error.t) ->
'a Async_kernel.Deferred.Or_error.t
Like with_transaction
but also rolls back the transaction on Error
exception Error of Error.t