Build Open Data Protocol (OData v4) queries in Elm.
This package supports a subset of OData 4.01 query option, common expression, and primitive literal.
http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html
http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html
Url.Builder.QueryParameter (see example)plainStringOperator (see example)customValue (see example)import Time
import Url
import Url.Builder
-- Custom value function
dateAsString : Time.Posix -> Value
dateAsString posix =
customValue (\s -> "'" ++ s ++ "'") (date posix)
[ filter
( or
[ eq "City" (string "Tallinn")
, eq "City" (string "Singapore")
-- Custom operator
, plainStringOperator "concat(concat(City,', '), Country) eq 'Berlin, Germany'"
-- Custom value
, ge "start/dateTime" (dateAsString (Time.millisToPosix 1631124861000))
]
)
, top 20
, skip 40
, orderBy [ ("Created", Just desc), ("City", Just asc) ]
, select [ "Id", "City", "Created", "Body" ]
]
|> List.map toQueryParameter
-- Custom query option
|> List.append [ Url.Builder.string "$search" "blue OR green" ]
|> Url.Builder.toQuery >> Url.percentDecode
--> Just (String.join ""
--> [ "?$search=blue OR green&"
--> , "$filter=City eq 'Tallinn' or "
--> , "City eq 'Singapore' or "
--> , "concat(concat(City,', '), Country) eq 'Berlin, Germany' or "
--> , "start/dateTime ge '2021-09-08'&"
--> , "$top=20&"
--> , "$skip=40&"
--> , "$orderBy=Created desc,City asc&"
--> , "$select=Id,City,Created,Body"
--> ])$ elm install Yagger/elm-odata4npx elm-verify-examples --run-testsCopyright © 2021 Jegor Uglov
Distributed under the MIT license.