Skip to content
Chalk drawing on a slate chalkboard of a database cylinder under a magnifying glass, with the slate logo above it.

slate

Type-safe, persistent key-value storage for Gleam — the gap between "serialize to a file" and "add a database." Built on OTP's DETS, no external dependencies.
Terminal window
gleam add slate

slate targets Erlang, where DETS ships with OTP. There is no database service or JavaScript-target dependency to add.

Open a table, insert, look up. Every value passes through the decoders you choose, so what comes off disk is typed — not dynamic data you have to trust.

import gleam/dynamic/decode
import gleam/result
import slate/set
pub fn main() {
use users <- set.with_table(
"data/users.dets",
key_decoder: decode.string,
value_decoder: decode.int,
)
use Nil <- result.try(
set.insert(users, "alice", 42),
)
set.lookup(users, key: "alice")
}
// Ok(42), and the table is closed

Gleam's use value <- function(...) syntax passes the rest of the block as a callback. Here, with_table supplies users and closes the table when that callback returns. The decoders define the key and value types expected from disk; result.try stops early if the insert fails.

Values persist across node restarts. After an abrupt process termination, DETS may repair the file when it next opens. The Quick Start walks through this pattern step by step, and Safe Resource Management covers long-lived tables and repair behavior.

Storage approaches at a glance
ApproachComplexityPersistenceQuery capability
JSON fileLowYesNone
DETS (slate)LowYesKey lookup, fold
SQLite/PostgresHighYesFull SQL
MnesiaHighYesTransactions, distribution

If a config file is too little and a database is too much, DETS is the middle layer you already have. It has real limits — 2 GB per table, disk I/O on every operation — and they are documented plainly in Limitations.

Every table type gets the same typed API; they differ in what happens when a key repeats.

slate is 1.0, with a public API covered by semver guarantees. Continue with the Quick Start to read and write a table in about two minutes.