Created
October 21, 2016 17:16
-
-
Save john-kelly/00424de66be03d9bbb07795b11c39a48 to your computer and use it in GitHub Desktop.
Example of nested entities using elm-postgrest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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