#[non_exhaustive]pub struct ScalarQueryOpts<'a> {
pub filters: &'a [ValueFilter<'a>],
pub sort: Option<(&'a [u8], SortOrder)>,
pub distinct: Option<&'a [u8]>,
pub facets: &'a [Vec<u8>],
pub offset: usize,
}Expand description
Everything a scalar RANGE/EQ query carries beyond its bounds and
limit — the embedded twin of the wire’s optional clauses.
ScalarQueryOpts::default is the plain query; the with_* methods
name the clauses a caller wants.
use kevy_embedded::{ScalarQueryOpts, SortOrder, ValueFilter};
let filters = [ValueFilter::Eq { field: b"status", value: b"paid" }];
let opts = ScalarQueryOpts::default()
.with_filters(&filters)
.with_sort(b"total", SortOrder::Desc)
.with_offset(20);
assert_eq!(opts.sort, Some((&b"total"[..], SortOrder::Desc)));Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.filters: &'a [ValueFilter<'a>]FILTER …: non-scoring predicates over stored values, ANDed. A
row without the stored value fails — absent is not a value.
// u:1 (age 30, paid, total 5), u:2 (40, paid, 20), u:3 (50, due, 8)
let paid = ValueFilter::Eq { field: b"status", value: b"paid" };
let big = ValueFilter::Range { field: b"total", min: b"10", max: b"99" };
let both = [paid, big];
let opts = ScalarQueryOpts::default().with_filters(&both);
assert_eq!(keys(opts)?, [b"u:2".to_vec()], "both predicates hold");sort: Option<(&'a [u8], SortOrder)>SORT <field> ASC|DESC: order the page by a stored value; a row
with no usable value sorts last in both directions.
// u:1 (age 30, paid, total 5), u:2 (40, paid, 20), u:3 (50, due, 8)
let opts = ScalarQueryOpts::default().with_sort(b"total", SortOrder::Desc);
assert_eq!(keys(opts)?, [b"u:2".to_vec(), b"u:3".to_vec(), b"u:1".to_vec()]);distinct: Option<&'a [u8]>DISTINCT <field>: at most one row per coerced value; a row
with no value is its own group.
// u:1 (age 30, paid, total 5), u:2 (40, paid, 20), u:3 (50, due, 8)
let opts = ScalarQueryOpts::default().with_distinct(b"status");
assert_eq!(keys(opts)?.len(), 2, "one paid row, one due row");facets: &'a [Vec<u8>]FACET <field…>: count each field’s values over the whole match
set (FILTER reduces the counts; DISTINCT does not).
// u:1 (age 30, paid, total 5), u:2 (40, paid, 20), u:3 (50, due, 8)
let fields = [b"status".to_vec()];
let opts = ScalarQueryOpts::default().with_facets(&fields);
let page = s.idx_query_claused(b"by_age", &lo, &hi, None, 10, opts)?;
assert_eq!(page.facets[0], [(b"paid".to_vec(), 2), (b"due".to_vec(), 1)]);offset: usizeOFFSET n: rows to skip before limit takes effect.
// u:1 (age 30, paid, total 5), u:2 (40, paid, 20), u:3 (50, due, 8)
let opts = ScalarQueryOpts::default().with_offset(2);
assert_eq!(keys(opts)?, [b"u:3".to_vec()]);Implementations§
Source§impl<'a> ScalarQueryOpts<'a>
impl<'a> ScalarQueryOpts<'a>
Sourcepub fn with_filters(self, filters: &'a [ValueFilter<'a>]) -> Self
pub fn with_filters(self, filters: &'a [ValueFilter<'a>]) -> Self
Set Self::filters.
let f = [kevy_embedded::ValueFilter::Eq { field: b"k", value: b"v" }];
assert_eq!(kevy_embedded::ScalarQueryOpts::default().with_filters(&f).filters.len(), 1);Sourcepub fn with_sort(self, field: &'a [u8], order: SortOrder) -> Self
pub fn with_sort(self, field: &'a [u8], order: SortOrder) -> Self
Set Self::sort: order by field, in order.
use kevy_embedded::{ScalarQueryOpts, SortOrder};
let o = ScalarQueryOpts::default().with_sort(b"ts", SortOrder::Asc);
assert!(o.sort.is_some());Sourcepub fn with_distinct(self, field: &'a [u8]) -> Self
pub fn with_distinct(self, field: &'a [u8]) -> Self
Set Self::distinct.
let o = kevy_embedded::ScalarQueryOpts::default().with_distinct(b"user");
assert_eq!(o.distinct, Some(&b"user"[..]));Sourcepub fn with_facets(self, facets: &'a [Vec<u8>]) -> Self
pub fn with_facets(self, facets: &'a [Vec<u8>]) -> Self
Set Self::facets.
let fields = [b"status".to_vec()];
let o = kevy_embedded::ScalarQueryOpts::default().with_facets(&fields);
assert_eq!(o.facets.len(), 1);Sourcepub fn with_offset(self, offset: usize) -> Self
pub fn with_offset(self, offset: usize) -> Self
Set Self::offset.
assert_eq!(kevy_embedded::ScalarQueryOpts::default().with_offset(5).offset, 5);