Chadtech/elm-relational-database/1.1.1

NOTE: the latest version is 1.2.2

Remote.Id

Much like the Id type in the non-remote version of this module, except now the Id might also point to the error that occured when trying to load the item.

Id

type Id error x
fromString : String -> Id error x

Make an id from a string

Id.fromString "vq93rUv0A4"
toString : Id error x -> String

Extract the string from an id.

encode : Id error x -> Value

Encode an Id

Encode.encode 0 (Id.encode id)
-- ""hDFL0Cs2EqWJ4jc3kMtOrKdEUTWh"" : String


[ ("id", Id.encode id) ]
    |> Encode.object
    |> Encode.encode 0


-- {\"id\":\"hDFL0Cs2EqWJ4jc3kMtOrKdEUTWh\"} : String
decoder : Decoder (Id error x)

Decode an Id

Decode.decodeString (Decode.field "id" Id.decoder) "{\"id\":\"19\"}"
-- Ok (Id "19") : Result String Id
generator : Generator (Id error x)

A way to generate random Ids

import Id exposing (Id)
import Random exposing (Seed)


user : Seed -> ( User, Seed )
user seed =
    let
        ( id, nextSeed ) =
            Random.step Id.generator seed
    in
    ( { id = id, email = "[email protected]" }
    , nextSeed
    )