Rel.TableTable definitions.
A table is defined by a name and a row definition.
This module defines a type to describe tables, their indices and constraints.
The type for extensible table parameters. Warning this may be removed in the future.
module Primary_key : sig ... endPrimary keys definitions.
module Unique_key : sig ... endUnique keys definitions.
module Foreign_key : sig ... endForeign keys definitions.
module Index : sig ... endTable index definitionss.
val make :
?params:'r param list ->
?indices:'r Index.t list ->
?foreign_keys:'r Foreign_key.t list ->
?unique_keys:'r Unique_key.t list ->
?primary_key:'r Primary_key.t ->
name ->
'r Row.t ->
'r tmake name row is a table definition with:
name, the name of the table.row, a description of its columns.primary_key, a description of its primary key constraint (if any).unique_keys, a description of unique key constraints (if any).foreign_keys, a description of foreign keys (if any).indices, a description of table indices (if any).params, a list of parameters for the tableNote. For now the module does not check that the columns mentioned in the various constraints actually belong to row. Do not rely on this, Invalid_argument may be raised in the future.
cols t is Row.cols (row t) with columns in ignore ommited from the result.
val primary_key : 'r t -> 'r Primary_key.t optionprimary_key t is the primary key of t (if any).
val unique_keys : 'r t -> 'r Unique_key.t listunique_keys t are the unique keys of t.
val foreign_keys : 'r t -> 'r Foreign_key.t listforeign_keys t are the foreign keys of t.
type 'r change = | Add_column_after : 'r Col.def * 'r Col.def option -> 'r changeIf the second column is None, in the first position.
*)| Add_foreign_key : 'r Foreign_key.t -> 'r change| Add_primary_key : 'r Primary_key.t -> 'r change| Add_unique_key : 'r Unique_key.t -> 'r change| Create_index : 'r Index.t -> 'r change| Drop_column : Col.name -> 'r change| Drop_foreign_key : 'a Foreign_key.t -> 'r change| Drop_index : Index.name -> 'r change| Drop_primary_key : 'r change| Drop_unique_key : 'a Unique_key.t -> 'r change| Set_column_default : 'r Col.def -> 'r changeThe given column default changed.
*)| Set_column_type : 'r Col.def * 'b Col.def -> 'r changeThe given column type changed, the second column is the old column. The default should also be changed.
*)| Set_column_pos_after : 'r Col.def * 'r Col.def option -> 'r changeIf the second column is None, in the first position.
*)The type for table changes.
changes ~src ~dst is the list of structural changes to bring table src to dst.
This function does not handle renames which should be performed before (also the table name is ignored). Any name found in src (resp. dst) and absent in dst (resp. src) will result in a column drop (resp. add).
See also Schema.changes which integrates renames.
XXX. Maybe we could surface the renaming business.
val pp_change : Stdlib.Format.formatter -> 'r change -> unitpp_change ppf c formats change c in a pseudo, non-executable, SQL.
sort ts sorts table ts in dependency order. A table t depends on a table s if t refers to s via a foreign key.
If table dependencies are cyclic, the function errors with a cycle. For this function Self table dependencies do not count as cycles.
Raises Invalid_argument if there are two tables with the same name in ts or if ts is not closed over dependencies.