What is slate?
slate gives Gleam programs typed access to Erlang's DETS (Disk Erlang Term Storage). It keeps DETS's file-backed storage model while replacing dynamic Erlang terms and exceptions with explicit Gleam types and Result values.
The BEAM storage layer you already have
Section titled “The BEAM storage layer you already have”DETS ships with OTP. It stores Erlang terms on disk, supports key lookup and folds, and survives node restarts without a separate database service.
That makes it useful when a serialized file is too limited but SQLite, Postgres, or Mnesia would add more operational weight than the application needs. The trade-offs are real: DETS has a 2 GB table limit, performs disk I/O on every operation, and is not a distributed database. See Limitations for the complete boundary.
How slate maps DETS into Gleam
Section titled “How slate maps DETS into Gleam”- Typed table handles:
slate/set,slate/bag, andslate/duplicate_bagexpose the same operations without allowing table types to be mixed accidentally. - Decoding at the storage boundary: You provide key and value decoders when opening a table. Reads return a decode error if the data on disk does not match those types.
- Explicit failures: Public operations return
Resultvalues instead of raising Erlang exceptions. - Managed short-lived access:
with_tableopens a table, runs your callback, and closes the table before returning. - Stable public API: slate 1.0 is covered by the documented semver guarantees.
Gleam idioms in the examples
Section titled “Gleam idioms in the examples”If you are coming from Erlang or Elixir, two patterns appear frequently:
use table <- set.with_table(...)is callback shorthand. The remainder of the block becomes the callback that receivestable.decode.string,decode.int, and other decoders describe the types slate should accept when reading Erlang terms from disk.
The Quick Start puts those pieces together in a complete read-and-write example.
Choose a table type
Section titled “Choose a table type”- Use a set table when each key has one value.
- Use a bag table when each key can have several distinct values.
- Use a duplicate bag table when repeated key-value pairs must be preserved.
Related BEAM storage projects
Section titled “Related BEAM storage projects”- bravo — Comprehensive ETS (in-memory) bindings for Gleam. Use bravo when you need fast, in-memory storage without persistence.
- shelf — Persistent ETS tables backed by DETS. Combines microsecond in-memory reads with durable disk storage. Built on top of slate.
Underlying DETS behavior
Section titled “Underlying DETS behavior”slate does not replace DETS semantics. For storage-engine details beyond slate's API, see the official Erlang DETS documentation.