dinostore/key
Types
Functions
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 ulid() -> KeyPart
Create a ULID key part. To create a new ULID without a key, use the
new
function in the dinostore/ulid
module.
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