pub struct TableDef {
pub name: String,
pub columns: Vec<ColumnDef>,
pub primary_key: Vec<KeyColumn>,
pub without_rowid: bool,
pub strict: bool,
pub unsupported_constraints: Vec<Constraint>,
/* private fields */
}Fields§
§name: String§columns: Vec<ColumnDef>§primary_key: Vec<KeyColumn>Empty when the table has no primary key at all.
without_rowid: bool§strict: bool§unsupported_constraints: Vec<Constraint>Rules the source enforces that we cannot: unique constraints beyond the key, check constraints, foreign keys and collations.
Implementations§
Source§impl TableDef
impl TableDef
pub fn column(&self, name: &str) -> Option<&ColumnDef>
pub fn column_index(&self, name: &str) -> Option<usize>
Sourcepub fn rowid_alias(&self) -> Option<&ColumnDef>
pub fn rowid_alias(&self) -> Option<&ColumnDef>
The column that is an alias for the rowid, if the table has one.
Such a column holds no value of its own in the record; SQLite stores NULL there and the value lives in the cell’s rowid. Getting this wrong means reading the primary key of an entire table as NULL, or inventing one, and nothing about it fails loudly, so the rule is spelled out here and checked against a fixture built from these exact cases:
| declaration | alias |
|---|---|
x integer primary key | yes |
x integer primary key desc | no |
x integer, primary key (x) | yes |
x integer, primary key (x desc) | yes |
x int primary key | no |
The two desc rows disagreeing is not a typo. Spelling out desc
in a column constraint suppresses the alias, and spelling it out in
a table constraint does not. SQLite documents that as a quirk kept
for backwards compatibility, and every reader has to reproduce it.
A without rowid table has no rowid to alias, so it never has one.