Store sensor data in five minutes
A short guide to writing and querying your first series with DriftDB from Rust or Python.
1 min read
On this page4 sections
DriftDB runs inside your process, like SQLite. There’s no server to start and no port to open. This guide gets you from an empty project to a downsampling query.
Install
In a Rust project, run cargo add driftdb@0.9. For Python, the bindings are on PyPI as driftdb.
Write and query
Rust
use driftdb::{Db, Duration};
let db = Db::open("./data")?;
let temp = db.series("greenhouse.temp")?;
temp.append(now(), 21.4)?;
let hourly = temp
.range(Duration::days(1))
.downsample(Duration::hours(1))
.avg()?;Python
import driftdb
db = driftdb.open("./data")
temp = db.series("greenhouse.temp")
temp.append(driftdb.now(), 21.4)
hourly = temp.range(days=1).downsample(hours=1).avg()Keep only what you need
Most sensor data loses value fast. Set a retention policy per series and DriftDB drops old blocks in the background:
temp.set_retention(Duration::days(90))?;