Skip to main content

Module attrs

Module attrs 

Source
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§

ColumnMarker
The type of the column constraint and option constants.
IndexMarker
The type of the index option constants.
NameMarker
The type of the NAME constant.
TableMarker
The type of the table option constants.
TypeMarker
The type of the column type constants.
ViewMarker
The type of the view option constants.

Constants§

ANY
Sets the column type to ANY (STRICT tables only).
AUTOINCREMENT
Adds AUTOINCREMENT to an INTEGER PRIMARY KEY column, so rowids of deleted rows are never reused.
BINARY
BINARY collation: bytewise comparison of operands. The default for BLOB columns and any column without an explicit collation.
BLOB
Sets the column type to BLOB.
BOOLEAN
Stores a bool as INTEGER 0 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 DEFAULT clause 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) or virtual (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: like RESTRICT, but checked at the end of the statement. The default.
NUMERIC
Sets the column type to NUMERIC.
ON_DELETE
Sets the ON DELETE action of a foreign key.
ON_UPDATE
Sets the ON UPDATE action 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 BINARY but 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§

ReferentialAction
The type of the referential action constants (CASCADE, SET_NULL, …).