summaryrefslogtreecommitdiff
path: root/lib/query/encoder.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/query/encoder.ml')
-rw-r--r--lib/query/encoder.ml26
1 files changed, 17 insertions, 9 deletions
diff --git a/lib/query/encoder.ml b/lib/query/encoder.ml
index 64464fd..2174e59 100644
--- a/lib/query/encoder.ml
+++ b/lib/query/encoder.ml
@@ -44,7 +44,7 @@ end
module Fold (T : sig
type 'a t
- val f : 'a t -> 'any data -> 'a t
+ val f : 'a t -> (_, _) data -> 'a t
end) =
struct
let rec f : type a. 'acc -> a tuple -> 'acc =
@@ -210,7 +210,7 @@ module CaqtiRequest = Map (struct
let t_n = t11
- let f : type a. unit -> a data -> a t =
+ let f : type a b. unit -> (a, b) data -> a t =
fun () -> function
| { content_type = Text; _ } -> option string
| { content_type = Integer; _ } -> option int64
@@ -255,7 +255,7 @@ module EncodeParameter = Map (struct
type 'a t = string
type env = unit
- let f : type a. unit -> a data -> a t =
+ let f : type a b. unit -> (a, b) data -> a t =
fun () -> function
| { content_type = Text; _ } -> "?"
| { content_type = Integer; _ } -> "?"
@@ -269,7 +269,7 @@ module InsertTableName = Map (struct
type 'a t = string
type env = unit
- let f : type a. unit -> a data -> a t =
+ let f : type a b. unit -> (a, b) data -> a t =
fun () -> function
| { name = column; content_type = Text; _ } -> Model.Identifier.quote column
| { name = column; content_type = Integer; _ } ->
@@ -293,7 +293,7 @@ module DataToCaqtiValues = Map (struct
type 'a t = 'a
type env = string -> Value.value
- let f : type a. env -> a Intf.data -> a t =
+ let f : type a b. env -> (a, b) Intf.data -> a t =
fun provider Intf.{ name; content_type } ->
let result = provider (Model.Identifier.to_string name) in
(* Check the value given by the provider and ensure it’s match the
@@ -301,13 +301,21 @@ module DataToCaqtiValues = Map (struct
match result with
| Value.Data.Any d -> (
match d with
- | Value.Data.Seq _ -> raise TypeMismatch
| Value.Data.None ->
(* The provider does not have any value for this property, use the
default value*)
Model.Typ.default_value content_type
| Value.Data.V (field_type', value) -> (
- match Model.Typ.eq content_type field_type' with
- | Some Equal -> value
- | None -> raise TypeMismatch))
+ (* For the single-column fields handled here, the DB and code
+ representations coincide — match the field type to prove it *)
+ let check (type x) (ct : (x, x, Model.target) Model.Typ.t) : x =
+ match Model.Typ.eq_ocaml ct field_type' with
+ | Some Equal -> value
+ | None -> raise TypeMismatch
+ in
+ match content_type with
+ | Model.Typ.MultiReference _ -> raise TypeMismatch
+ | Model.Typ.Text as ct -> check ct
+ | Model.Typ.Integer as ct -> check ct
+ | Model.Typ.MonoReference _ as ct -> check ct))
end)