A type representing which attributes and resources you want to select. It also contains parameters that target nested resources.
A type to specify whether you want an order to be ascending or descending, and optionally whether you want nulls to be first or last.
Type that can be represented in the queries: strings, ints and lists.
A type that represents the clause of a query. In name=eq.John the clause would be the part
after the equal sign.
A constructor for the select parameter.
P.select
[ P.attribute "id"
, P.attribute "title"
, P.resource "user" <|
P.attributes
[ "email"
, "name"
]
]When you want to select all attributes. This is only useful when used to select attributes of a resource or override default parameters in another function since postgrest returns all attributes by default.
When you want to select a certain column.
Shorthand for attributes, when you don't need to specify nested resources:
-- Short version
attributes [ "id" "name" ]
-- Long version
[ attribute "id"
, attribute "name"
]When you want to select a nested resource with no special parameters for the nested
resources. If you do want to specify parameters, see resourceWithParams.
When you want to select a nested resource with special praameters.
[ P.select
[ P.resource "sites"
[ P.resourceWithParams "streams"
[ P.order [ P.asc "name" ]
]
allAttributes
]
]
]
|> toQueryString
-- select=sites(streams(*))&sites.streams.order=name.ascTakes a default set of params and a custom set of params and prefers the second set. Useful when you're constructing reusable functions that make similar queries.
Takes Params and returns the parameters as a list of (Key, Value) strings.
Takes Params and returns a query string such as
foo=eq.bar&baz=is.true
A constructor for an individual postgrest parameter.
param "name" (eq (string "John"))Join multiple conditions together with or.
[ or
[ param "age" <| gte <| int 14
, param "age" <| lte <| int 18
]
]
|> toQueryString
-- or=(age.gte.14,age.lte.18)Join multiple conditions together with and.
[ and
[ param "grade" <| gte <| int 90
, param "student" <| true
, or
[ param "age" <| gte <| int 14
, param "age" <| null
]
]
]
|> toQueryString
-- and=(grade.gte.90,student.is.true,or(age.gte.14,age.is.null))When you want to specify an operator for a nested resource manually. It is recommended to use resourceWithParams though.
[ select
[ attribute "*"
, resource "actors" allAttributes
]
, nestedParam [ "actors" ] <| limit 10
, nestedParam [ "actors" ] <| offset 2
]
|> toQueryString
-- "select=*,actors(*)&actors.limit=10&actors.offset=2"Used to indicate you need a column to be greater than or equal than a certain value.
Used to indicate you need a column to be within a certain list of values.
param "name" <| inList string [ "Chico", "Harpo", "Groucho" ]
-- name=in.(\"Chico\",\"Harpo\",\"Groucho\")"Used to indicate you need a column to be less than or equal than a certain value.
Negate a condition.
[ param "my_tsv" <| not <| phfts (Just "english") "The Fat Cats"
]
|> toQueryString
-- my_tsv=not.phfts(english).The%20Fat%20CatsWhen you need a column value to be true
-- foo=is.true
[ P.param "foo" P.true ]
|> toQueryStringWhen you need a column value to be false
-- foo=is.false
[ P.param "foo" P.false ]
|> toQueryStringWhen you don't want to use a specific type after the equals sign in the query, you
can use value to set anything you want.
This is available if you need it, but more likely you'll want to use
inList.
A constructor for the limit parameter.
order (asc "name")
order (desc "name")Used in combination with order to sort results ascending.
Used in combination with order to sort results descending.
Sort so that nulls will come first.
order [ asc "age" |> nullsfirst ]Sort so that nulls will come last.
order [ asc "age" |> nullslast ]
An individual postgrest parameter.