Skip to content

Instantly share code, notes, and snippets.

@john-kelly
Created October 21, 2016 17:16
Show Gist options
  • Save john-kelly/00424de66be03d9bbb07795b11c39a48 to your computer and use it in GitHub Desktop.
Save john-kelly/00424de66be03d9bbb07795b11c39a48 to your computer and use it in GitHub Desktop.
Example of nested entities using elm-postgrest
import Task
import PostgRest exposing (..)
trainerResource =
resource "trainer"
{ id = int "id"
, name = string "name"
}
pokemonResource =
resource "pokemon"
{ id = int "id"
, name = string "name"
, base_experience = int "base_experience"
, weight = int "weight"
, height = int "height"
}
type alias Pokemon =
{ id : Int
, name : String
}
type alias Trainer =
{ id : Int
, name : String
, pokemon : List Pokemon
}
pokemonQuery =
query pokemonResource Pokemon
|> select .id
|> select .name
|> filter [ .id |> lte 151 ]
|> order [ asc .id ]
trainerQuery =
query trainerResource Trainer
|> select .id
|> select .name
|> includeMany (Just 6) pokemonQuery
|> filter [ .name |> eq "Ash" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment