Skip to main content

ScalarQueryOpts

Struct ScalarQueryOpts 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional 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: usize

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

Source

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);
Source

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());
Source

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"[..]));
Source

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);
Source

pub fn with_offset(self, offset: usize) -> Self

Set Self::offset.

assert_eq!(kevy_embedded::ScalarQueryOpts::default().with_offset(5).offset, 5);

Trait Implementations§

Source§

impl<'a> Clone for ScalarQueryOpts<'a>

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<'a> Copy for ScalarQueryOpts<'a>

Source§

impl<'a> Debug for ScalarQueryOpts<'a>

Source§

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

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

impl<'a> Default for ScalarQueryOpts<'a>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a> Eq for ScalarQueryOpts<'a>

Source§

impl<'a> Hash for ScalarQueryOpts<'a>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a> PartialEq for ScalarQueryOpts<'a>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'a> StructuralPartialEq for ScalarQueryOpts<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for ScalarQueryOpts<'a>

§

impl<'a> RefUnwindSafe for ScalarQueryOpts<'a>

§

impl<'a> Send for ScalarQueryOpts<'a>

§

impl<'a> Sync for ScalarQueryOpts<'a>

§

impl<'a> Unpin for ScalarQueryOpts<'a>

§

impl<'a> UnsafeUnpin for ScalarQueryOpts<'a>

§

impl<'a> UnwindSafe for ScalarQueryOpts<'a>

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