Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Track client prefences set in HTTP Prefer
headers according to RFC7240[1].
Synopsis
- data Preferences = Preferences {}
- data PreferCount
- data PreferParameters
- data PreferRepresentation
- = Full
- | HeadersOnly
- | None
- data PreferResolution
- data PreferTransaction
- fromHeaders :: [Header] -> Preferences
- class ToHeaderValue a => ToAppliedHeader a where
- toAppliedHeader :: a -> Header
Documentation
data Preferences Source #
Preferences recognized by the application.
data PreferCount Source #
How to determine the count of (expected) results
ExactCount | Exact count (slower). |
PlannedCount | PostgreSQL query planner rows count guess. Done by using EXPLAIN {query}. |
EstimatedCount | Use the query planner rows if the count is superior to max-rows, otherwise get the exact count. |
Instances
Eq PreferCount Source # | |
Defined in PostgREST.Request.Preferences (==) :: PreferCount -> PreferCount -> Bool # (/=) :: PreferCount -> PreferCount -> Bool # |
data PreferParameters Source #
How to pass parameters to stored procedures.
SingleObject | Pass all parameters as a single json object to a stored procedure. |
MultipleObjects | Pass an array of json objects as params to a stored procedure. |
Instances
Eq PreferParameters Source # | |
Defined in PostgREST.Request.Preferences (==) :: PreferParameters -> PreferParameters -> Bool # (/=) :: PreferParameters -> PreferParameters -> Bool # |
data PreferRepresentation Source #
How to return the mutated data.
Full | Return the body plus the Location header(in case of POST). |
HeadersOnly | Return the Location header(in case of POST). This needs a SELECT privilege on the pk. |
None | Return nothing from the mutated data. |
Instances
Eq PreferRepresentation Source # | |
Defined in PostgREST.Request.Preferences (==) :: PreferRepresentation -> PreferRepresentation -> Bool # (/=) :: PreferRepresentation -> PreferRepresentation -> Bool # |
data PreferTransaction Source #
Whether to commit or roll back transactions.
Commit | Commit transaction - the default. |
Rollback | Rollback transaction after sending the response - does not persist changes, e.g. for running tests. |
Instances
Eq PreferTransaction Source # | |
Defined in PostgREST.Request.Preferences (==) :: PreferTransaction -> PreferTransaction -> Bool # (/=) :: PreferTransaction -> PreferTransaction -> Bool # | |
ToAppliedHeader PreferTransaction Source # | |
Defined in PostgREST.Request.Preferences |
fromHeaders :: [Header] -> Preferences Source #
Parse HTTP headers based on RFC7240[1] to identify preferences.
One header with comma-separated values can be used to set multiple preferences:
>>>
pPrint $ fromHeaders [("Prefer", "resolution=ignore-duplicates, count=exact")]
Preferences { preferResolution = Just IgnoreDuplicates , preferRepresentation = Nothing , preferParameters = Nothing , preferCount = Just ExactCount , preferTransaction = Nothing }
Multiple headers can also be used:
>>>
pPrint $ fromHeaders [("Prefer", "resolution=ignore-duplicates"), ("Prefer", "count=exact")]
Preferences { preferResolution = Just IgnoreDuplicates , preferRepresentation = Nothing , preferParameters = Nothing , preferCount = Just ExactCount , preferTransaction = Nothing }
If a preference is set more than once, only the first is used:
>>>
preferTransaction $ fromHeaders [("Prefer", "tx=commit, tx=rollback")]
Just Commit
This is also the case across multiple headers:
>>>
:{
preferResolution . fromHeaders $ [ ("Prefer", "resolution=ignore-duplicates") , ("Prefer", "resolution=merge-duplicates") ] :} Just IgnoreDuplicates
Preferences not recognized by the application are ignored:
>>>
preferResolution $ fromHeaders [("Prefer", "resolution=foo")]
Nothing
Preferences can be separated by arbitrary amounts of space, lower-case header is also recognized:
>>>
pPrint $ fromHeaders [("prefer", "count=exact, tx=commit ,return=minimal")]
Preferences { preferResolution = Nothing , preferRepresentation = Just None , preferParameters = Nothing , preferCount = Just ExactCount , preferTransaction = Just Commit }
class ToHeaderValue a => ToAppliedHeader a where Source #
Header to indicate that a preference has been applied.
>>>
toAppliedHeader MergeDuplicates
("Preference-Applied","resolution=merge-duplicates")
Nothing
toAppliedHeader :: a -> Header Source #