package mssql

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
module Error : sig ... end
module Param : sig ... end
module Row : sig ... end
module Test : sig ... end

Exposes functions to help with tests that use Mssql

type t
val with_conn : host:string -> db:string -> user:string -> password:string -> port:string -> (t -> 'a Async.Deferred.t) -> 'a Async.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.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.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.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.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.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.Deferred.t

Begin a transaction

val commit : t -> unit Async.Deferred.t

Commit the current transaction

val rollback : t -> unit Async.Deferred.t

Rollback the current transaction

val with_transaction : t -> (t -> 'a Async.Deferred.t) -> 'a Async.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.

val with_transaction_or_error : t -> (t -> 'a Async.Deferred.Or_error.t) -> 'a Async.Deferred.Or_error.t

Like with_transaction but also rolls back the transaction on Error

module Pool : sig ... end
exception Error of Error.t
OCaml

Innovation. Community. Security.