github ↗
docs menu

Module Talon.Schema

Schemas: the names and types of a table's columns.

A schema is an ordered list of columns, each a name and a Type.t, with distinct names. Tables, queries and format descriptions each have one, and a query's is known before any data is read.

#type t

The type for schemas.

#val v : (string * Type.any) list -> t

v columns is the schema of columns, in order. A schema may have no columns, and a column's name may be empty.

Raises Invalid_argument if two columns have the same name, or a name is not valid UTF-8.

#val columns : t -> (string * Type.any) list

columns s is the columns of s, in order. columns (v cs) is cs.

#val find : t -> string -> Type.any option

find s name is the type of the column name of s, or None if s has no such column. It costs O(log n) for a schema of n columns.

Comparing

#val equal : t -> t -> bool

equal s0 s1 is true iff s0 and s1 have the same names with equal types (Type.equal) in the same order.

#type change =
  1. #| Added of string * Type.any
    (*

    Added (name, t): s1 has the column name of type t, and s0 has none.

    *)
  2. #| Removed of string * Type.any
    (*

    Removed (name, t): s0 has the column name of type t, and s1 has none.

    *)
  3. #| Retyped of string * Type.any * Type.any
    (*

    Retyped (name, t0, t1): the column name has the type t0 in s0 and a different type t1 in s1.

    *)

The type for the differences between two schemas s0 and s1.

#val diff : t -> t -> change list

diff s0 s1 is the changes from s0 to s1: first the Removed and Retyped columns in the order of s0, then the Added ones in the order of s1. It ignores order, so it is empty iff s0 and s1 have the same names with equal types, in any order; then equal s0 s1 holds iff the order is also the same.

Formatting

#val pp : Stdlib.Format.formatter -> t -> unit

pp ppf s formats the columns of s in order, separated by commas, each as its name and its type: carrier string, delay float64. Names are quoted as Type.pp quotes field names, and types format with Type.pp. The empty schema formats as nothing.