package caqti
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=1bf0c0d60547033c10d6148cf5297b25ab66c9a2832b680329df2f3816bc674d
sha512=0b03bd1788d99bbac59679338768a5633ec473346eed333fca4c104bc88f04c24e138af2228fc20dcf295b7106778328d228643ae8235a3f722f54cc69919295
doc/caqti/Caqti_type/index.html
Module Caqti_typeSource
Type descriptors for fields and tuples.
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.
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.
Row Types
type _ t = private 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.
pp ppf t prints a human presentation of t on ppf.
pp_any ppf t prints a human presentation of t on ppf.
pp_value ppf (t, v) prints a human representation of v given the type descriptor t. This function is meant for debugging; the output is neither guaranteed to be consistent across releases nor to contain a complete record of the data.
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.
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.
A type 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 custom :
encode:('a -> ('b, string) result) ->
decode:('b -> ('a, string) result) ->
'b t ->
'a tcustom ~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.
redacted t is the same type as t but sealed as potentially containing sensitive information to be redacted from pretty-printers and logs.
Singular
A bool mapped to boolean on the SQL side if supported, otherwise mapped to an integer.
A float mapped to double precision or (best alternative) on the SQL side. Serialization may be lossy (e.g. base 10 may be used), so even if both sides support IEEE 754 double precision numbers, there may be discrepancies in the last digits of the binary representaton.
An UTF-8 string. The database should accept UTF-8 if non-ASCII characters are present.
A string mapped to whichever type is used to represent binary data on the SQL side.
An absolute time with driver-dependent precision. This corresponds to an SQL timestamp with time zone or a suitable alternative where not available:
- MariaDB has
datetimewhich is similar to the SQLtimestampandtimestampwhich is similar to the SQLtimestamp with time zone, but the driver does not make the distinction. Caqti sets the session time zone to UTC to avoid misinterpretation, since time values are passed in both directions without time zones. Values have microsecond precision, but you will need to specify the desired precision in the database schema to avoid truncation.
- PostgreSQL supports this type and it's a good option to avoid any time zone issues if used conistently both on the client side, in SQL expressions, and in the database schema. Note that
timestamp with time zoneis stored as UTC without time zone, taking up no more space thentimestamp. The PostgreSQLtimestamptype is problematic since how conversions work and the manual indicate that it is meant to be a local time, and since database columns of this type stores the value without conversion to UTC, it becomes prone to time zone changes. To mitigate the issue, Caqti sets the time zone of sessions to UTC.
- Sqlite3 does not have a dedicated type for absolute time. The date and time is sent as strings expressed at the UTC time zone using same format that the SQLite datetime function and
CURRENT_TIMESTAMPreturn, except for an additional three decimals to achive millisecond precision.
It might seem better to use standard RFC3339 format, since it is accepted by the SQLite functions, but that would misorder some time values if mixed with the results of these functions, even just the "Z" suffix would misorder values with different precision.
Date and time values which comes from the database without time zone are interpreted as UTC. This is not necessarily correct, and it is highly recommended to use SQL types which are transmitted with time zone information, even if this is UTC.
A period of time. If the database lacks a dedicated representation, the integer number of seconds is used.
enum ~encode ~decode name creates an enum type which on the SQL side is named name, with cases which are converted with encode and decode functions. This is implemented in terms of the Caqti_type.Enum field type.