Skip to main content

Select

Struct Select 

Source
pub struct Select<T: SurrealRecord> { /* private fields */ }
Expand description

A SELECT statement builder: projections, WHERE, ORDER BY, LIMIT, START, FETCH, GROUP BY/GROUP ALL, count(), and the modifiers VALUE/OMIT/SPLIT/WITH/TIMEOUT/EXPLAIN.

Implementations§

Source§

impl<T: SurrealRecord> Select<T>

Source

pub fn filter(self, expr: impl DynExpr + 'static) -> Self

Source

pub fn with_path(self, path: Path, alias: &'static str) -> Self

Add a <path> AS <alias> graph-traversal projection to the select list. Appends to any existing projections, so select(T::all()).with_path(p, "x") renders SELECT *, <path> AS x (a * is emitted only when the list is otherwise empty).

Source

pub fn limit(self, n: u32) -> Self

Source

pub fn start(self, n: u32) -> Self

Source

pub fn fetch(self, field: impl Into<String>) -> Self

Source

pub fn group_by<C: DynExpr>(self, col: C) -> Self

Source

pub fn group_all(self) -> Self

GROUP ALL (whole-table aggregate, e.g. with count()).

Source

pub fn count_as(self, alias: &'static str) -> Self

Alias for the count() projection: SELECT count() AS <alias>.

Source

pub fn value(self) -> Self

SELECT VALUE … — return bare values instead of field-wrapping objects. Pair with a single projection (e.g. project(vec![col("name")]).value()).

Source

pub fn omit(self, field: impl Into<String>) -> Self

OMIT <field> — exclude a field from a SELECT *.

Source

pub fn split(self, field: impl Into<String>) -> Self

SPLIT <field> — fan one row out into multiple rows by an array field.

Source

pub fn with_index<I, S>(self, indexes: I) -> Self
where I: IntoIterator<Item = S>, S: AsRef<str>,

WITH INDEX <a, b> — force the planner to use the named index(es).

Source

pub fn with_no_index(self) -> Self

WITH NOINDEX — force a table scan (ignore indexes).

Source

pub fn timeout(self, duration: impl Into<String>) -> Self

TIMEOUT <duration> — abort the query after the given duration (e.g. "5s").

Source

pub fn from_subquery(self, sub: Select<T>) -> Self

SELECT … FROM (<subquery>) — read from a subquery instead of the base table. The subquery (a Select<T> of the same record type) renders parenthesized in place of the table name.

Source

pub fn explain(self) -> Self

EXPLAIN — return the query plan instead of results.

Source

pub fn explain_full(self) -> Self

EXPLAIN FULL — return the query plan with execution detail.

Source

pub fn order_by<C: DynExpr>(self, col: C, dir: Order) -> Self

Source

pub fn order_asc<C: DynExpr>(self, col: C) -> Self

Source

pub fn order_desc<C: DynExpr>(self, col: C) -> Self

Source

pub fn to_surrealql(&self) -> String

Source

pub fn to_surrealql_with_params(&self) -> (String, BTreeMap<String, Value>)

Render the statement with $param placeholders instead of inlined literals, returning the SQL string and a map of parameter name to value. Literal values become numbered $p0, $p1, …; explicit Param wrappers use their declared name.

Trait Implementations§

Source§

impl<T: SurrealRecord> Debug for Select<T>

Source§

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

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

impl<T: SurrealRecord> Display for Select<T>

Source§

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

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

impl<T: SurrealRecord> DynExpr for Select<T>

A Select is usable as an expression — rendered parenthesized — so it can be embedded as a subquery: a scalar/IN operand in a WHERE, a projection, or a SET/FROM value. Params from the subquery merge into the parent’s map.

Source§

fn render_dyn(&self, buf: &mut String)

Append this expression’s SurrealQL to buf with all values inlined.
Source§

fn render_dyn_params( &self, buf: &mut String, params: &mut BTreeMap<String, Value>, )

Render with $param placeholders, collecting values into params. Default falls back to inline rendering; Literal nodes override this to emit $pN placeholders and collect their value.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for Select<T>

§

impl<T> !UnwindSafe for Select<T>

§

impl<T> Freeze for Select<T>

§

impl<T> Send for Select<T>

§

impl<T> Sync for Select<T>

§

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

§

impl<T> UnsafeUnpin for Select<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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<E> Expr for E
where E: DynExpr,

Source§

fn ty_hint(&self) -> &'static str

A best-effort SurrealQL type name for this expression.
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool