pub enum Pred {
Show 22 variants
Always,
Eq(&'static str, Value),
Ne(&'static str, Value),
Lt(&'static str, Value),
Le(&'static str, Value),
Gt(&'static str, Value),
Ge(&'static str, Value),
Contains(&'static str, String),
ContainsCi(&'static str, String),
StartsWith(&'static str, String),
StartsWithCi(&'static str, String),
Between(&'static str, Value, Value),
In(&'static str, Vec<Value>),
NotIn(&'static str, Vec<Value>),
IdIn(Vec<u64>),
Related {
owner: &'static str,
field: &'static str,
target: &'static str,
quant: Quant,
inner: Box<Pred>,
},
And(Box<Pred>, Box<Pred>),
Or(Box<Pred>, Box<Pred>),
Not(Box<Pred>),
Raw(String, Vec<Value>),
Matches {
columns: &'static [&'static str],
query: String,
},
Within {
lat: &'static str,
lon: &'static str,
min_lat: f64,
max_lat: f64,
min_lon: f64,
max_lon: f64,
},
}Expand description
A predicate as a value. Compiles to SQL; the fallback evaluator (Pred::eval) exists
for drivers that cannot fold case exactly, and for tests.
Variants§
Always
Eq(&'static str, Value)
Ne(&'static str, Value)
Lt(&'static str, Value)
Le(&'static str, Value)
Gt(&'static str, Value)
Ge(&'static str, Value)
Contains(&'static str, String)
Case-sensitive substring on a TEXT column (SQL: instr(col, ?) > 0).
ContainsCi(&'static str, String)
Case-insensitive substring, what a search field wants. Folds with full Unicode
lowercasing on both paths: the driver registers day_fold (Rust’s to_lowercase as a
SQL function), so the SQL form selects exactly the rows the in-memory form would.
StartsWith(&'static str, String)
Case-sensitive prefix. Not LIKE, whose SQLite default is case-insensitive for
ASCII and would quietly answer the wrong question.
StartsWithCi(&'static str, String)
Case-insensitive prefix through day_fold, like Pred::ContainsCi.
Between(&'static str, Value, Value)
In(&'static str, Vec<Value>)
column ∈ set. The set is sorted and deduped at construction, so the fallback
evaluator can binary-search it.
NotIn(&'static str, Vec<Value>)
column ∉ set, with SQL’s NULL rule: a NULL column is unknown, not a match.
IdIn(Vec<u64>)
The row’s key ∈ set. Compiles against the key column directly.
Related
A question about a row’s relatives: “some lodging of this trip is in Kyoto”.
Compiles to a correlated EXISTS over the relation’s foreign key (or join table);
inner evaluates against rows of target, not of the query’s own table. Nesting is
unlimited; each level is another subquery the engine plans.
Fields
And(Box<Pred>, Box<Pred>)
Or(Box<Pred>, Box<Pred>)
Not(Box<Pred>)
Raw(String, Vec<Value>)
Raw SQL the layer cannot read. The query cannot know its dependencies, so every flush that touches the table re-runs it. That is the cost of the escape hatch.
Matches
Full-text match (#[model(fts(…))]): compiles to a subquery over the FTS5 shadow.
The dependency set is the indexed columns, so the zero-cost tier survives search.
Within
A bounding-box test over two REAL columns. When the columns are the model’s declared
spatial(…) pair, the compiler narrows through the R*Tree shadow first and re-checks
exactly (the shadow stores 32-bit floats, outward-rounded, as a candidate superset).
Implementations§
Source§impl Pred
impl Pred
Sourcepub fn columns(&self, out: &mut Vec<&'static str>)
pub fn columns(&self, out: &mut Vec<&'static str>)
The columns whose change can move a result through this predicate: local columns
only; what a predicate reads across a relation is collected by Pred::related_deps.
Sourcepub fn contains_raw(&self) -> bool
pub fn contains_raw(&self) -> bool
Whether any part is raw SQL (unreadable, so every flush of the table re-queries).
Sourcepub fn eval(&self, key: u64, row: &dyn RowView) -> bool
pub fn eval(&self, key: u64, row: &dyn RowView) -> bool
Whether this row matches, in the WHERE-clause reading: unknown is not a match. This is
the fallback evaluator; the SQL compiler is the primary path, and this answers for
drivers without day_fold (over the row’s own columns; relation crossings are refused
upstream) and for unit tests. Raw and Matches answer true here: on the fallback
path they have already filtered in SQL.
Sourcepub fn eval3(&self, key: u64, row: &dyn RowView) -> Option<bool>
pub fn eval3(&self, key: u64, row: &dyn RowView) -> Option<bool>
Pred::eval, three-valued: SQL’s logic, which is the only way this path and the SQL
path can agree about NULL.
A comparison against a NULL column is unknown (None), not false: SQL’s notes <> 'x'
does not select rows whose notes is NULL, and neither does this. Eq/Ne against a
Null literal keep their IS NULL / IS NOT NULL meaning and are always definite.
Trait Implementations§
impl StructuralPartialEq for Pred
Auto Trait Implementations§
impl Forget for Pred
impl Freeze for Pred
impl Move for Pred
impl RefUnwindSafe for Pred
impl Send for Pred
impl Sync for Pred
impl Unpin for Pred
impl UnsafeUnpin for Pred
impl UnwindSafe for Pred
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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