package caqti
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=b8ea432820154ec095132c4f7b244b06cd8553e0b2035185b844d9c4f30af8bb
sha512=b7e3ad8e6a9b587db2d517e15cd42df2945148f9223b2fa6f4bc2bcdd2709d53549cca4b65e54511d22466e4c9aa7f0b9c17305a07505519d8bf81d95de629b8
doc/caqti.template/Caqti_template/Type/index.html
Module Caqti_template.Type
Source
This module imports everything needed to describe a request type, including the parameter type, row type, and row multiplicity.
include Row_type.STD
Field Types
The following types correspond to what usually fits in a single field of a result row or input parameter set.
A bool
mapped to boolean
on the SQL side if supported, otherwise mapped to an integer.
An int
mapped to a sufficiently wide integer on the SQL side.
An int
mapped to a smallint
(16 bits) on the SQL side.
An int32
mapped to an integer
(32 bits) on the SQL side.
An int64
mapped to a bigint
(64 bits) on the SQL side.
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.
A time truncated to a date and mapped to the SQL date
type.
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
datetime
which is similar to the SQLtimestamp
andtimestamp
which 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 zone
is stored as UTC without time zone, taking up no more space thentimestamp
. The PostgreSQLtimestamp
type 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_TIMESTAMP
return, 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.
Composite Types
option t
turns a set of fields encoded as t
into a correspending set of nullable fields. The encoder will encode None
as into a tuple of NULL
values and the decoder will return None
if all fields are NULL
.
If the type t
itself is option t'
for some t'
, or contains nested tuples and options such that all field types are nested under an option type, then it would have been possible to decode an all-NULL
segment of a row as Some x
where x
is a corresponding tuple-option-tree terminating in None
values. The above paragraph resolves this ambiguity since it implies that the outermost option possible will be decoded as None
.
redacted t
is the same type as t
but sealed as potentially containing sensitive information to be redacted from pretty-printers and logs.
Tuple Types
As a common case of composite types, constructors for tuples up to 12 components are predefined here. Higher tuples can be created with Row_type.product
.
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.
Creates a pair type.
Creates a 3-tuple type.
val t4 :
'a1 Row_type.t ->
'a2 Row_type.t ->
'a3 Row_type.t ->
'a4 Row_type.t ->
('a1 * 'a2 * 'a3 * 'a4) Row_type.t
Creates a 4-tuple type.
val t5 :
'a1 Row_type.t ->
'a2 Row_type.t ->
'a3 Row_type.t ->
'a4 Row_type.t ->
'a5 Row_type.t ->
('a1 * 'a2 * 'a3 * 'a4 * 'a5) Row_type.t
Creates a 5-tuple type.
val t6 :
'a1 Row_type.t ->
'a2 Row_type.t ->
'a3 Row_type.t ->
'a4 Row_type.t ->
'a5 Row_type.t ->
'a6 Row_type.t ->
('a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6) Row_type.t
Creates a 6-tuple type.
val t7 :
'a1 Row_type.t ->
'a2 Row_type.t ->
'a3 Row_type.t ->
'a4 Row_type.t ->
'a5 Row_type.t ->
'a6 Row_type.t ->
'a7 Row_type.t ->
('a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7) Row_type.t
Creates a 7-tuple type.
val t8 :
'a1 Row_type.t ->
'a2 Row_type.t ->
'a3 Row_type.t ->
'a4 Row_type.t ->
'a5 Row_type.t ->
'a6 Row_type.t ->
'a7 Row_type.t ->
'a8 Row_type.t ->
('a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8) Row_type.t
Creates a 8-tuple type.
val t9 :
'a1 Row_type.t ->
'a2 Row_type.t ->
'a3 Row_type.t ->
'a4 Row_type.t ->
'a5 Row_type.t ->
'a6 Row_type.t ->
'a7 Row_type.t ->
'a8 Row_type.t ->
'a9 Row_type.t ->
('a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8 * 'a9) Row_type.t
Creates a 9-tuple type.
val t10 :
'a1 Row_type.t ->
'a2 Row_type.t ->
'a3 Row_type.t ->
'a4 Row_type.t ->
'a5 Row_type.t ->
'a6 Row_type.t ->
'a7 Row_type.t ->
'a8 Row_type.t ->
'a9 Row_type.t ->
'a10 Row_type.t ->
('a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8 * 'a9 * 'a10) Row_type.t
Creates a 10-tuple type.
val t11 :
'a1 Row_type.t ->
'a2 Row_type.t ->
'a3 Row_type.t ->
'a4 Row_type.t ->
'a5 Row_type.t ->
'a6 Row_type.t ->
'a7 Row_type.t ->
'a8 Row_type.t ->
'a9 Row_type.t ->
'a10 Row_type.t ->
'a11 Row_type.t ->
('a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8 * 'a9 * 'a10 * 'a11)
Row_type.t
Creates a 11-tuple type.
val t12 :
'a1 Row_type.t ->
'a2 Row_type.t ->
'a3 Row_type.t ->
'a4 Row_type.t ->
'a5 Row_type.t ->
'a6 Row_type.t ->
'a7 Row_type.t ->
'a8 Row_type.t ->
'a9 Row_type.t ->
'a10 Row_type.t ->
'a11 Row_type.t ->
'a12 Row_type.t ->
('a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8 * 'a9 * 'a10 * 'a11 * 'a12)
Row_type.t
Creates a 12-tuple type.
val (-->.) :
'a Row_type.t ->
unit Row_type.t ->
'a Row_type.t * unit Row_type.t * Row_mult.zero Row_mult.t
val (-->!) :
'a Row_type.t ->
'b Row_type.t ->
'a Row_type.t * 'b Row_type.t * Row_mult.one Row_mult.t
val (-->?) :
'a Row_type.t ->
'b Row_type.t ->
'a Row_type.t * 'b Row_type.t * Row_mult.zero_or_one Row_mult.t
val (-->*) :
'a Row_type.t ->
'b Row_type.t ->
'a Row_type.t * 'b Row_type.t * Row_mult.zero_or_more Row_mult.t