Module Ask.Table

Table descriptions.

Tables simply give a name to rows.

Tables

type 'r param = ..

The type for exensible table parameters. See Parameters.

type 'r t = {
name : string;
params : 'r param list;
row : 'r Row.t Stdlib.Lazy.t;
}

The type for tables with rows represented by type 'r. Unless you get into recursive trouble, use the constructor v.

type v =
| V : 'r t -> v(*

The type for existential tables.

*)
val v : ?params:'r param list -> string -> 'r Row.t -> 'r t

v name ~params r is a table with corresponding attributes.

val name : 'r t -> string

name t is the name of t.

val params : 'r t -> 'r param list

name t are the parameters of t.

val row : 'r t -> 'r Row.t

row t is the description of t's rows.

val cols : ?ignore:'r Col.v list -> 'r t -> 'r Col.v list

cols t is Row.cols (row t) with columns in ignore ommited from the result.

Parameters

Foreign keys

type foreign_key_action = [
| `Set_null
| `Set_default
| `Cascade
| `Restrict
]

The type for foreign key actions.

type ('r, 's) foreign_key = {
cols : 'r Col.v list;
reference : 's t * 's Col.v list;
on_delete : foreign_key_action option;
on_update : foreign_key_action option;
}

The type for representing foreign keys from table 'r to 's. This is exposed for recursive defs reasons, use foreign_key unless you get into trouble. FIXME. At least provide a default empty value so that with can be used.

val foreign_key : ?on_delete:foreign_key_action -> ?on_update:foreign_key_action -> cols:'r Col.v list -> reference:('s t * 's Col.v list) -> unit -> ('r's) foreign_key

foreign_key is a foreign key with given paramers

val foreign_key_cols : ('r's) foreign_key -> 'r Col.v list
val foreign_key_reference : ('r's) foreign_key -> 's t * 's Col.v list

Parameters

type param +=
| Primary_key : 'r Col.v list -> 'r param
| Unique : 'r Col.v list -> 'r param
| Foreign_key : ('r's) foreign_key -> 'r param
| Index : 'r Index.t -> 'r param

Common table parameters.

  • Primary_key cols, declares a table primary key constraint on columns cols.
  • Unique cols, declares a uniqueness constraint on cols
  • Foreign_key (cols, (t, cols')) declares a foreign key between cols and the columns cols' of t. Can be repeated.
  • Index is an index specification for the table.
val indexes : 'r t -> 'r Index.t list

indexes t are the indexes of table t found in the table's parameters.