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
impl Query
Sourcepub fn last_seconds(self, n: usize) -> RangeQuery
pub fn last_seconds(self, n: usize) -> RangeQuery
Query the last N seconds.
Sourcepub fn last_minutes(self, n: usize) -> RangeQuery
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));Sourcepub fn last_hours(self, n: usize) -> RangeQuery
pub fn last_hours(self, n: usize) -> RangeQuery
Query the last N hours.
Sourcepub fn last_days(self, n: usize) -> RangeQuery
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));Sourcepub fn last_weeks(self, n: usize) -> RangeQuery
pub fn last_weeks(self, n: usize) -> RangeQuery
Query the last N weeks.
Sourcepub fn last_months(self, n: usize) -> RangeQuery
pub fn last_months(self, n: usize) -> RangeQuery
Query the last N months (28-day approximation).
Sourcepub fn last_years(self, n: usize) -> RangeQuery
pub fn last_years(self, n: usize) -> RangeQuery
Query the last N years (365-day approximation).
Sourcepub fn ever(self) -> RangeQuery
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.
Sourcepub fn days(self, range: Range<usize>) -> RangeQuery
pub fn days(self, range: Range<usize>) -> RangeQuery
Query a specific range of days.
Sourcepub fn days_from(self, offset: usize) -> RangeQuery
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.
Sourcepub fn last_seen(self) -> Option<Duration>
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());Sourcepub fn first_seen(self) -> Option<Duration>
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());Sourcepub fn first_seen_in(self, time_unit: TimeUnit) -> Option<Duration>
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());