Expand description
Names accepted inside #[SQLiteTable(...)], #[column(...)],
#[SQLiteView(...)] and #[SQLiteIndex(...)].
The macros read these attributes by name, case-insensitively
(primary and PRIMARY are the same). The constants here exist so your
editor can show their documentation on hover; the macros point each
attribute at its constant, so import them through the prelude.
§Examples
use drizzle::sqlite::prelude::*;
#[SQLiteTable(
name = "users",
strict,
unique(columns(email, tenant_id)),
check(name = "users_score_check", expr = "score >= 0")
)]
struct User {
#[column(primary, autoincrement)]
id: i32,
#[column(unique, collate = NOCASE)]
email: String,
tenant_id: i32,
#[column(default = 0)]
score: i32,
}
#[SQLiteTable(name = "posts")]
struct Post {
#[column(primary)]
id: i32,
#[column(references = User::id, on_delete = CASCADE)]
author_id: i32,
title: String,
}The per-attribute examples below are fragments of such a definition.
Structs§
- Column
Marker - The type of the column constraint and option constants.
- Index
Marker - The type of the index option constants.
- Name
Marker - The type of the
NAMEconstant. - Table
Marker - The type of the table option constants.
- Type
Marker - The type of the column type constants.
- View
Marker - The type of the view option constants.
Constants§
- ANY
- Sets the column type to
ANY(STRICT tables only). - AUTOINCREMENT
- Adds
AUTOINCREMENTto anINTEGER PRIMARY KEYcolumn, so rowids of deleted rows are never reused. - BINARY
- BINARY collation: bytewise comparison of operands. The default for
BLOBcolumns and any column without an explicit collation. - BLOB
- Sets the column type to
BLOB. - BOOLEAN
- Stores a
boolasINTEGER0 or 1. - CASCADE
CASCADE: delete or update the referencing rows too.- CHECK
- Adds a CHECK constraint to a column (
check = "...") or a table (check(name = "...", expr = "...")). The expression is raw SQL. - COLLATE
- Sets the collation of a text column.
- DEFAULT
- Adds a
DEFAULTclause to the column. - DEFAULT_
FN - Generates a value in Rust for each insert that leaves the column unset.
- DEFINITION
- The view’s query: an SQL string, or a block that returns a query builder.
- ENUM
- Stores a
#[derive(SQLiteEnum)]enum. - EXISTING
- Marks the view as already existing, so migrations do not create it.
- FOREIGN_
KEY - Adds a table-level foreign key, for keys over several columns.
- GENERATED
- Makes the column a generated column:
stored(computed on write) orvirtual(computed on read), from a raw SQL expression. - INTEGER
- Sets the column type to
INTEGER. - JSON
- Stores the field as JSON text, serialized with serde.
- MANY_
TO_ MANY - Names the many-to-many accessor the referenced table gets through this link table.
- NAME
- Sets the name used in the database.
- NOCASE
- NOCASE collation: compares ASCII letters case-insensitively.
- NO_
ACTION NO ACTION: likeRESTRICT, but checked at the end of the statement. The default.- NUMERIC
- Sets the column type to
NUMERIC. - ON_
DELETE - Sets the
ON DELETEaction of a foreign key. - ON_
UPDATE - Sets the
ON UPDATEaction of a foreign key. - PRIMARY
- Marks this column as the PRIMARY KEY.
- PRIMARY_
KEY - Alias for
PRIMARY. - REAL
- Sets the column type to
REAL. - REFERENCES
- Adds a foreign key that references a column of another table.
- RELATION
- Names the accessor that loads this table’s rows from the referenced table (the reverse relation).
- RESTRICT
RESTRICT: reject the delete or update while rows reference it.- RTRIM
- RTRIM collation: like
BINARYbut trailing spaces are ignored when comparing. - SET_
DEFAULT SET DEFAULT: set the referencing columns to their defaults.- SET_
NULL SET NULL: set the referencing columns to NULL.- STRICT
- Makes the table
STRICT, so SQLite rejects values that do not match the declared column types. - TEXT
- Sets the column type to
TEXT. - UNIQUE
- Adds a UNIQUE constraint to a column, table, or index.
- WHERE
- Makes an index partial: only rows matching the SQL predicate are indexed.
- WITHOUT_
ROWID - Makes the table
WITHOUT ROWID, stored as a clustered index on its primary key.
Type Aliases§
- Referential
Action - The type of the referential action constants (
CASCADE,SET_NULL, …).