slate
Start here
Section titled “Start here”gleam add slateslate targets Erlang, where DETS ships with OTP. There is no database service or JavaScript-target dependency to add.
What it looks like
Section titled “What it looks like”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/decodeimport gleam/resultimport 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 closedGleam'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.
When to use DETS
Section titled “When to use DETS”| Approach | Complexity | Persistence | Query capability |
|---|---|---|---|
| JSON file | Low | Yes | None |
| DETS (slate) | Low | Yes | Key lookup, fold |
| SQLite/Postgres | High | Yes | Full SQL |
| Mnesia | High | Yes | Transactions, 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.
Pick a table type
Section titled “Pick a table type”Every table type gets the same typed API; they differ in what happens when a key repeats.
Ready to try it?
Section titled “Ready to try it?”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.