dinostore/key

Types

pub type JsKey

A key is simply a list of KeyParts.

pub type Key =
  List(KeyPart)
pub type KeyPart {
  StringPart(value: String)
  NumberPart(value: Float)
  BoolPart(value: Bool)
}

Constructors

  • StringPart(value: String)
  • NumberPart(value: Float)

    Number parts are represented as floats since JavaScript does not differentiate between integers and floats.

  • BoolPart(value: Bool)

Functions

pub fn b(b: Bool) -> KeyPart

Helper function to create a BoolPart.

pub fn decode(
  x: Dynamic,
) -> Result(List(KeyPart), List(DecodeError))

Decode a normal JavaScript key (e.g. one created with unwrap and stored in the database) into a Gleam Key.

Both this function and unwrap are helpful for creating secondary indexes where a primary key is stored as a secondary index’s value.

pub fn n(n: Float) -> KeyPart

Helper function to create a NumberPart.

pub fn s(s: String) -> KeyPart

Helper function to create a StringPart.

pub fn ulid() -> KeyPart

Create a ULID key part. To create a new ULID without a key, use the new function in the dinostore/ulid module.

Official Documentation

pub fn unwrap(key: List(KeyPart)) -> JsKey

Turn a Gleam Key into a normal JavaScript key (of the TS type (string | number | boolean)[]) by unwrapping the value of each KeyPart. Use decode to convert the key back to a Key.

Both this function and decode are helpful for creating secondary indexes where a primary key is stored as a secondary index’s value.

io.debug(unwrap([s("foo"), n(1.0), b(True)]))
// => #("foo", 1.0, True)
// Gleam tuples are represented as JavaScript arrays under the hood
Search Document