Struct sequelite::model::Column

source ·
pub struct Column<'a> {
    pub table_name: &'a str,
    pub ty: SqliteType,
    /* private fields */
}
Expand description

A column of a model. This struct is quite big, so it is automatically implemented for every column in a struct that derives Model.

Fields§

§table_name: &'a str§ty: SqliteType

Implementations§

source§

impl<'a> Column<'a>

source

pub fn new( name: String, table_name: &'a str, ty: SqliteType, flags: Vec<SqliteFlag>, default: Option<Box<dyn IntoSqlite>>, relation: Option<ColumnRelation<'a>> ) -> Column<'a>

source

pub fn flags(&self) -> Vec<SqliteFlag>

source

pub fn name(&self) -> String

Returns the name of the column.

Example
User::id.name() == "id"
source

pub fn has_flag(&self, flag: SqliteFlag) -> bool

Check if the column has a specific flag.

Example
User::id.has_flag(SqliteFlag::PrimaryKey) == true
source

pub fn has_default(&self) -> bool

Check if the column has a default value.

source

pub fn can_insert_null(&self) -> bool

source

pub fn ref_<M: Model + ModelExt<M>>(self, id: i64) -> InQueryFilterwhere Self: ColumnQueryFilterImpl,

Shorthand method for filtering by a relation.

Expanded Example
// Short form
Post::select().filter(Post::author.ref_::<User>(1))
 
// Expanded form
Post::select().filter(Post::author.in_(User::select().columns(&[User::id]).with_id(1).limit(1)))
Panics

Panics if the column is not a relation

source§

impl Column<'static>

source

pub const fn new_const( name: &'static str, table_name: &'static str, ty: SqliteType, flags: &'static [SqliteFlag], default: Option<&'static dyn IntoSqlite>, relation: Option<ColumnRelation<'static>> ) -> Column<'static>

Creates a new column with static lifetime. This is used in the Model macro.

source

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

source

pub const fn get_relation(&self) -> Option<ColumnRelation<'static>>

Trait Implementations§

source§

impl Clone for Column<'_>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl ColumnQueryFilterImpl for Column<'_>

source§

fn eq<V: ToSql + 'static>(self, value: V) -> ColumnQueryFilter

Checks if the column is equal to the given value.

Example
User::select().filter(User::name.eq("John")).exec(conn);

This will generate the following SQL query:

-- ? is a parameter
SELECT * FROM users WHERE users.name = ?;
source§

fn ne<V: ToSql + 'static>(self, value: V) -> ColumnQueryFilter

Checks if the column is not equal to the given value.

Example
User::select().filter(User::name.ne("John")).exec(conn);

This will generate the following SQL query:

-- ? is a parameter
SELECT * FROM users WHERE users.name != ?;
source§

fn gt<V: ToSql + 'static>(self, value: V) -> ColumnQueryFilter

Checks if the column is greater than the given value.

Example
User::select().filter(User::age.gt(18)).exec(conn);

This will generate the following SQL query:

-- ? is a parameter
SELECT * FROM users WHERE users.age > ?;
source§

fn lt<V: ToSql + 'static>(self, value: V) -> ColumnQueryFilter

Checks if the column is less than the given value.

Example
User::select().filter(User::age.lt(18)).exec(conn);

This will generate the following SQL query:

-- ? is a parameter
SELECT * FROM users WHERE users.age < ?;
source§

fn ge<V: ToSql + 'static>(self, value: V) -> ColumnQueryFilter

Checks if the column is greater than or equal to the given value.

Example
User::select().filter(User::age.ge(18)).exec(conn);

This will generate the following SQL query:

-- ? is a parameter
SELECT * FROM users WHERE users.age >= ?;
source§

fn le<V: ToSql + 'static>(self, value: V) -> ColumnQueryFilter

Checks if the column is less than or equal to the given value.

Example
User::select().filter(User::age.le(18)).exec(conn);

This will generate the following SQL query:

-- ? is a parameter
SELECT * FROM users WHERE users.age <= ?;
source§

fn like<V: ToSql + 'static>(self, value: V) -> ColumnQueryFilter

Checks if the column is like the given value.

Example
User::select().filter(User::name.like("%John%")).exec(conn);

This will generate the following SQL query:

-- ? is a parameter
SELECT * FROM users WHERE users.name LIKE ?;
source§

fn not_like<V: ToSql + 'static>(self, value: V) -> ColumnQueryFilter

Checks if the column is not like the given value.

Example
User::select().filter(User::name.not_like("%John%")).exec(conn);

This will generate the following SQL query:

SELECT * FROM users WHERE users.name NOT LIKE ?;
source§

fn is_null(self) -> ColumnQueryFilterUnary

Check if the column is null (only for nullable columns)

Example
User::select().filter(User::name.is_null()).exec(conn);

This will generate the following SQL query:

SELECT * FROM users WHERE users.name IS NULL;
source§

fn is_not_null(self) -> ColumnQueryFilterUnary

Check if the column is not null (only for nullable columns)

Example
User::select().filter(User::name.is_not_null()).exec(conn);

This will generate the following SQL query:

SELECT * FROM users WHERE users.name IS NOT NULL;
source§

fn in_(self, values: impl ColumnInQuery) -> InQueryFilter

Check if the column is in the list of values

Example
User::select().filter(User::name.in_(vec!["John", "Jane"])).exec(conn);

This will generate the following SQL query:

-- ? is a parameter
SELECT * FROM users WHERE users.name IN (?, ?);
source§

fn not_in(self, values: impl ColumnInQuery) -> InQueryFilter

Check if the column is not in the list of values

Example
User::select().filter(User::name.not_in(vec!["John", "Jane"])).exec(conn);

This will generate the following SQL query:

-- ? is a parameter
SELECT * FROM users WHERE users.name NOT IN (?, ?);
source§

fn asc(self) -> ColumnQueryOrder

Order the query by the column in ascending order

Example
User::select().order_by(User::name.asc()).exec(conn);

This will generate the following SQL query:

SELECT * FROM users ORDER BY users.name ASC;
source§

fn desc(self) -> ColumnQueryOrder

Order the query by the column in descending order

Example
User::select().order_by(User::name.desc()).exec(conn);

This will generate the following SQL query:

SELECT * FROM users ORDER BY users.name DESC;
source§

impl Debug for Column<'_>

source§

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

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

impl<'a> IntoSqlite for Column<'a>

source§

impl PartialEq<Column<'_>> for Column<'_>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Column<'a>

§

impl<'a> !Send for Column<'a>

§

impl<'a> !Sync for Column<'a>

§

impl<'a> Unpin for Column<'a>

§

impl<'a> !UnwindSafe for Column<'a>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere T: Clone,

§

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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.