Skip to main content

QueryCore

Struct QueryCore 

Source
pub struct QueryCore {
    pub table: String,
    pub model_type: Option<String>,
    pub projection: Option<Vec<String>>,
    pub where_clauses: Vec<WhereClause>,
    pub order_by: Vec<OrderBy>,
    pub limit: Option<u32>,
    pub offset: Option<u32>,
    pub search_fields: Vec<String>,
    pub search_term: Option<String>,
    pub hop_source: Option<HopSource>,
    pub or_groups: Vec<Vec<WhereClause>>,
    pub group_by: Vec<String>,
}
Expand description

Core query builder that compiles per registered engine.

Fields§

§table: String§model_type: Option<String>§projection: Option<Vec<String>>§where_clauses: Vec<WhereClause>§order_by: Vec<OrderBy>§limit: Option<u32>§offset: Option<u32>§search_fields: Vec<String>§search_term: Option<String>§hop_source: Option<HopSource>

Previous hop in the chain. None for root queries, Some for hopped queries.

§or_groups: Vec<Vec<WhereClause>>

OR-combined clause groups for union queries.

§group_by: Vec<String>

GROUP BY fields for distinct/aggregation queries.

Implementations§

§

impl QueryCore

pub fn new(table: String) -> Self

Create a new query core for a table

pub fn with_model_type( table: impl Into<String>, model_type: impl Into<String>, ) -> Self

Create a QueryCore with model type information

§

impl QueryCore

pub fn where_int(self, field: String, predicate: IntPredicate) -> Self

Add a WHERE clause for an integer field

pub fn where_string(self, field: String, predicate: StringPredicate) -> Self

Add a WHERE clause for a string field

pub fn where_datetime(self, field: String, predicate: DateTimePredicate) -> Self

Add a WHERE clause for a datetime field

pub fn where_record(self, field: String, predicate: RecordPredicate) -> Self

Add a WHERE clause for a record field

pub fn where_null(self, field: String, predicate: NullPredicate) -> Self

Add a WHERE clause for null/not-null check on optional fields

pub fn where_connection_exists( self, from_field: String, to_table: String, subquery: QueryCore, ) -> Self

Add a correlated semi-join (SurrealQL SELECT … LIMIT 1 with $parent, not SQL EXISTS).

pub fn where_connection_exists_reverse( self, to_table: String, reverse_field: String, subquery: QueryCore, ) -> Self

Correlated semi-join for reverse/HasMany: to_table rows with reverse_field = $parent.id.

pub fn where_connection_exists_many_to_many( self, edge_table: String, to_table: String, subquery: QueryCore, ) -> Self

Semi-join filter for ManyToMany connections.

pub fn where_connection_contains_many_to_many( self, edge_table: String, target: RecordId, ) -> Self

Add a direct edge-membership filter for ManyToMany connections.

§

impl QueryCore

pub fn order_by(self, field: String, direction: SortDirection) -> Self

Add an ORDER BY clause

pub fn group_by(self, field: String) -> Self

Add a GROUP BY field

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

Set the LIMIT (clamped to super::MAX_QUERY_LIMIT).

pub fn offset(self, offset: u32) -> Self

Set the OFFSET (clamped to super::MAX_QUERY_OFFSET).

pub fn set_search_fields(self, fields: Vec<String>) -> Self

Set search fields for full-text search

pub fn search(self, term: String) -> Self

Add a search term (expands to OR clause across search_fields)

§

impl QueryCore

pub fn union_with(self, other: QueryCore) -> Self

OR-combine another query’s WHERE conditions with this one.

pub fn join_with(self, other: QueryCore) -> Self

AND-combine another query’s WHERE conditions with this one.

§

impl QueryCore

pub async fn execute<T>(self, valence: &Valence) -> Result<Vec<T>>

Compile the query for the active backend and execute it

§Errors

Returns an error when the requested operation cannot be completed.

pub async fn distinct_values( self, field: &str, valence: &Valence, ) -> Result<Vec<String>>

Execute as a distinct-value query, returning a flat Vec<String>.

§Errors

Returns an error when the requested operation cannot be completed.

§

impl QueryCore

pub fn select(self, fields: Vec<String>) -> Self

Set the projection fields for SELECT clause

If not set, defaults to SELECT *.

pub async fn get_id_only( table: impl Into<String>, id: impl AsRef<str>, valence: &Valence, ) -> Result<Option<IdOnlyRecord>>

Get a record by ID, returning a minimal result with just the ID

Loads via DatabaseBackend::get_record using table:id wire form.

§Errors

Returns an error when the requested operation cannot be completed.

pub async fn get_record_json( table: impl Into<String>, id: impl AsRef<str>, valence: &Valence, ) -> Result<Option<Value>>

Get a record by ID and return it as serde_json::Value.

Uses the table’s resolved crate::backend::DatabaseBackend (same routing as CRUD).

§Errors

Returns an error when the requested operation cannot be completed.

pub async fn latest_ids( table: impl Into<String>, limit: u32, valence: &Valence, ) -> Result<Vec<IdOnlyRecord>>

Get the latest N record IDs from a table, ordered by ID descending

This is useful for displaying sample records where only the ID is needed.

§Errors

Returns an error when the requested operation cannot be completed.

pub async fn get_entity( table: impl Into<String>, id: impl AsRef<str>, valence: &Valence, ) -> Result<Option<ValenceEntity>>

Get an entity with privacy filtering applied

This is the primary method for generic entity access. Returns a ValenceEntity with only the fields the viewer can see.

Flow:

  1. Check if record exists (lightweight query)
  2. Get schema metadata
  3. Load full record
  4. Check entity-level privacy
  5. Apply field-level privacy filtering
  6. Return ValenceEntity
§Errors

Returns an error when the requested operation cannot be completed.

Trait Implementations§

Source§

impl Clone for QueryCore

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 Debug for QueryCore

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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<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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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