Skip to main content

Query

Struct Query 

Source
pub struct Query<T> { /* private fields */ }
Expand description

A value representing a sql select statement which produces rows of type T.

Implementations§

Source§

impl<'scope, T> Query<T>
where T: Table<'scope> + ForLifetimeTable,

Source

pub fn aggregate<U>( self, f: impl for<'inner, 'outer> FnOnce(&mut A<'inner, 'outer>, T::WithLt<'inner>) -> U::WithLt<'outer>, ) -> Query<U::WithLt<'scope>>

Enter a context in which A can be used to build aggregations.

The callback f will receive an A, the methods of which can be used to build a table in the 'outer scope.

Source

pub fn many(self) -> Query<ListTable<T>>

Construct a simple list aggregation for this query.

That is, all rows of this query will be aggregated into an array.

Source

pub fn window<U>( self, f: impl for<'inner, 'outer> FnOnce(&mut W<'inner, 'outer>, T::WithLt<'inner>) -> U::WithLt<'outer>, ) -> Query<U::WithLt<'scope>>
where U: ForLifetimeTable + Table<'scope>,

Enter a context in which W can be used to insert expressions using window functions.

The callback f will receive an [F], the methods of which can be used to build a table in the 'outer scope.

Source

pub fn evaluate(table: T) -> Self

Lift a table into a query which ensures side effects happen and are not shared.

Source

pub fn optional(self) -> Query<MaybeTable<'scope, T>>

Transform this query into one which produces rows of either Some<T> or None.

That is, this turns the query into a left join.

Source

pub fn nullable(self) -> Query<NullTable<'scope, T>>

Make this table nullable. Unlike MaybeTable, this isn’t a left join, but instead considers the table null if any of the non-nullable columns are null.

If the table only contains Option<T> then this table cannot distinguish.

Source

pub fn order_by<U, F>(self, f: F) -> Query<T>
where U: Table<'scope>, F: FnOnce(&T) -> (U, Order),

Add an order by clause to the query, the given function should return a table, the query will be ordered by each column of the table.

Source§

impl<'scope, T> Query<T>
where T: MapTable<'scope> + TableHKT<Mode = NameMode>, T::InMode<ExprMode>: ForLifetimeTable + Table<'scope>,

Source

pub fn each(schema: &TableSchema<T>) -> Query<T::InMode<ExprMode>>

Given a TableSchema, build a query that selects all columns of every row.

Source§

impl<'scope, T: TableHKT<Mode = ValueMode>> Query<T>

Source

pub fn values(vals: impl IntoIterator<Item = T>) -> Query<T::InMode<ExprMode>>
where T: MapTable<'scope>, T::InMode<ExprMode>: ForLifetimeTable + Table<'scope>,

Construct a query yielding the given rows

Source§

impl<T: TableLoaderSqlx> Query<T>

Source

pub async fn all(&self, pool: &mut PgConnection) -> Result<Vec<T::Result>>

Load all rows of the query

Trait Implementations§

Source§

impl<T: Clone> Clone for Query<T>

Source§

fn clone(&self) -> Query<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Query<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Query<T>
where T: RefUnwindSafe,

§

impl<T> Send for Query<T>
where T: Send,

§

impl<T> Sync for Query<T>
where T: Sync,

§

impl<T> Unpin for Query<T>
where T: Unpin,

§

impl<T> UnwindSafe for Query<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

type Alias = T

Always set to Self, but the type checker doesn’t reduce T::Alias to T.
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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

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

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T, U> IsEqual<U> for T
where T: AliasSelf<Alias = U> + ?Sized, U: ?Sized,