Skip to main content

Query

Struct Query 

Source
pub struct Query<R, T = Vec<R>> { /* private fields */ }
Expand description

A query over the rows of R’s table that materializes to a T: the rows (Vec<R>), the row of one() (Option<R>), or an aggregate.

Implementations§

Source§

impl<R, T> Query<R, T>

Source

pub fn from_any(any: AnyQuery) -> Self

The typed form of an untyped query of R’s table.

Source

pub fn any(&self) -> &AnyQuery

The untyped query this one builds.

Source

pub fn into_any(self) -> AnyQuery

The untyped query this one wraps.

Source§

impl<R: ZeroRow> Query<R>

Source

pub fn table(schema: Arc<Schema>) -> Self

All rows of R’s table, for the generated query functions.

Source§

impl<R: ZeroRow, T> Query<R, T>

Source

pub fn where_eq<V: ZeroValue>(self, column: Column<R, V>, value: V) -> Self

Rows whose column equals value; with null, IS.

Source

pub fn where_<V: ZeroValue>( self, column: Column<R, V>, op: SimpleOperator, value: V, ) -> Self

Rows whose column compares to value by op.

Source

pub fn where_in<V: ZeroValue>( self, column: Column<R, V>, op: SimpleOperator, values: Vec<V>, ) -> Self

Rows whose column is IN or NOT IN values.

Source

pub fn where_param<V>( self, column: Column<R, V>, op: SimpleOperator, param: &StaticParameter, ) -> Self

Rows whose column compares to a value of the context by op.

Source

pub fn where_condition(self, condition: Condition) -> Self

Rows that match condition, and any earlier where.

Source

pub fn where_expr( self, factory: impl FnOnce(&RowExpression<'_, '_, R>) -> Condition, ) -> Self

Rows that match the condition factory builds from the row’s expression: its JSON paths, exists, and and, or and not.

Source

pub fn where_exists<D: ZeroRow>( self, relationship: Relationship<R, D>, options: ExistsOptions, sub: impl FnOnce(Query<D>) -> Query<D>, ) -> Self

Rows with a related row in relationship that sub matches.

Source

pub fn related<D: ZeroRow, S>( self, relationship: Relationship<R, D>, sub: impl FnOnce(Query<D>) -> Query<D, S>, ) -> Self

Fills relationship of each row, or, when sub ends in an aggregate, sets the row’s aggregate of it: related(Issue::COMMENTS, |q| q.count()) gives aggregates.count(Issue::COMMENTS).

Source

pub fn order_by<V>(self, column: Column<R, V>, direction: Direction) -> Self

Orders the rows by column, after any earlier order_by; the primary key breaks ties.

Source

pub fn limit(self, limit: i64) -> Self

At most limit rows.

Source

pub fn start(self, row: &R, inclusive: bool) -> Self

Starts after row, or at it when inclusive.

Source

pub fn start_values( self, values: Vec<(ColumnRef<R>, Value)>, inclusive: bool, ) -> Self

Starts after the row with these column values, or at it when inclusive: a cursor that holds only the columns the query orders by.

Source

pub fn one(self) -> Query<R, Option<R>>

At most one row.

Source

pub fn count(self) -> Query<R, i64>

Reduces the query to a count of the rows left after where, start and limit.

Source

pub fn sum<V: NumericZeroValue>( self, column: Column<R, V>, ) -> Query<R, Option<f64>>

The sum of a number column; None over no rows.

Source

pub fn sum_json<V>( self, column: Column<R, V>, path: Vec<JsonPathSegment>, ) -> Query<R, Option<f64>>

The sum of the numbers at path in a json column. A missing path, or a value that isn’t a number, is skipped.

Source

pub fn avg<V: NumericZeroValue>( self, column: Column<R, V>, ) -> Query<R, Option<f64>>

The average of a number column; None over no rows.

Source

pub fn avg_json<V>( self, column: Column<R, V>, path: Vec<JsonPathSegment>, ) -> Query<R, Option<f64>>

Reduces the query to the average of the numbers at path in the JSON column.

Source

pub fn min<V: OrderedZeroValue>( self, column: Column<R, V>, ) -> Query<R, Option<V::Unwrapped>>

The least value of a number or string column; None over no rows.

Source

pub fn min_json<V>( self, column: Column<R, V>, path: Vec<JsonPathSegment>, ) -> Query<R, Option<Value>>

Reduces the query to the least value at path in the JSON column.

Source

pub fn max<V: OrderedZeroValue>( self, column: Column<R, V>, ) -> Query<R, Option<V::Unwrapped>>

The greatest value of a number or string column; None over no rows.

Source

pub fn max_json<V>( self, column: Column<R, V>, path: Vec<JsonPathSegment>, ) -> Query<R, Option<Value>>

Reduces the query to the greatest value at path in the JSON column.

Source

pub fn distinct( self, columns: Vec<ColumnRef<R>>, ) -> Query<R, Vec<DistinctRow<R>>>

The distinct combinations of columns among the rows where keeps. count() after it counts the combinations.

Source

pub fn group_by(self, columns: Vec<ColumnRef<R>>) -> GroupedQuery<R>

Groups the rows by columns, for the aggregate that reduces each group.

Source§

impl<R, T: QueryValue> Query<R, T>

Source

pub fn read(&self, view: &ViewValue) -> Result<T, ZeroValueError>

Reads a view of this query as its result.

Trait Implementations§

Source§

impl<R, T> Clone for Query<R, T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<R, T> Debug for Query<R, T>

Source§

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

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

impl<C, R, T: QueryValue> TypedQuery<C> for Query<R, T>

Source§

type Value = T

What the query’s view reads as.
Source§

impl<C, R, T> ZeroQuery<C> for Query<R, T>

Source§

fn any_query(&self, _: &C) -> Cow<'_, AnyQuery>

The query, as context sees it.

Auto Trait Implementations§

§

impl<R, T> Forget for Query<R, T>

§

impl<R, T> Freeze for Query<R, T>
where PhantomData<fn() -> (R, T)>: Freeze,

§

impl<R, T> Move for Query<R, T>

§

impl<R, T> RefUnwindSafe for Query<R, T>

§

impl<R, T> Send for Query<R, T>
where PhantomData<fn() -> (R, T)>: Send,

§

impl<R, T> Sync for Query<R, T>
where PhantomData<fn() -> (R, T)>: Sync,

§

impl<R, T> Unpin for Query<R, T>
where PhantomData<fn() -> (R, T)>: Unpin,

§

impl<R, T> UnsafeUnpin for Query<R, T>

§

impl<R, T> UnwindSafe for Query<R, T>

Blanket Implementations§

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, 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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.