package caqti
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
Unified interface to relational database libraries
Install
dune-project
Dependency
Authors
Maintainers
Sources
caqti-v1.6.0.tbz
sha256=1bf0c0d60547033c10d6148cf5297b25ab66c9a2832b680329df2f3816bc674d
sha512=0b03bd1788d99bbac59679338768a5633ec473346eed333fca4c104bc88f04c24e138af2228fc20dcf295b7106778328d228643ae8235a3f722f54cc69919295
doc/src/caqti/caqti_type.ml.html
Source file caqti_type.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242(* Copyright (C) 2017--2021 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 OCaml static compilation 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 * along with this library. If not, see <http://www.gnu.org/licenses/>. *) open Caqti_compat [@@warning "-33"] type _ field = .. type _ field += | Bool : bool field | Int : int field | Int16 : 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 | Enum : string -> string field module Field = struct type 'a t = 'a field type _ coding = Coding : { rep: 'b t; encode: 'a -> ('b, string) result; decode: 'b -> ('a, string) result; } -> 'a coding type get_coding = {get_coding: 'a. Caqti_driver_info.t -> 'a t -> 'a coding} let coding_ht : (extension_constructor, get_coding) Hashtbl.t = Hashtbl.create 11 let define_coding ft get = let ec = Obj.Extension_constructor.of_val ft in Hashtbl.add coding_ht ec get let coding di ft = let ec = Obj.Extension_constructor.of_val ft in try Some ((Hashtbl.find coding_ht ec).get_coding di ft) with Not_found -> None let to_string : type a. a field -> string = function | Bool -> "bool" | Int -> "int" | Int16 -> "int16" | Int32 -> "int32" | Int64 -> "int64" | Float -> "float" | String -> "string" | Octets -> "octets" | Pdate -> "pdate" | Ptime -> "ptime" | Ptime_span -> "ptime_span" | Enum name -> name | ft -> Obj.Extension_constructor.name (Obj.Extension_constructor.of_val ft) let pp_ptime = Ptime.pp_rfc3339 ~tz_offset_s:0 ~space:false () let rec pp_value : type a. _ -> a field * a -> unit = fun ppf -> function | Bool, x -> Format.pp_print_bool ppf x | Int, x -> Format.pp_print_int ppf x | Int16, x -> Format.pp_print_int ppf x | Int32, x -> Format.fprintf ppf "%ldl" x | Int64, x -> Format.fprintf ppf "%LdL" x | Float, x -> Format.fprintf ppf "%F" x | String, x -> Format.fprintf ppf "%S" x | Octets, x -> Format.fprintf ppf "%S" x | Pdate, x -> let y, m, d = Ptime.to_date x in Format.fprintf ppf "%d-%02d-%02d" y m d | Ptime, x -> pp_ptime ppf x | Ptime_span, x -> Ptime.Span.pp ppf x | Enum _, x -> Format.pp_print_string ppf x | (ft, x) -> (match coding Caqti_driver_info.dummy ft with | Some (Coding {rep; encode; _}) -> (match encode x with | Ok y -> pp_value ppf (rep, y) | Error _ -> Format.fprintf ppf "<%s,invalid>" (Obj.Extension_constructor.name (Obj.Extension_constructor.of_val ft))) | None -> Format.fprintf ppf "<%s>" (Obj.Extension_constructor.name (Obj.Extension_constructor.of_val ft))) end type _ t = | Unit : unit t | Field : 'a field -> 'a t | Option : 'a t -> 'a option t | Tup2 : 'a0 t * 'a1 t -> ('a0 * 'a1) t | Tup3 : 'a0 t * 'a1 t * 'a2 t -> ('a0 * 'a1 * 'a2) t | Tup4 : 'a0 t * 'a1 t * 'a2 t * 'a3 t -> ('a0 * 'a1 * 'a2 * 'a3) t | Custom : { rep: 'b t; encode: 'a -> ('b, string) result; decode: 'b -> ('a, string) result; } -> 'a t | Annot : [`Redacted] * 'a t -> 'a t type any = Any : 'a t -> any let rec length : type a. a t -> int = function | Unit -> 0 | Field _ -> 1 | Option t -> length t | Tup2 (t0, t1) -> length t0 + length t1 | Tup3 (t0, t1, t2) -> length t0 + length t1 + length t2 | Tup4 (t0, t1, t2, t3) -> length t0 + length t1 + length t2 + length t3 | Custom {rep; _} -> length rep | Annot (_, t) -> length t let rec pp_at : type a. int -> Format.formatter -> a t -> unit = fun prec ppf -> function | Unit -> Format.pp_print_string ppf "unit" | Field ft -> Format.pp_print_string ppf (Field.to_string ft) | Option t -> pp_at 1 ppf t; Format.pp_print_string ppf " option" | Tup2 (t0, t1) -> if prec > 0 then Format.pp_print_char ppf '('; pp_at 1 ppf t0; Format.pp_print_string ppf " × "; pp_at 1 ppf t1; if prec > 0 then Format.pp_print_char ppf ')' | Tup3 (t0, t1, t2) -> if prec > 0 then Format.pp_print_char ppf '('; pp_at 1 ppf t0; Format.pp_print_string ppf " × "; pp_at 1 ppf t1; Format.pp_print_string ppf " × "; pp_at 1 ppf t2; if prec > 0 then Format.pp_print_char ppf ')' | Tup4 (t0, t1, t2, t3) -> if prec > 0 then Format.pp_print_char ppf '('; pp_at 1 ppf t0; Format.pp_print_string ppf " × "; pp_at 1 ppf t1; Format.pp_print_string ppf " × "; pp_at 1 ppf t2; Format.pp_print_string ppf " × "; pp_at 1 ppf t3; if prec > 0 then Format.pp_print_char ppf ')' | Custom {rep; _} -> Format.pp_print_string ppf "</"; pp_at 0 ppf rep; Format.pp_print_string ppf "/>" | Annot (`Redacted, t) -> Format.pp_print_string ppf "redacted "; pp_at 2 ppf t let pp ppf = pp_at 1 ppf let pp_any ppf (Any t) = pp_at 1 ppf t let rec pp_value : type a. _ -> a t * a -> unit = fun ppf -> function | Unit, () -> Format.pp_print_string ppf "()" | Field ft, fv -> Field.pp_value ppf (ft, fv) | Option _, None -> Format.pp_print_string ppf "None" | Option t, Some x -> Format.pp_print_string ppf "Some "; pp_value ppf (t, x) | Tup2 (t1, t2), (x1, x2) -> Format.pp_print_char ppf '('; pp_value ppf (t1, x1); Format.pp_print_string ppf ", "; pp_value ppf (t2, x2); Format.pp_print_char ppf ')' | Tup3 (t1, t2, t3), (x1, x2, x3) -> Format.pp_print_char ppf '('; pp_value ppf (t1, x1); Format.pp_print_string ppf ", "; pp_value ppf (t2, x2); Format.pp_print_string ppf ", "; pp_value ppf (t3, x3); Format.pp_print_char ppf ')' | Tup4 (t1, t2, t3, t4), (x1, x2, x3, x4) -> Format.pp_print_char ppf '('; pp_value ppf (t1, x1); Format.pp_print_string ppf ", "; pp_value ppf (t2, x2); Format.pp_print_string ppf ", "; pp_value ppf (t3, x3); Format.pp_print_string ppf ", "; pp_value ppf (t4, x4); Format.pp_print_char ppf ')' | Custom {rep; encode; _}, x -> (match encode x with | Ok y -> pp_value ppf (rep, y) | Error _ -> Format.pp_print_string ppf "INVALID") | Annot (`Redacted, _), _ -> Format.pp_print_string ppf "#redacted#" let show t = let buf = Buffer.create 64 in let ppf = Format.formatter_of_buffer buf in pp ppf t; Format.pp_print_flush ppf (); Buffer.contents buf let field ft = Field ft module Std = struct let unit = Unit let option t = Option t let tup2 t0 t1 = Tup2 (t0, t1) let tup3 t0 t1 t2 = Tup3 (t0, t1, t2) let tup4 t0 t1 t2 t3 = Tup4 (t0, t1, t2, t3) let custom ~encode ~decode rep = Custom {rep; encode; decode} let redacted t = Annot (`Redacted, t) let enum ~encode ~decode name = Custom {rep = Field (Enum name); encode = (fun x -> Ok (encode x)); decode} let bool = Field Bool let int = Field Int let int16 = Field Int16 let int32 = Field Int32 let int64 = Field Int64 let float = Field Float let string = Field String let octets = Field Octets let pdate = Field Pdate let ptime = Field Ptime let ptime_span = Field Ptime_span end include Std
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>