LockQuery

Struct LockQuery 

Source
pub struct LockQuery<'a, T: 'static, L>
where L: LockValue<T> + 'a,
{ /* private fields */ }
Expand description

A query builder for locked data structures.

Provides full SQL-like query operations (WHERE, SELECT, ORDER BY, GROUP BY) on collections of locked values without unnecessary copying.

Implementations§

Source§

impl<'a, T: 'static, L> LockQuery<'a, T, L>
where L: LockValue<T> + 'a,

Source

pub fn from_locks(locks: Vec<&'a L>) -> Self

Create a new lock query from a collection of locks.

§Example
let query = LockQuery::from_locks(product_map.values().collect());
Source

pub fn where_<F>( self, path: KeyPaths<T, F>, predicate: impl Fn(&F) -> bool + 'a, ) -> Self
where F: 'static,

Add a WHERE clause using a key-path.

§Example
let query = LockQuery::new(&products)
    .where_(Product::category(), |cat| cat == "Electronics");
Source

pub fn all(&self) -> Vec<T>
where T: Clone,

Get all matching items (collects by cloning).

§Example
let results: Vec<Product> = query.all();
Source

pub fn first(&self) -> Option<T>
where T: Clone,

Get the first matching item.

§Example
let first = query.first();
Source

pub fn count(&self) -> usize

Count matching items.

§Example
let count = query.count();
Source

pub fn exists(&self) -> bool

Check if any items match.

§Example
let exists = query.exists();
Source

pub fn limit(&self, n: usize) -> Vec<T>
where T: Clone,

Limit results to first N items.

§Example
let first_10 = query.limit(10);
Source

pub fn select<F>(&self, path: KeyPaths<T, F>) -> Vec<F>
where F: Clone + 'static,

Select/project a field.

§Example
let names: Vec<String> = query.select(Product::name());
Source

pub fn sum<F>(&self, path: KeyPaths<T, F>) -> F
where F: Clone + Add<Output = F> + Default + 'static,

Sum a numeric field.

§Example
let total = query.sum(Product::price());
Source

pub fn avg(&self, path: KeyPaths<T, f64>) -> Option<f64>

Calculate average of f64 field.

§Example
let avg = query.avg(Product::price());
Source

pub fn min<F>(&self, path: KeyPaths<T, F>) -> Option<F>
where F: Ord + Clone + 'static,

Find minimum value.

§Example
let min = query.min(Product::stock());
Source

pub fn max<F>(&self, path: KeyPaths<T, F>) -> Option<F>
where F: Ord + Clone + 'static,

Find maximum value.

§Example
let max = query.max(Product::stock());
Source

pub fn min_float(&self, path: KeyPaths<T, f64>) -> Option<f64>

Find minimum float value.

Source

pub fn max_float(&self, path: KeyPaths<T, f64>) -> Option<f64>

Find maximum float value.

Source

pub fn order_by<F>(&self, path: KeyPaths<T, F>) -> Vec<T>
where F: Ord + Clone + 'static, T: Clone,

Order by a field (requires collecting data).

§Example
let sorted = query.order_by(Product::name());
Source

pub fn order_by_desc<F>(&self, path: KeyPaths<T, F>) -> Vec<T>
where F: Ord + Clone + 'static, T: Clone,

Order by a field descending.

Source

pub fn order_by_float(&self, path: KeyPaths<T, f64>) -> Vec<T>
where T: Clone,

Order by float field.

Source

pub fn order_by_float_desc(&self, path: KeyPaths<T, f64>) -> Vec<T>
where T: Clone,

Order by float field descending.

Source

pub fn group_by<F>(&self, path: KeyPaths<T, F>) -> HashMap<F, Vec<T>>
where F: Eq + Hash + Clone + 'static, T: Clone,

Group by a field.

§Example
let groups = query.group_by(Product::category());
Source

pub fn min_timestamp(&self, path: KeyPaths<T, i64>) -> Option<i64>

Finds minimum i64 timestamp value.

§Example
let earliest = query.min_timestamp(Event::created_at());
Source

pub fn max_timestamp(&self, path: KeyPaths<T, i64>) -> Option<i64>

Finds maximum i64 timestamp value.

§Example
let latest = query.max_timestamp(Event::created_at());
Source

pub fn avg_timestamp(&self, path: KeyPaths<T, i64>) -> Option<i64>

Computes average of i64 timestamp values.

§Example
let avg = query.avg_timestamp(Event::created_at());
Source

pub fn sum_timestamp(&self, path: KeyPaths<T, i64>) -> i64

Computes sum of i64 timestamp values.

§Example
let total = query.sum_timestamp(Event::created_at());
Source

pub fn count_timestamp(&self, path: KeyPaths<T, i64>) -> usize

Counts i64 timestamp values.

§Example
let count = query.count_timestamp(Event::created_at());
Source

pub fn where_after_timestamp( self, path: KeyPaths<T, i64>, reference: i64, ) -> Self

Filter by i64 timestamp being after a reference time.

§Arguments
  • path - The key-path to the i64 timestamp field
  • reference - The reference timestamp to compare against
§Example
let recent = query.where_after_timestamp(Event::created_at(), cutoff_time);
Source

pub fn where_before_timestamp( self, path: KeyPaths<T, i64>, reference: i64, ) -> Self

Filter by i64 timestamp being before a reference time.

§Arguments
  • path - The key-path to the i64 timestamp field
  • reference - The reference timestamp to compare against
§Example
let old = query.where_before_timestamp(Event::created_at(), cutoff_time);
Source

pub fn where_between_timestamp( self, path: KeyPaths<T, i64>, start: i64, end: i64, ) -> Self

Filter by i64 timestamp being between two times (inclusive).

§Arguments
  • path - The key-path to the i64 timestamp field
  • start - The start timestamp
  • end - The end timestamp
§Example
let range = query.where_between_timestamp(Event::created_at(), start, end);
Source

pub fn where_last_days_timestamp( self, path: KeyPaths<T, i64>, days: i64, ) -> Self

Filter by i64 timestamp being within the last N days.

§Arguments
  • path - The key-path to the i64 timestamp field
  • days - Number of days to look back
§Example
let recent = query.where_last_days_timestamp(Event::created_at(), 30);
Source

pub fn where_next_days_timestamp( self, path: KeyPaths<T, i64>, days: i64, ) -> Self

Filter by i64 timestamp being within the next N days.

§Arguments
  • path - The key-path to the i64 timestamp field
  • days - Number of days to look forward
§Example
let upcoming = query.where_next_days_timestamp(Event::scheduled_at(), 7);
Source

pub fn where_last_hours_timestamp( self, path: KeyPaths<T, i64>, hours: i64, ) -> Self

Filter by i64 timestamp being within the last N hours.

§Arguments
  • path - The key-path to the i64 timestamp field
  • hours - Number of hours to look back
§Example
let recent = query.where_last_hours_timestamp(Event::created_at(), 24);
Source

pub fn where_next_hours_timestamp( self, path: KeyPaths<T, i64>, hours: i64, ) -> Self

Filter by i64 timestamp being within the next N hours.

§Arguments
  • path - The key-path to the i64 timestamp field
  • hours - Number of hours to look forward
§Example
let upcoming = query.where_next_hours_timestamp(Event::scheduled_at(), 2);
Source

pub fn where_last_minutes_timestamp( self, path: KeyPaths<T, i64>, minutes: i64, ) -> Self

Filter by i64 timestamp being within the last N minutes.

§Arguments
  • path - The key-path to the i64 timestamp field
  • minutes - Number of minutes to look back
§Example
let recent = query.where_last_minutes_timestamp(Event::created_at(), 60);
Source

pub fn where_next_minutes_timestamp( self, path: KeyPaths<T, i64>, minutes: i64, ) -> Self

Filter by i64 timestamp being within the next N minutes.

§Arguments
  • path - The key-path to the i64 timestamp field
  • minutes - Number of minutes to look forward
§Example
let upcoming = query.where_next_minutes_timestamp(Event::scheduled_at(), 30);

Auto Trait Implementations§

§

impl<'a, T, L> Freeze for LockQuery<'a, T, L>

§

impl<'a, T, L> !RefUnwindSafe for LockQuery<'a, T, L>

§

impl<'a, T, L> !Send for LockQuery<'a, T, L>

§

impl<'a, T, L> !Sync for LockQuery<'a, T, L>

§

impl<'a, T, L> Unpin for LockQuery<'a, T, L>
where T: Unpin,

§

impl<'a, T, L> !UnwindSafe for LockQuery<'a, T, L>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.