next up previous contents
Next: Table Constraints Up: The Ur/Web Standard Library Previous: HTTP   Contents

SQL

Everything about SQL database access is restricted to server-side code.

The fundamental unit of interest in the embedding of SQL is tables, described by a type family and creatable only via the $ \mathsf{table}$ declaration form.

\begin{displaymath}\begin{array}{l}
\mathsf{con} \; \mathsf{sql\_table} :: \{\m...
...Type}\} \to \{\{\mathsf{Unit}\}\} \to \mathsf{Type}
\end{array}\end{displaymath}

The first argument to this constructor gives the names and types of a table's columns, and the second argument gives the set of valid keys. Keys are the only subsets of the columns that may be referenced as foreign keys. Each key has a name.

We also have the simpler type family of SQL views, which have no keys.

\begin{displaymath}\begin{array}{l}
\mathsf{con} \; \mathsf{sql\_view} :: \{\mathsf{Type}\} \to \mathsf{Type}
\end{array}\end{displaymath}

A multi-parameter type class is used to allow tables and views to be used interchangeably, with a way of extracting the set of columns from each.

\begin{displaymath}\begin{array}{l}
\mathsf{class} \; \mathsf{fieldsOf} :: \mat...
... (\mathsf{sql\_view} \; \mathsf{fs}) \; \mathsf{fs}
\end{array}\end{displaymath}



Subsections

2014-07-14