Query

Struct Query 

Source
pub struct Query { /* private fields */ }
Expand description

Builder for constructing queries on a single event.

Created by EventStore::query(), this builder provides methods to specify time ranges before executing aggregation operations.

Implementations§

Source§

impl Query

Source

pub fn last_seconds(self, n: usize) -> RangeQuery

Query the last N seconds.

Source

pub fn last_minutes(self, n: usize) -> RangeQuery

Query the last N minutes.

§Examples
use tiny_counter::EventStore;

let store = EventStore::new();
store.record("event");

let count = store.query("event").last_minutes(60).sum();
assert_eq!(count, Some(1));
Source

pub fn last_hours(self, n: usize) -> RangeQuery

Query the last N hours.

Source

pub fn last_days(self, n: usize) -> RangeQuery

Query the last N days.

§Examples
use tiny_counter::EventStore;

let store = EventStore::new();
store.record("app_launch");

let count = store.query("app_launch").last_days(7).sum();
assert_eq!(count, Some(1));
Source

pub fn last_weeks(self, n: usize) -> RangeQuery

Query the last N weeks.

Source

pub fn last_months(self, n: usize) -> RangeQuery

Query the last N months (28-day approximation).

Source

pub fn last_years(self, n: usize) -> RangeQuery

Query the last N years (365-day approximation).

Source

pub fn ever(self) -> RangeQuery

Query all available data (all buckets).

Uses the longest time unit configured for this event to capture the maximum available history.

Source

pub fn days(self, range: Range<usize>) -> RangeQuery

Query a specific range of days.

Source

pub fn days_from(self, offset: usize) -> RangeQuery

Start building a query from an offset of days.

Use with .take(n) to specify the range length.

Source

pub fn last_seen(self) -> Option<Duration>

Returns the time since the event was last seen.

Returns None if the event has never been recorded or doesn’t exist.

§Examples
use tiny_counter::EventStore;
use chrono::Duration;

let store = EventStore::new();
store.record("settings_visit");

let time_since = store.query("settings_visit").last_seen();
assert!(time_since.is_some());

// Check for events never recorded
let never_seen = store.query("never_happened").last_seen();
assert!(never_seen.is_none());
Source

pub fn first_seen(self) -> Option<Duration>

Returns an estimate for the time since the event was first seen.

Returns None if the event has never been recorded or doesn’t exist. This searches for the oldest non-zero bucket across all tracked time units.

§Examples
use tiny_counter::EventStore;
use chrono::Duration;

let store = EventStore::new();
store.record("user_signup");

let time_since = store.query("user_signup").first_seen();
assert!(time_since.is_some());

// Check for events never recorded
let never_seen = store.query("never_happened").first_seen();
assert!(never_seen.is_none());
Source

pub fn first_seen_in(self, time_unit: TimeUnit) -> Option<Duration>

Returns the time since the event was first seen in a specific time unit.

Returns None if the event has never been recorded, doesn’t exist, or the time unit is not tracked.

§Examples
use tiny_counter::{EventStore, TimeUnit};
use chrono::Duration;

let store = EventStore::new();
store.record("page_view");

let time_since = store.query("page_view").first_seen_in(TimeUnit::Days);
assert!(time_since.is_some());

Auto Trait Implementations§

§

impl Freeze for Query

§

impl !RefUnwindSafe for Query

§

impl Send for Query

§

impl Sync for Query

§

impl Unpin for Query

§

impl !UnwindSafe for Query

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.