Records / Records

Records

The Records engine keeps logs and events in records.db and reads them back by time, level, trace, fields and text. A logger prints each line to the console as any logger does, and keeps it too. Events are named facts a program appends and keeps as long as their stream says. Both are packed into compact blocks by column.

const log = store.logger('api', { redact: secrets })
const audit = store.events('audit', { keep: '365d' })

log.info('signed in', { userId: 42 })
await audit.append('role.changed', { userId: 42, role: 'admin' })
const page = await store.events().list({ since: '1h', minLevel: 'warn' })
log = store.logger("api", redact=tinystore.secrets)
audit = store.events("audit", keep="365d")

log.info("signed in", user_id=42)
await audit.append("role.changed", {"user_id": 42, "role": "admin"})
page = await store.events().list(since="1h", min_level="warn")
log := slog.New(records.NewHandler(store, "api", console.Redact(console.Secrets...)))
audit, err := records.OpenEvents(store, "audit", records.Keep(365*24*time.Hour))

log.Info("signed in", "userId", 42)
_, err = audit.Append(ctx, "role.changed", records.Fields{"userId": 42, "role": "admin"})
events, err := records.OpenAllEvents(store)
page, err := events.List(ctx, records.Query{Since: time.Hour, MinLevel: slog.LevelWarn})
let log = store.logger("api").layer()?;
tracing_subscriber::registry().with(log.clone()).init();
let audit = store.events("audit").keep(Duration::from_hours(365 * 24)).open()?;

tracing::info!(user_id = 42, "signed in");
audit.append("role.changed", &RoleChanged { user_id: 42, role: "admin".into() })?;
let page = store.all_events()?.list().since(Duration::from_hours(1)).min_level(Level::WARN).page()?;

What it guarantees

  • A log call never waits: lines are kept within a second, and a line that finds the buffer full is dropped and counted (NOT-09).
  • append returns after the event is written, and a read finds it at once.
  • An event's values come back as they were written, byte for byte.
  • A stream keeps its events for its own keep, 14 days unless set, with no cleanup job.
  • A damaged segment is named, listed and removable, and never stops the others (contract ERR-07).

In these guides

PageCovers
Logginglevels, with, redact, Go's slog and Rust's tracing
Console outputpretty or JSON, a quiet console, LOG_LEVEL, LOG_CONSOLE_LEVEL, a console alone
Eventsappend, names, fields, context, times, ids for an append sent again
An audit that commits with the changedb.events, an append inside a database's transaction or batch
Readinglist, all, where, search, count, top, aggregate
Tracesone request's lines across streams
Tail and polllive events, and every event once from a cursor
Other programs' outputanother process's lines as events
Deleting eventsa person's events taken out of every stream, with what was kept only for them
Repairdamaged and drop

New to Records? What it is doing in the Handbook logs a chat's requests and reads them back.

Async Rust

With the async feature, tinystore::aio::Store opens the same streams, and each call that reads or writes returns a future. The calls have the same names as in the blocking API. Rust with async has what every engine shares: opening, where a call runs, a dropped future, timeouts and closing.

use tinystore::Store;

let store = Store::open("data", Default::default())?;
let audit = store.events("audit").keep(Duration::from_hours(365 * 24)).open()?;
audit.append("role.changed", &RoleChanged { user_id: 42, role: "admin".into() })?;
let errors = store.all_events()?.list().since(Duration::from_hours(1)).min_level(Level::ERROR).count()?;
for event in audit.list().since(Duration::from_hours(24)).search("admin").all() {
    show(event?);
}
BlockingAsyncWhere it runsIf you drop the future after its first poll
append, append_all, event(...).appendthe same, awaitedchecked in the poll, committed on the store's threadsthe events are still written
page, count, top, aggregate, field_namesthe same, awaitedon the store's threadsthe read stops, and its reader goes back
all(), an Iteratorall(), a Streama page at a time on the store's threadsthe page being read stops
tail() with next_withintail(), a Streamwaits on no thread, each batch taken from memorythe tail closes
poll, poll_limit, streams, fields, damagedthe same, awaitedon the store's threadsthe read stops
drop(&damage)the same, awaitedon the store's threadsit runs to its end
Lines, a std::io::Writewrite, a plain call, and flush().awaitwrite into the buffer, flush on the store's threadsthe flush runs to its end
logger(...), records::maintainthe same, blockingthe logger's buffer; maintenance on the caller's threadnot a future

An append's events are checked in the poll that starts it, at most 4 MiB per append. An append of up to 256 KiB is also compressed in that poll. A larger one, or one that arrives while another append is compressing, is compressed on the store's threads, so the poll never waits. If the store has a memory budget and no room for the events, the append waits for memory without holding a thread. It fails with a limit error (ErrorKind::Limit) after ten seconds, as the blocking call does.

Each append wakes a tail, and its stream ends when the store closes. To wait with a bound, use your runtime's timeout. The tail stays open after a timeout:

rust
let mut tail = store.all_events()?.list().streams(["api"]).min_level(Level::WARN).tail()?;
while let Ok(Some(batch)) = tokio::time::timeout(Duration::from_secs(30), tail.next()).await {
    let batch = batch?;
    if batch.missed > 0 {
        socket.send(skipped(batch.missed)).await?;
    }
    for event in &batch.events {
        socket.send(json(event)).await?;
    }
}

A writer of another program's lines is no std::io::Write in the async API, because its flush would block your executor's thread. write never waits, and you await flush:

rust
use tokio::io::AsyncReadExt;

let mut out = store.events("worker").open()?.lines()?;
let mut stdout = child.stdout.take().unwrap();
let mut piece = vec![0; 64 << 10];
loop {
    let read = stdout.read(&mut piece).await?;
    if read == 0 {
        break;
    }
    out.write(&piece[..read])?; // never waits
}
out.flush().await?; // the lines ended so far are written

A store opened without background work runs tinystore::records::maintain on store.blocking().

Reference

Bun and Node · Python · Go · Rust

Edit this page on GitHub Updated 19 November 2026

esc
↑↓ navigate ↵ open ⇥ filter 0 results