riptide v0.5.0-beta8 Riptide.UUID View Source
This module allows you to generate sortable Time UUIDs that can be used to control sorting order in Riptide stores. They have a time component that defaults to creation time as well as a random component.
- Ascending UUIDs generated with
Riptide.UUID.ascending/0
will be sorted oldest to newest by their time component. - Descending UUIDs generated with
Riptide.UUID.descending/0
will be sorted newest to oldest by their time component.
Usage
Take the following data:
{
"todo:info": {
"0S1eOQ0kd0wnuUSWbDAu" => %{
"text" => "My first todo!"
}
}
}
This entry uses an ascending UUID. This means if we create a new entry with an ascending UUID it will be inserted below the existing entry:
{
"todo:info": {
"0S1eOQ0kd0wnuUSWbDAu" => %{
"text" => "My first todo!"
},
"0S1eP9y9x61XmeVoHzVM" => %{
"text" => "My second todo!"
}
}
}
Now let's try it with descending UUIDs:
{
"todo:info": {
"zXyLafLmMB6Uac8NTOvA" => %{
"text" => "My first todo!"
}
}
}
Adding another todo will insert it above the existing entry:
{
"todo:info": {
"zXyLaUMUDcB4zaVNCLM2" => %{
"text" => "My second todo!"
},
"zXyLafLmMB6Uac8NTOvA" => %{
"text" => "My first todo!"
}
}
}
The type of UUID that should be used depends on how your application is planning on using the data. For example, if your application typically loads the 10 newest created todos it makes sense to use descending UUIDs with the following query:
Riptide.query_path ["todo:info"], %{limit: 10}
Explore the functions in this module to see the additional options there are for creating UUIDs.
Link to this section Summary
Functions
Generate a UUID that can be sorted lexicographically from oldest to newest. The time component is set to the current time.
Like ascending/1
with the ability to specify time component.
For a given ascending UUID, extract the time component in milliseconds.
Like ascending/1
with the ability to specify time component.
Generate a UUID that can be sorted lexicographically from newest to oldest. The time component is set to the current time.
Like descending/0
with the ability to specify time component in milliseconds.
For a given descending UUID, extract the time component in milliseconds.
Like descending/1
with the random part zero filled. Useful for specifying ranges of UUIDs in queries.
Link to this section Functions
Generate a UUID that can be sorted lexicographically from oldest to newest. The time component is set to the current time.
Like ascending/1
with the ability to specify time component.
For a given ascending UUID, extract the time component in milliseconds.
Like ascending/1
with the ability to specify time component.
Generate a UUID that can be sorted lexicographically from newest to oldest. The time component is set to the current time.
Like descending/0
with the ability to specify time component in milliseconds.
For a given descending UUID, extract the time component in milliseconds.
Like descending/1
with the random part zero filled. Useful for specifying ranges of UUIDs in queries.