pub enum SQLiteType {
Integer,
Text,
Blob,
Real,
Numeric,
Any,
}Expand description
A SQLite column type as written in DDL.
These are the types a STRICT table accepts, plus NUMERIC; see
SQLite datatypes. The type decides
which column attributes are allowed (is_valid_flag).
§Examples
use drizzle_types::sqlite::SQLiteType;
let int_type = SQLiteType::Integer;
assert_eq!(int_type.to_sql_type(), "INTEGER");
assert!(int_type.is_valid_flag("autoincrement"));
let text_type = SQLiteType::Text;
assert!(text_type.is_valid_flag("json"));
assert!(!text_type.is_valid_flag("autoincrement"));Variants§
Integer
SQLite INTEGER type - stores signed integers up to 8 bytes.
See: https://sqlite.org/datatype3.html#integer_datatype
Supports: primary keys, autoincrement, enums (discriminant storage)
Text
SQLite TEXT type - stores text in UTF-8, UTF-16BE, or UTF-16LE encoding.
See: https://sqlite.org/datatype3.html#text_datatype
Supports: enums (variant name storage), JSON (#[column(json)])
Blob
SQLite BLOB type - stores binary data exactly as input.
See: https://sqlite.org/datatype3.html#blob_datatype
Used for byte arrays and UUIDs.
Real
SQLite REAL type - stores floating point values as 8-byte IEEE floating point numbers.
Numeric
SQLite NUMERIC type - stores values as INTEGER, REAL, or TEXT depending on the value.
Any
SQLite ANY type - no type affinity, can store any type of data.
This holds in STRICT tables; elsewhere SQLite gives a column declared
ANY NUMERIC affinity. The default.
Implementations§
Source§impl SQLiteType
impl SQLiteType
Sourcepub const fn from_attribute_name(name: &str) -> Option<Self>
pub const fn from_attribute_name(name: &str) -> Option<Self>
Parses a type name from a column attribute, ignoring case. Returns
None for unknown names.
Also accepts "number" (as NUMERIC) and "boolean" (as INTEGER).
Sourcepub const fn to_sql_type(&self) -> &'static str
pub const fn to_sql_type(&self) -> &'static str
Returns the type as written in DDL, such as "INTEGER".
Sourcepub const fn affinity(&self) -> SQLiteAffinity
pub const fn affinity(&self) -> SQLiteAffinity
Returns this type’s SQLite affinity.
Sourcepub const fn is_strict_allowed(&self) -> bool
pub const fn is_strict_allowed(&self) -> bool
Returns true if a STRICT table accepts this type: every type except NUMERIC.
Sourcepub fn is_valid_flag(&self, flag: &str) -> bool
pub fn is_valid_flag(&self, flag: &str) -> bool
Returns true if the column attribute flag can be used with this type.
Valid flags per type:
INTEGER:primary,primary_key,unique,autoincrement,enumTEXT:primary,primary_key,unique,json,enumBLOB:primary,primary_key,uniqueREAL:primary,primary_key,uniqueNUMERIC:primary,primary_key,uniqueANY:primary,primary_key,unique