Skip to main content

SQLiteType

Enum SQLiteType 

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

See: https://sqlite.org/datatype3.html#real_datatype

§

Numeric

SQLite NUMERIC type - stores values as INTEGER, REAL, or TEXT depending on the value.

See: https://sqlite.org/datatype3.html#numeric_datatype

§

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.

See: https://sqlite.org/stricttables.html

Implementations§

Source§

impl SQLiteType

Source

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).

Source

pub const fn to_sql_type(&self) -> &'static str

Returns the type as written in DDL, such as "INTEGER".

Source

pub const fn affinity(&self) -> SQLiteAffinity

Returns this type’s SQLite affinity.

Source

pub const fn is_strict_allowed(&self) -> bool

Returns true if a STRICT table accepts this type: every type except NUMERIC.

Source

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, enum
  • TEXT: primary, primary_key, unique, json, enum
  • BLOB: primary, primary_key, unique
  • REAL: primary, primary_key, unique
  • NUMERIC: primary, primary_key, unique
  • ANY: primary, primary_key, unique

Trait Implementations§

Source§

impl Clone for SQLiteType

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for SQLiteType

Source§

impl Debug for SQLiteType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SQLiteType

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for SQLiteType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for SQLiteType

Source§

impl Hash for SQLiteType

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for SQLiteType

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for SQLiteType

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.