View Source Needle.ULID (Bonfire v0.9.10-classic-beta.156)

hex.pm hexdocs

A ULID datatype and some postgres support for ULID operations (min and max functions and aggregates)

Originally forked from ecto-ulid but the internals have been replaced with a dependency on ex_ulid

Installation

{:needle_ulid, git: "https://github.com/bonfire-networks/needle_ulid", branch: "main"}

Copyright (c) 2021 Bonfire contributors. Copyright (c) 2018 The RealReal, Inc. Copyright (c) 2020 needle_ulid contributors.

Licensed under the terms of the MIT License.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Summary

Functions

Casts a 26-byte encoded string to ULID or a 16-byte binary unchanged

Same as cast/1 but raises Ecto.CastError on invalid arguments.

Converts a Crockford Base32 encoded ULID into a binary.

Callback implementation for Ecto.Type.embed_as/1.

Returns the randomness portion of the encoded ulid

Returns the timestamp portion of the encoded ulid

Callback implementation for Ecto.Type.equal?/2.

Generates a Crockford Base32 encoded ULID.

Converts a binary ULID into a Crockford Base32 encoded string.

translates alphanumerics into a sentinel ulid value

Returns the timestamp of an encoded or unencoded ULID

The underlying schema type.

Functions

Link to this function

bingenerate(timestamp \\ System.system_time(:millisecond))

View Source

Generates a binary ULID.

If a value is provided for timestamp, the generated ULID will be for the provided timestamp. Otherwise, a ULID will be generated for the current time.

Arguments:

  • timestamp: A Unix timestamp with millisecond precision.

Casts a 26-byte encoded string to ULID or a 16-byte binary unchanged

Same as cast/1 but raises Ecto.CastError on invalid arguments.

Converts a Crockford Base32 encoded ULID into a binary.

Callback implementation for Ecto.Type.embed_as/1.

Link to this function

encode(bytes, leading_zeroes? \\ true)

View Source

Returns the randomness portion of the encoded ulid

Returns the timestamp portion of the encoded ulid

Callback implementation for Ecto.Type.equal?/2.

Link to this function

generate(timestamp \\ System.system_time(:millisecond))

View Source

Generates a Crockford Base32 encoded ULID.

If a value is provided for timestamp, the generated ULID will be for the provided timestamp. Otherwise, a ULID will be generated for the current time.

Arguments:

  • timestamp: A Unix timestamp with millisecond precision.

Converts a binary ULID into a Crockford Base32 encoded string.

translates alphanumerics into a sentinel ulid value

Returns the timestamp of an encoded or unencoded ULID

The underlying schema type.