Database schemas and instances #
A database schema (DbSchema) names the tables and gives each table its arity and its column
declarations, independently of any data: an empty table still has columns and types. The typing
context of a table (DbSchema.ctx) is the list of its declared column types.
A database instance (Database S) gives each table of S its rows. The rows form a bag, which
is represented by a list: duplicates matter, and the list order is a property of this
representation only, since SQL promises no order without ORDER BY. An instance conforms to its
schema (Database.Conforms) when every cell of every table is NULL or a value of its column's
declared type.
It adapts and redesigns the databases of sql_equiv (revision 38030a6b) by Evelyn Mitchell,
which mapped table names to lists of name–value rows, so that a table's columns and types came
from its data and an empty table had none; here the schema is separate data that every instance
of it conforms to.
Main definitions #
Cslib.SQL.DbSchema: table names, arities and column declarations.Cslib.SQL.DbSchema.ctx: the typing context of a table.Cslib.SQL.Database: an instance of a schema, a bag of rows for each table.Cslib.SQL.Database.Conforms: every table's rows conform to its declared types.
A database schema: the table names, and for each table its number of columns and their declarations. It does not depend on data, so an empty table has columns too.
- Table : Type
The table names.
The number of columns of each table.
The column declarations of each table: names, qualifiers and declared types.
Instances For
A database instance of the schema S: for each table, its rows. A table is a bag of rows,
represented by a list; the list order means nothing in SQL.
Instances For
The instance conforms to its schema: every row of every table has the table's declared types.