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
impl QueryCore
pub fn where_int(self, field: String, predicate: IntPredicate) -> Self
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
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
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
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
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
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
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
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
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
impl QueryCore
pub fn order_by(self, field: String, direction: SortDirection) -> Self
pub fn order_by(self, field: String, direction: SortDirection) -> Self
Add an ORDER BY clause
pub fn limit(self, limit: u32) -> Self
pub fn limit(self, limit: u32) -> Self
Set the LIMIT (clamped to super::MAX_QUERY_LIMIT).
pub fn offset(self, offset: u32) -> Self
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
pub fn set_search_fields(self, fields: Vec<String>) -> Self
Set search fields for full-text search
§impl QueryCore
impl QueryCore
pub fn union_with(self, other: QueryCore) -> Self
pub fn union_with(self, other: QueryCore) -> Self
OR-combine another query’s WHERE conditions with this one.
§impl QueryCore
impl QueryCore
§impl QueryCore
impl QueryCore
pub fn select(self, fields: Vec<String>) -> Self
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>>
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>>
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>>
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>>
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:
- Check if record exists (lightweight query)
- Get schema metadata
- Load full record
- Check entity-level privacy
- Apply field-level privacy filtering
- Return ValenceEntity
§Errors
Returns an error when the requested operation cannot be completed.