caqti

Unified interface to relational database libraries
Library caqti
Module Caqti_type

Primitive Field Types

The following is normally only needed for drivers and to define new field types. Everything needed for common usage is covered in Row Types.

type 'a field = ..

An extensible type describing primitive SQL types and types which can be converted to and from such types. When adding a new constructor, register the coding with Field.define_coding if possible. Otherwise, the type will only work with drivers which handle it themselves. The shipped drivers only handle the constructors listed here.

type field +=
| Bool : bool field
| Int : int field
| Int32 : int32 field
| Int64 : int64 field
| Float : float field
| String : string field
| Octets : string field
| Pdate : Ptime.t field
| Ptime : Ptime.t field
| Ptime_span : Ptime.span field

Primitive field types handled by the shipped drivers.

module Field : sig ... end

Facilities for extending and using primitive field types.

Row Types

type _ t = private
| Unit : unit t
| Field : 'a field -> 'a t
| Option : 'a t -> 'a option t
| Tup2 : 'a t * 'b t -> ('a * 'b) t
| Tup3 : 'a t * 'b t * 'c t -> ('a * 'b * 'c) t
| Tup4 : 'a t * 'b t * 'c t * 'd t -> ('a * 'b * 'c * 'd) t
| Custom : {
rep : 'b t;
encode : 'a -> ( 'b, string ) result;
decode : 'b -> ( 'a, string ) result;
} -> 'a t

Type descriptor for row types.

Note. The concrete representation of this type should be considered private, including pattern-matching usage; use the below functions for compatibility with future versions.

type any =
| Any : 'a t -> any

t with existentially wrapped static type.

val length : 'a t -> int

length t is the number of fields used to represent t.

val pp : Format.formatter -> 'a t -> unit

pp ppf t prints a human presentation of t on ppf.

val pp_any : Format.formatter -> any -> unit

pp_any ppf t prints a human presentation of t on ppf.

val show : 'a t -> string

show t is a human presentation of t.

val field : 'a field -> 'a t

field ft is a row of a single field of type ft. This function can be used when adding new field types; use the below functions otherwise.

module Std : Caqti_type_sig.Std with type 'a t := 'a t

Standard type descriptors provided as a submodule for easy inclusion.

include Caqti_type_sig.Std with type 'a t := 'a t

Composite

The following provides constructors for narrow tuple types; to describe wider tuple types, use nested application.

val option : 'a t -> 'a option t
val unit : unit t

A holding no fields. This is used to pass no parameters and as the result for queries which does not return any rows. It can also be nested in tuples, in which case it will not contribute to the total number of fields.

val tup2 : 'a t -> 'b t -> ('a * 'b) t

Creates a pair type.

val tup3 : 'a t -> 'b t -> 'c t -> ('a * 'b * 'c) t

Creates a 3-tuple type.

val tup4 : 'a t -> 'b t -> 'c t -> 'd t -> ('a * 'b * 'c * 'd) t

Creates a 4-tuple type.

val custom : encode:( 'a -> ( 'b, string ) result ) -> decode:( 'b -> ( 'a, string ) result ) -> 'b t -> 'a t

custom ~encode ~decode rep creates a custom type represented by rep, where encode is used to encode parameters into rep and decode is used to decode result rows from rep.

Note. This should be considered experimental and may be revised or removed in a future version.

Singular

val bool : bool t

A boolean.

val int : int t

An integer.

val int32 : int32 t

A 32 bit integer.

val int64 : int64 t

A 64 bit integer.

val float : float t

A float.

val string : string t

An UTF-8 string. The database should accept UTF-8 if non-ASCII characters are present.

val octets : string t

A binary string.

val pdate : Ptime.t t

A date. This corresponds to the SQL date type.

val ptime : Ptime.t t

An absolute time with driver-dependent precision. This corresponds to an SQL timestamp type with UTC time zone.

val ptime_span : Ptime.span t

A period of time. If the database lacks a dedicated representation, the integer number of seconds is used.