
slate
Start here
Section titled “Start here”gleam add slateslate supports Gleam's Erlang target. DETS is part of OTP; slate does not support the JavaScript target.
What it looks like
Section titled “What it looks like”Open a table, insert a value, and look it up. Reads use your decoders to check the stored data.
Create the parent directory before you run the example:
mkdir -p dataimport gleam/dynamic/decodeimport gleam/resultimport slateimport slate/set
pub fn main() { use users <- set.with_table( "data/users.dets", repair: slate.AutoRepair, access: slate.ReadWrite, 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 attempts to close the table when the callback returns. The decoders define the key and value types expected from disk; result.try stops early if the insert fails.
Stored data persists across node restarts. An abnormal node shutdown can lose pending writes and leave the file needing repair. The quick start explains this example. See the table cleanup guide for cleanup and repair options.
When to use DETS
Section titled “When to use DETS”| Approach | Setup | Persistence | Query capability |
|---|---|---|---|
| JSON file | File I/O and serialization | Yes | None |
| DETS (slate) | Included in OTP; add slate for Gleam | Yes | Key lookup, fold |
| SQLite | Embedded database library | Yes | Full SQL |
| Postgres | Database server | Yes | Full SQL |
| Mnesia | Included in OTP; configure a schema | Yes | Key lookup, query expressions |
Use DETS when you need persistent key lookup without a separate database service. Each table has a 2 GB file size limit. Disk-backed access is slower than ETS for frequent reads. See Limitations.
Pick a table type
Section titled “Pick a table type”The table modules share a core API. Set and bag tables also provide insert_new, with different duplicate rules. Only set tables provide update_counter.
Next steps
Section titled “Next steps”slate follows Semantic Versioning. Continue with the quick start to create a table, write values, and read them back.
