serial_table<movie> movies(db, "movies", &movie::id); serial_table<cinema> cinemas(db, "cinemas", &cinema::id); serial_table<screen> screens(db, "screens", &screen::id);
These definitions create three objects representing tables. The actual SQL tables aren't being created yet. In fact these constructors don't communicate with the DBMS at all; they just collect details for later.
The template parameter (e.g.
gives the table's value type. This is the C++ type
that each complete row of the table represents.
The three constructor arguments are:
Every table has a value mapper, which tells quince
exactly how the table's value type should be represented in this particular
table. The table constructor builds this, using predefined mapper classes
etc. that are appropriate to the given database.
In this example we're constructing
tables. I use
the noun “table”, in normal font, for both, but
differ from each other as follows:
serial_table, a value is automatically assigned to the primary key whenever a record is inserted (so it must be a
table, the primary key must be present in a record before it is inserted, and then it is copied into the table like any other member (regardless of whether it is a
Our code uses the simplest form of the constructor, which is often all you need, but other forms are available also.
PostgreSQL only: When we constructed
we specified that
is the default schema. So when we create tables without mentioning a schema
(as we do here), they go into the schema
-- with quince creating it if necessary.