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: SqliteTypeImplementations§
source§impl<'a> Column<'a>
impl<'a> Column<'a>
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>
pub fn flags(&self) -> Vec<SqliteFlag>
sourcepub fn has_flag(&self, flag: SqliteFlag) -> bool
pub fn has_flag(&self, flag: SqliteFlag) -> bool
sourcepub fn has_default(&self) -> bool
pub fn has_default(&self) -> bool
Check if the column has a default value.
pub fn can_insert_null(&self) -> bool
sourcepub fn ref_<M: Model + ModelExt<M>>(self, id: i64) -> InQueryFilterwhere
Self: ColumnQueryFilterImpl,
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>
impl Column<'static>
sourcepub 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>
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.
pub const fn name_const(&self) -> &'static str
pub const fn get_relation(&self) -> Option<ColumnRelation<'static>>
Trait Implementations§
source§impl ColumnQueryFilterImpl for Column<'_>
impl ColumnQueryFilterImpl for Column<'_>
source§fn eq<V: ToSql + 'static>(self, value: V) -> ColumnQueryFilter
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
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
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
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
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
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
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
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
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
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
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
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
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
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;