NAME
ort-sql —
produce ort SQL schema
SYNOPSIS
ort-sql |
[config...] |
DESCRIPTION
The ort-sql utility accepts
ort(5)
config files, defaulting to standard input, and
produces an SQL schema. The SQL generated is designed for
sqlite3(1).
SQL Commands
Output always begins with PRAGMA
foreign_keys=ON regardless of whether the configuration has any
references.
The schema begins of a series of CREATE
TABLE SQL commands for each struct object in
config. The name of the table inherits from the
structure name.
Each field within each
struct is mapped into a representative SQL type
except the struct, which is a virtual type. The name
of the column inherits from the field name.
bit |
INTEGER |
bitfield |
INTEGER |
blob |
BLOB |
date |
INTEGER |
email |
TEXT |
enum |
INTEGER |
epoch |
INTEGER |
int |
INTEGER |
password |
TEXT |
real |
REAL |
text |
TEXT |
Furthermore, types may have the following attributes.
actdel |
ON
DELETE |
actup |
ON
UPDATE |
default |
DEFAULT() |
rowid |
PRIMARY
KEY |
unique |
UNIQUE |
If null is not specified, the SQL column
is marked as NOT NULL. The
default attribute is type-specific.
Reference types may contain the actup and
actdel attributes map as follows:
cascade |
CASCADE |
default |
DEFAULT |
nullify |
NULLIFY |
restrict |
RESTRICT |
These are assigned as FOREIGN KEY(xxx) REFERENCE
yyy(zzz) followed by the update or delete clause, if applicable.
Lastly, any unique statement on the
structure is rendered as a unique index. The name of the index is the
(sorted) fields in the unique statement, separated
by underscores, and prefixed with “unique_strct__” where
“strct” is the name of the structure. Thus, an example
structure “xyzzy” having unique(foo,
bar) would be rendered as:
CREATE UNIQUE INDEX unique_xyzzy__bar_foo ON xyzzy(foo, bar);
EXIT STATUS
The ort-sql utility exits 0 on
success, and >0 if an error occurs.