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

hex.pm hexdocs

Hybrid prefixed UUIDv7 and ULID data type for Ecto (using pride and needle_ulid)

Installation

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

Copyright (c) 2024 Bonfire 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 an encoded string to ID. Transforms outside data into runtime data.

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

Converts an encoded ID into a binary. Used to get your data ready to be written to the database. Transforms anything (outside data or runtime data) into database column data

Takes a string and returns true if it is a valid ULID (Universally Unique Lexicographically Sortable Identifier).

Takes a string and returns true if it is a valid Object ID or Prefixed UUID (Universally Unique Identifier).

Converts a binary ID into an encoded string. Transforms database column data into runtime data.

translates alphanumerics into a sentinel ID value

Returns the timestamp of an encoded or unencoded UID

The underlying schema type.

Takes a string and returns true if it is a valid UUID or ULID.

Functions

Link to this function

cast(term, params \\ nil)

View Source

Casts an encoded string to ID. Transforms outside data into runtime data.

Used to (potentially) convert your data into an internal normalized representation which will be part of your changesets. It also used for verifying that something is actually valid input data for your type.

Link to this function

cast!(value, params \\ nil)

View Source

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

Link to this function

dump(value, dumper \\ nil, params \\ nil)

View Source

Converts an encoded ID into a binary. Used to get your data ready to be written to the database. Transforms anything (outside data or runtime data) into database column data

Link to this function

generate(params_or_timestamp \\ nil)

View Source
Link to this function

is_pride?(str, params \\ nil)

View Source

Takes a string and returns true if it is a valid ULID (Universally Unique Lexicographically Sortable Identifier).

Examples

iex> is_ulid?("01J3MQ2Q4RVB1WTE3KT1D8ZNX1")
true

iex> is_ulid?("invalid_ulid")
false
Link to this function

is_uuid?(str, params \\ nil)

View Source

Takes a string and returns true if it is a valid Object ID or Prefixed UUID (Universally Unique Identifier).

Examples

iex> is_uuid?("550e8400-e29b-41d4-a716-446655440000")
true

iex> is_uuid?("test_3TUIKuXX5mNO2jSA41bsDx")
true

iex> is_uuid?("invalid_uuid")
false
Link to this function

load(value, loader \\ nil, params \\ nil)

View Source

Converts a binary ID into an encoded string. Transforms database column data into runtime data.

translates alphanumerics into a sentinel ID value

Returns the timestamp of an encoded or unencoded UID

The underlying schema type.

Link to this function

valid?(str, params \\ nil)

View Source

Takes a string and returns true if it is a valid UUID or ULID.

Examples

iex> valid?("01J3MQ2Q4RVB1WTE3KT1D8ZNX1")
true

iex> valid?("550e8400-e29b-41d4-a716-446655440000")
true

iex> is_uuid?("test_3TUIKuXX5mNO2jSA41bsDx")
true

iex> valid?("invalid_id")
false