Something went wrong. Try again.
My own corner of monopam
Something went wrong. Try again.
1.9 kB · 58 lines
OCaml
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859(*--------------------------------------------------------------------------- Copyright (c) 2025 Thomas Gazagnaire. All rights reserved. SPDX-License-Identifier: ISC ---------------------------------------------------------------------------*)
type t = Any | Blob | Int | Integer | Real | Text
let of_type_name ty = match String.uppercase_ascii ty with | "ANY" -> Some Any | "BLOB" -> Some Blob | "INT" -> Some Int | "INTEGER" -> Some Integer | "REAL" -> Some Real | "TEXT" -> Some Text | _ -> None
let to_string = function | Any -> "ANY" | Blob -> "BLOB" | Int -> "INT" | Integer -> "INTEGER" | Real -> "REAL" | Text -> "TEXT"
let pp = Fmt.of_to_string to_string
(* A column's affinity is the one its declared type name carries, with one override: a STRICT ANY column takes BLOB affinity rather than the NUMERIC affinity the name would carry outside a STRICT table. BLOB affinity converts nothing, so ANY and BLOB values keep the storage class they were written in. *)let apply_affinity t v = match t with | Any | Blob -> v | Int | Integer | Real | Text -> Catalog.Value_ops.apply_affinity (to_string t) v
let accepts t (v : Catalog.Value.t) = match v with | Null -> true | _ -> ( match t with | Any -> true | Blob -> ( match v with Blob _ -> true | _ -> false) | Int | Integer -> ( match v with Int _ -> true | _ -> false) (* REAL affinity has already turned an integer into a real; an integer that survived it (one too large to be one) is a real all the same. *) | Real -> ( match v with Float _ | Int _ -> true | _ -> false) | Text -> ( match v with Text _ -> true | _ -> false))
let storage_class (v : Catalog.Value.t) = match v with | Null -> "NULL" | Int _ -> "INT" | Float _ -> "REAL" | Text _ -> "TEXT" | Blob _ -> "BLOB"