pub struct Indexer { /* private fields */ }Expand description
Owning handle over a SQLite connection to a logdive index.
Implementations§
Source§impl Indexer
impl Indexer
Sourcepub fn open(path: &Path) -> Result<Self>
pub fn open(path: &Path) -> Result<Self>
Open (or create) a logdive index at path.
Creates the parent directory if it does not already exist, opens the SQLite database, and runs idempotent schema migrations.
Sourcepub fn open_in_memory() -> Result<Self>
pub fn open_in_memory() -> Result<Self>
Open an in-memory index. Used by tests; also usable for one-shot scenarios that don’t need persistence.
Sourcepub fn open_read_only(path: &Path) -> Result<Self>
pub fn open_read_only(path: &Path) -> Result<Self>
Open an existing logdive index at path in read-only mode.
Unlike Indexer::open, this method:
- Does not create the database file if it is missing (the
SQLITE_OPEN_READ_ONLYflag fails rather than creates), - Does not create the parent directory,
- Does not run schema migrations — the caller is promising
that
pathalready points at a valid logdive index.
Enforcement of read-only semantics is at the SQLite level: any attempted write through the returned connection raises a runtime error. This is defense-in-depth for the HTTP API (milestone 8), whose surface is exclusively read.
Sourcepub fn connection(&self) -> &Connection
pub fn connection(&self) -> &Connection
Borrow the underlying connection.
Exposed so the query executor can run reads without an extra
abstraction layer. Read-only borrow keeps ingestion and querying
from contending over &mut.
Sourcepub fn insert_batch(&mut self, entries: &[LogEntry]) -> Result<InsertStats>
pub fn insert_batch(&mut self, entries: &[LogEntry]) -> Result<InsertStats>
Insert a slice of entries into the index, chunking internally into
transactions of BATCH_SIZE rows each.
Returns aggregate stats across all chunks. Entry ordering within the index is not guaranteed.
Sourcepub fn prune(&mut self, cutoff: &str) -> Result<PruneStats>
pub fn prune(&mut self, cutoff: &str) -> Result<PruneStats>
Delete every entry whose timestamp is strictly older than cutoff,
then VACUUM to reclaim the freed disk space.
cutoff is compared lexically against the stored timestamp TEXT
column. This is correct for ISO-8601 / RFC3339 timestamps, which sort
chronologically as text — the same comparison contract the query
executor’s last / since clauses rely on. A non-ISO-shaped cutoff
(or non-ISO timestamps in the index) will compare incorrectly, the
same known limitation that applies to time-range queries.
The comparison is strict <: a row whose timestamp exactly equals
cutoff is kept, not deleted.
Returns the number of rows deleted in PruneStats::deleted.
§VACUUM and transactions
SQLite refuses to run VACUUM inside an explicit transaction, so this
method issues the DELETE and the VACUUM as two separate autocommit
statements rather than wrapping them in conn.transaction(). The
DELETE is a single statement and therefore atomic on its own; a
crash between the two would leave the rows deleted but the file not
yet compacted — harmless, since any later VACUUM reclaims the space.
Sourcepub fn stats(&self) -> Result<Stats>
pub fn stats(&self) -> Result<Stats>
Read aggregate metadata about the index.
Runs three read-only queries:
COUNT(*)for the row count,MIN(timestamp), MAX(timestamp)for the time range,SELECT DISTINCT tag ... ORDER BY tagfor the tag list.
On an empty database, returns entries = 0, both timestamp bounds
as None, and an empty tags vector — not an error.