pub struct QueryBuilder<T> { /* private fields */ }Implementations§
Source§impl<T> QueryBuilder<T>
impl<T> QueryBuilder<T>
pub fn new(table: impl Into<String>, pk: impl Into<String>) -> Self
Sourcepub fn with_soft_delete_col(self, col: impl Into<String>) -> Self
pub fn with_soft_delete_col(self, col: impl Into<String>) -> Self
Устанавливает имя колонки soft-delete. Если установлено, автоматически добавляет WHERE col IS NULL.
Sourcepub fn filter_raw(self, sql: impl Into<String>) -> Self
pub fn filter_raw(self, sql: impl Into<String>) -> Self
Добавляет сырое WHERE условие.
Sourcepub fn filter_if<F>(self, condition: bool, f: F) -> Self
pub fn filter_if<F>(self, condition: bool, f: F) -> Self
Условный фильтр — добавляется только если condition == true.
Sourcepub fn with_deleted(self) -> Self
pub fn with_deleted(self) -> Self
Включить удалённые записи.
Sourcepub fn only_deleted(self) -> Self
pub fn only_deleted(self) -> Self
Только удалённые записи.
Sourcepub fn select_cols(
self,
cols: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn select_cols( self, cols: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Выбрать конкретные колонки.
pub fn select_distinct_col(self, col: impl Into<String>) -> Self
Sourcepub fn inner_join(self, table: impl Into<String>, on: impl Into<String>) -> Self
pub fn inner_join(self, table: impl Into<String>, on: impl Into<String>) -> Self
INNER JOIN таблицы с ON-выражением.
pub fn group_by_col(self, col: impl Into<String>) -> Self
pub fn having_raw(self, sql: impl Into<String>) -> Self
pub fn order_by<F>(self, f: F) -> Self
pub fn order_by_raw(self, sql: impl Into<String>) -> Self
pub fn order_by_random(self) -> Self
pub fn limit(self, n: i64) -> Self
pub fn offset(self, n: i64) -> Self
Sourcepub fn paginate(self, page: i64, per_page: i64) -> Self
pub fn paginate(self, page: i64, per_page: i64) -> Self
Выставляет limit/offset для страницы page (с 1), per_page записей.
Sourcepub fn build_select(&self) -> (String, Vec<SqlValue>)
pub fn build_select(&self) -> (String, Vec<SqlValue>)
Строит финальный SELECT SQL и список bind-значений.
Sourcepub async fn fetch_all(self, pool: &PgPool) -> OrmResult<Vec<T>>
pub async fn fetch_all(self, pool: &PgPool) -> OrmResult<Vec<T>>
Выполняет запрос и возвращает Vec<T>.
Sourcepub async fn first_or_fail(self, pool: &PgPool) -> OrmResult<T>
pub async fn first_or_fail(self, pool: &PgPool) -> OrmResult<T>
Первая или OrmError::NotFound.
Sourcepub async fn last(self, pool: &PgPool) -> OrmResult<Option<T>>
pub async fn last(self, pool: &PgPool) -> OrmResult<Option<T>>
Последняя запись (обратный порядок по PK).
Sourcepub async fn count(self, pool: &PgPool) -> OrmResult<i64>
pub async fn count(self, pool: &PgPool) -> OrmResult<i64>
Количество записей, удовлетворяющих фильтру.
Sourcepub async fn exists(self, pool: &PgPool) -> OrmResult<bool>
pub async fn exists(self, pool: &PgPool) -> OrmResult<bool>
Существует ли хоть одна запись по фильтру.
Sourcepub async fn fetch_page(
self,
page: i64,
per_page: i64,
pool: &PgPool,
) -> OrmResult<Page<T>>
pub async fn fetch_page( self, page: i64, per_page: i64, pool: &PgPool, ) -> OrmResult<Page<T>>
Пагинированный результат.
Sourcepub async fn update_all<F>(self, f: F, pool: &PgPool) -> OrmResult<u64>
pub async fn update_all<F>(self, f: F, pool: &PgPool) -> OrmResult<u64>
UPDATE table SET ... WHERE <накопленные фильтры> — возвращает кол-во строк.
Sourcepub async fn delete_all(self, pool: &PgPool) -> OrmResult<u64>
pub async fn delete_all(self, pool: &PgPool) -> OrmResult<u64>
DELETE FROM table WHERE <накопленные фильтры> — возвращает кол-во строк.
Trait Implementations§
Source§impl<T> Clone for QueryBuilder<T>
impl<T> Clone for QueryBuilder<T>
Auto Trait Implementations§
impl<T> Freeze for QueryBuilder<T>
impl<T> RefUnwindSafe for QueryBuilder<T>where
T: RefUnwindSafe,
impl<T> Send for QueryBuilder<T>where
T: Send,
impl<T> Sync for QueryBuilder<T>where
T: Sync,
impl<T> Unpin for QueryBuilder<T>where
T: Unpin,
impl<T> UnsafeUnpin for QueryBuilder<T>
impl<T> UnwindSafe for QueryBuilder<T>where
T: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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