snowflake-0.1.0.0: A loose port of Twitter Snowflake to Haskell. Generates arbitrary precision, unique, time-sortable identifiers.

Stabilityexperimental
Maintaineredofic@gmail.com
Safe HaskellNone

Data.Snowflake

Description

This generates unique(guaranteed) identifiers build from time stamp, counter(inside same millisecond) and node id - if you wish to generate ids across several nodes. Identifiers are convertible to Integer values which are monotonically increasing with respect to time.

Synopsis

Documentation

data SnowflakeConfig Source

Configuration that specifies how much bits are used for each part of the id. There are no limits to total bit sum.

Constructors

SnowflakeConfig 

data Snowflake Source

Generated identifier. Can be converted to Integer.

data SnowflakeGen Source

Generator which contains needed state. You should use newSnowflakeGen to create instances.

newSnowflakeGen :: SnowflakeConfig -> Integer -> IO SnowflakeGenSource

Create a new generator. Takes a configuration and node id.

nextSnowflake :: SnowflakeGen -> IO SnowflakeSource

Generates next id. The bread and butter. See module description for details.

defaultConfig :: SnowflakeConfigSource

Default configuration using 40 bits for time, 16 for count and 8 for node id.

snowflakeToInteger :: Snowflake -> IntegerSource

Converts an identifier to an integer with respect to configuration used to generate it.