pub struct Column<M> { /* private fields */ }Expand description
A column of model M.
#[derive(Model)] generates one associated constant per field, named
after the field in SCREAMING_SNAKE_CASE (User::EMAIL, User::ID, …).
Columns are tied to their model, so a Post column can’t accidentally be
used to filter Users.
Implementations§
Source§impl<M> Column<M>where
M: Model,
impl<M> Column<M>where
M: Model,
Sourcepub fn contains(self, text: &str) -> Expr<M>
pub fn contains(self, text: &str) -> Expr<M>
column LIKE '%text%', escaping %, _ and \ in text.
Sourcepub fn starts_with(self, text: &str) -> Expr<M>
pub fn starts_with(self, text: &str) -> Expr<M>
column LIKE 'text%', escaping %, _ and \ in text.
Sourcepub fn ends_with(self, text: &str) -> Expr<M>
pub fn ends_with(self, text: &str) -> Expr<M>
column LIKE '%text', escaping %, _ and \ in text.
Sourcepub fn is_in<V>(self, values: impl IntoIterator<Item = V>) -> Expr<M>
pub fn is_in<V>(self, values: impl IntoIterator<Item = V>) -> Expr<M>
column IN (…). An empty list matches nothing.
Sourcepub fn not_in<V>(self, values: impl IntoIterator<Item = V>) -> Expr<M>
pub fn not_in<V>(self, values: impl IntoIterator<Item = V>) -> Expr<M>
column NOT IN (…). An empty list matches everything.
Sourcepub fn in_subquery<N>(self, subquery: Projected<N>) -> Expr<M>where
N: Model,
pub fn in_subquery<N>(self, subquery: Projected<N>) -> Expr<M>where
N: Model,
column IN (subquery), where the subquery selects one column.
// Users who wrote a post with more than 100 views.
User::filter(User::ID.in_subquery(
Post::filter(Post::VIEWS.gt(100)).select(Post::AUTHOR_ID),
))Sourcepub fn not_in_subquery<N>(self, subquery: Projected<N>) -> Expr<M>where
N: Model,
pub fn not_in_subquery<N>(self, subquery: Projected<N>) -> Expr<M>where
N: Model,
column NOT IN (subquery). Beware that NOT IN matches nothing if
the subquery returns any NULL; prefer Expr::not_exists then.
Sourcepub fn eq_outer<O>(self, outer: Column<O>) -> Expr<M>
pub fn eq_outer<O>(self, outer: Column<O>) -> Expr<M>
Compare this column to a column of the enclosing query’s model, for
correlated subqueries: "posts"."author_id" = "users"."id".
// Users with at least one post.
User::filter(Expr::exists(Post::filter(Post::AUTHOR_ID.eq_outer(User::ID))))Sourcepub fn between(self, low: impl Into<Value>, high: impl Into<Value>) -> Expr<M>
pub fn between(self, low: impl Into<Value>, high: impl Into<Value>) -> Expr<M>
column BETWEEN low AND high
Sourcepub fn is_not_null(self) -> Expr<M>
pub fn is_not_null(self) -> Expr<M>
column IS NOT NULL
Sourcepub fn eq_any<T>(self, values: impl IntoIterator<Item = T>) -> Expr<M>
pub fn eq_any<T>(self, values: impl IntoIterator<Item = T>) -> Expr<M>
column = ANY($1) with a single array parameter — like
is_in, but one parameter however many values, so it
suits very large lists.
Sourcepub fn array_contains(self, values: impl Into<Value>) -> Expr<M>
pub fn array_contains(self, values: impl Into<Value>) -> Expr<M>
Array column contains every element of values (column @> $1).
Sourcepub fn array_overlaps(self, values: impl Into<Value>) -> Expr<M>
pub fn array_overlaps(self, values: impl Into<Value>) -> Expr<M>
Array column shares at least one element with values (column && $1).
Sourcepub fn array_has(self, value: impl Into<Value>) -> Expr<M>
pub fn array_has(self, value: impl Into<Value>) -> Expr<M>
Array column contains value ($1 = ANY(column)).
Sourcepub fn json_has_key(self, key: &str) -> Expr<M>
pub fn json_has_key(self, key: &str) -> Expr<M>
JSONB column has the top-level key key (column ? $1).
Sourcepub fn json_has_any_key<K>(self, keys: impl IntoIterator<Item = K>) -> Expr<M>
pub fn json_has_any_key<K>(self, keys: impl IntoIterator<Item = K>) -> Expr<M>
JSONB column has any of keys (column ?| $1).
Sourcepub fn json_has_all_keys<K>(self, keys: impl IntoIterator<Item = K>) -> Expr<M>
pub fn json_has_all_keys<K>(self, keys: impl IntoIterator<Item = K>) -> Expr<M>
JSONB column has all of keys (column ?& $1).
Sourcepub fn json_contains(self, json: Value) -> Expr<M>
pub fn json_contains(self, json: Value) -> Expr<M>
JSONB column contains json (column @> $1), e.g.
User::PREFS.json_contains(json!({"theme": "dark"})).
Sourcepub fn json_text(self, key: &str) -> Projection<M>
pub fn json_text(self, key: &str) -> Projection<M>
The text value at key of a JSON/JSONB column (column ->> $1), to
filter, select or order by: User::PREFS.json_text("theme").eq("dark").
Sourcepub fn json_path_text<K>(
self,
path: impl IntoIterator<Item = K>,
) -> Projection<M>
pub fn json_path_text<K>( self, path: impl IntoIterator<Item = K>, ) -> Projection<M>
The text value at a nested path (column #>> $1):
Event::DATA.json_path_text(["user", "id"]).
Sourcepub fn search(self, query: &str) -> Expr<M>
pub fn search(self, query: &str) -> Expr<M>
Full-text search on a text column with the server’s default text
search configuration:
to_tsvector(column) @@ websearch_to_tsquery($1).
query uses web-search syntax: rust -java "query builder" or orm.
For speed, index to_tsvector(column) or use a generated tsvector
column with ts_matches.
Sourcepub fn search_in(self, config: &str, query: &str) -> Expr<M>
pub fn search_in(self, config: &str, query: &str) -> Expr<M>
search with an explicit configuration such as
"english" (enables stemming and stop words).
Sourcepub fn ts_matches(self, query: &str) -> Expr<M>
pub fn ts_matches(self, query: &str) -> Expr<M>
Match a tsvector column: column @@ websearch_to_tsquery($1).
Sourcepub fn search_rank(self, query: &str) -> Projection<M>
pub fn search_rank(self, query: &str) -> Projection<M>
Relevance of a text column for query, to order results:
.order_by(Post::BODY.search_rank("rust orm").desc()).
Sourcepub fn count(self) -> Projection<M>
pub fn count(self) -> Projection<M>
COUNT(column) — number of non-NULL values.
Sourcepub fn count_distinct(self) -> Projection<M>
pub fn count_distinct(self) -> Projection<M>
COUNT(DISTINCT column)
Sourcepub fn sum(self) -> Projection<M>
pub fn sum(self) -> Projection<M>
SUM(column). PostgreSQL returns BIGINT for SMALLINT/INTEGER
columns and NUMERIC for BIGINT columns; use
Projection::cast to pick the Rust type you decode into.
Sourcepub fn avg(self) -> Projection<M>
pub fn avg(self) -> Projection<M>
AVG(column), returned as NUMERIC for integer columns; see
Projection::cast.
Sourcepub fn min(self) -> Projection<M>
pub fn min(self) -> Projection<M>
MIN(column)
Sourcepub fn max(self) -> Projection<M>
pub fn max(self) -> Projection<M>
MAX(column)
Trait Implementations§
impl<M> Copy for Column<M>
Source§impl<M> From<Column<M>> for Projection<M>where
M: Model,
impl<M> From<Column<M>> for Projection<M>where
M: Model,
Source§fn from(column: Column<M>) -> Projection<M>
fn from(column: Column<M>) -> Projection<M>
Source§impl<M> IntoProjections<M> for Column<M>where
M: Model,
impl<M> IntoProjections<M> for Column<M>where
M: Model,
Source§fn into_projections(self) -> Vec<Projection<M>>
fn into_projections(self) -> Vec<Projection<M>>
Auto Trait Implementations§
impl<M> Freeze for Column<M>
impl<M> RefUnwindSafe for Column<M>
impl<M> Send for Column<M>
impl<M> Sync for Column<M>
impl<M> Unpin for Column<M>
impl<M> UnsafeUnpin for Column<M>
impl<M> UnwindSafe for Column<M>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<M> InScope<(M, ()), Here> for M
impl<M, Rest, N> InScope<(M, (Rest, N)), Last> for N
impl<X, M, Rest, N, I> InScope<(M, (Rest, N)), There<I>> for X
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more