Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file caqti_type_sig.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190(* Copyright (C) 2018--2023 Petter A. Urkedal <paurkedal@gmail.com>
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at your
* option) any later version, with the LGPL-3.0 Linking Exception.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* and the LGPL-3.0 Linking Exception along with this library. If not, see
* <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively.
*)(** Signatures for {!Caqti_type}. *)(** Standard type descriptors. *)moduletypeStd=sigtype'attype('a,'i)product(** {3 Composite}
The following provides constructors for narrow tuple types; to describe
wider tuple types, use nested application. *)valoption:'at->'aoptiont(** [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]. *)valunit:unitt(** 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. *)valt2:'a1t->'a2t->('a1*'a2)t(** Creates a pair type. *)valt3:'a1t->'a2t->'a3t->('a1*'a2*'a3)t(** Creates a 3-tuple type. *)valt4:'a1t->'a2t->'a3t->'a4t->('a1*'a2*'a3*'a4)t(** Creates a 4-tuple type. *)valt5:'a1t->'a2t->'a3t->'a4t->'a5t->('a1*'a2*'a3*'a4*'a5)t(** Creates a 5-tuple type. This is implemented in terms of lower tuples. *)valt6:'a1t->'a2t->'a3t->'a4t->'a5t->'a6t->('a1*'a2*'a3*'a4*'a5*'a6)t(** Creates a 6-tuple type. This is implemented in terms of lower tuples. *)valt7:'a1t->'a2t->'a3t->'a4t->'a5t->'a6t->'a7t->('a1*'a2*'a3*'a4*'a5*'a6*'a7)t(** Creates a 7-tuple type. This is implemented in terms of lower tuples. *)valt8:'a1t->'a2t->'a3t->'a4t->'a5t->'a6t->'a7t->'a8t->('a1*'a2*'a3*'a4*'a5*'a6*'a7*'a8)t(** Creates a 8-tuple type. This is implemented in terms of lower tuples. *)valproduct:'i->('a,'i)product->'atvalproj:'bt->('a->'b)->('a,'i)product->('a,'b->'i)productvalproj_end:('a,'a)productvalcustom:encode:('a->('b,string)result)->decode:('b->('a,string)result)->'bt->'at(** [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]. *)valredacted:'at->'at(** [redacted t] is the same type as [t] but sealed as potentially containing
sensitive information to be redacted from pretty-printers and logs. *)(** {3 Singular} *)valbool:boolt(** A [bool] mapped to [boolean] on the SQL side if supported, otherwise
mapped to an integer. *)valint:intt(** An [int] mapped to a sufficiently wide integer on the SQL side. *)valint16:intt(** An [int] mapped to a [smallint] (16 bits) on the SQL side. *)valint32:int32t(** An [int32] mapped to an [integer] (32 bits) on the SQL side. *)valint64:int64t(** An [int64] mapped to a [bigint] (64 bits) on the SQL side. *)valfloat:floatt(** 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. *)valstring:stringt(** An UTF-8 string. The database should accept UTF-8 if non-ASCII characters
are present. *)valoctets:stringt(** A [string] mapped to whichever type is used to represent binary data on
the SQL side. *)valpdate:Ptime.tt(** A time truncated to a date and mapped to the SQL [date] type. *)valptime:Ptime.tt(** 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 SQL [timestamp] and
[timestamp] which is similar to the SQL [timestamp 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
then [timestamp]. The PostgreSQL [timestamp] 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 {{:https://sqlite.org/lang_datefunc.html}
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. *)valptime_span:Ptime.spant(** A period of time. If the database lacks a dedicated representation, the
integer number of seconds is used. *)valenum:encode:('a->string)->decode:(string->('a,string)result)->string->'at(** [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.Field.Enum}
field type. *)(**/**)valtup2:'a1t->'a2t->('a1*'a2)t[@@deprecated"Renamed to t2."]valtup3:'a1t->'a2t->'a3t->('a1*'a2*'a3)t[@@deprecated"Renamed to t3."]valtup4:'a1t->'a2t->'a3t->'a4t->('a1*'a2*'a3*'a4)t[@@deprecated"Renamed to t4."]end