suweal/identifier

Types

A typed identifier that can be used to uniquely identify a record in a SurrealDB database. The type parameter a is used to associate the identifier with a specific table or record type.

A typed identifier has the following string representation type:id but the type is optional and can also be represented as just id.

pub type Identifier(a) {
  Identifier(type_: option.Option(String), id: String)
}

Constructors

Values

pub fn compare(a: Identifier(a), b: Identifier(b)) -> order.Order

Compare two identifiers by their string representation. This is useful for sorting or ordering identifiers in a consistent manner. The comparison is case-sensitive and will return an Order value indicating whether the first identifier is less than, equal to, or greater than the second identifier.

pub fn decoder() -> decode.Decoder(Identifier(a))

The decoder for the Identifier type. This decoder will parse a string representation of an identifier and return an Identifier value. If the string is not a valid identifier, the decoder will return an error.

pub fn from_string(str: String) -> Result(Identifier(a), Nil)

Create a new identifier with the given type and id. The type is optional and can be used to associate the identifier with a specific table or record type.

pub fn generate(type_: option.Option(String)) -> Identifier(a)

Generate a new identifier with a random alphanumeric string of 20 characters. The type is optional and can be used to associate the identifier with a specific table or record type.

pub fn to_string(self: Identifier(a)) -> String

Convert the identifier to a string representation. If the identifier has a type, it will be represented as type:id, otherwise it will be represented as just id.

pub fn typed(self: Identifier(a), type_: String) -> Identifier(b)

Replace the type of the identifier with a new type. This is useful for converting between different types of identifiers that may represent the same underlying record in the database.

pub fn typed_decoder(
  allowed_types: List(String),
) -> decode.Decoder(Identifier(a))

The decoder for the Identifier type. This decoder will parse a string representation of an identifier and return an Identifier value. If the string is not a valid identifier, the decoder will return an error.

pub fn untyped(self: Identifier(a)) -> Identifier(b)

Remove the type from the identifier, returning an untyped identifier. This is useful for converting a typed identifier to an untyped identifier that can be used in contexts where the type is not needed or relevant.

✨ Search Document