Snowgleam ❄️
Gleam version of the Twitter’s snowflake format for unique IDs. Although it is more inspired by the Discord implementation of the snowflake format.
They are great for generating unique IDs in a distributed system.
gleam add snowgleam
And then use it in your project like this:
import gleam/io
import gleam/int
import snowgleam
pub fn main() {
let assert Ok(generator) = snowgleam.new_generator() |> snowgleam.start()
let id = generator |> snowgleam.generate()
io.println("Generated ID: " <> id |> int.to_string())
generator |> snowgleam.stop()
}
Features
- Setup with a custom epoch
- Simple ID generation
- Lazy ID generation
- Lazy ID generation with custom timestamp (useful for backfilling)
- Batch ID generation
- Batch Lazy ID generation
Further documentation can be found at https://hexdocs.pm/snowgleam.