package mssql

  1. Overview
  2. Docs

Module MssqlSource

Sourcemodule Error : sig ... end
Sourcemodule Param : sig ... end
Sourcemodule Row : sig ... end
Sourcetype t
Sourceval 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.

Sourceval 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.

Sourceval execute_map : ?params:Mssql__.Db_field.t option list -> f:(Row.t -> 'a) -> t -> string -> 'a list Async_kernel.Deferred.t
Sourceval execute_iter : ?params:Mssql__.Db_field.t option list -> f:(Row.t -> unit) -> t -> string -> unit Async_kernel.Deferred.t
Sourceval execute_fold : ?params:Mssql__.Db_field.t option list -> init:'a -> f:('a -> Row.t -> 'a) -> t -> string -> 'a Async_kernel.Deferred.t
Sourceval execute_pipe : ?params:Mssql__.Db_field.t option list -> t -> string -> Row.t Async_kernel.Pipe.Reader.t
Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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)

Sourceval begin_transaction : t -> unit Async_kernel.Deferred.t

Begin a transaction

Sourceval commit : t -> unit Async_kernel.Deferred.t

Commit the current transaction

Sourceval rollback : t -> unit Async_kernel.Deferred.t

Rollback the current transaction

Sourceval with_transaction : t -> (t -> 'a Async_kernel.Deferred.t) -> 'a Async_kernel.Deferred.t

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.

Sourceval 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

Sourceexception Error of Error.t
OCaml

Innovation. Community. Security.