feat: allow unknown on the is operator
Also make the IS values strict at the Parser level since IS cannot be parametrized.
This commit is contained in:
committed by
Steve Chavez
parent
91689e28f0
commit
bae5afbad6
@@ -195,15 +195,22 @@ pOpExpr pSVal = try ( string "not" *> pDelimiter *> (OpExpr True <$> pOperation)
|
||||
pOperation =
|
||||
Op . toS <$> foldl1 (<|>) (try . ((<* pDelimiter) . string) . toS <$> M.keys ops) <*> pSVal
|
||||
<|> In <$> (try (string "in" *> pDelimiter) *> pListVal)
|
||||
<|> Is <$> (try (string "is" *> pDelimiter) *> pTriVal)
|
||||
<|> pFts
|
||||
<?> "operator (eq, gt, ...)"
|
||||
|
||||
pTriVal = try (string "null" $> TriNull)
|
||||
<|> try (string "unknown" $> TriUnknown)
|
||||
<|> try (string "true" $> TriTrue)
|
||||
<|> try (string "false" $> TriFalse)
|
||||
<?> "null or trilean value (unknown, true, false)"
|
||||
|
||||
pFts = do
|
||||
op <- foldl1 (<|>) (try . string . toS <$> ftsOps)
|
||||
lang <- optionMaybe $ try (between (char '(') (char ')') (many (letter <|> digit <|> oneOf "_")))
|
||||
pDelimiter >> Fts (toS op) (toS <$> lang) <$> pSVal
|
||||
|
||||
ops = M.filterWithKey (const . flip notElem ("in":ftsOps)) operators
|
||||
ops = M.filterWithKey (const . flip notElem ("in":"is":ftsOps)) operators
|
||||
ftsOps = M.keys ftsOperators
|
||||
|
||||
pSingleVal :: Parser SingleVal
|
||||
|
||||
@@ -31,6 +31,7 @@ module PostgREST.Request.Types
|
||||
, ReadRequest
|
||||
, SelectItem
|
||||
, SingleVal
|
||||
, TrileanVal(..)
|
||||
, fstFieldNames
|
||||
) where
|
||||
|
||||
@@ -209,6 +210,7 @@ data OpExpr =
|
||||
data Operation
|
||||
= Op Operator SingleVal
|
||||
| In ListVal
|
||||
| Is TrileanVal
|
||||
| Fts Operator (Maybe Language) SingleVal
|
||||
deriving (Eq)
|
||||
|
||||
@@ -220,3 +222,11 @@ type SingleVal = Text
|
||||
|
||||
-- | Represents a list value in a filter, e.g. id=in.(val1,val2,val3)
|
||||
type ListVal = [Text]
|
||||
|
||||
-- | Three-valued logic values
|
||||
data TrileanVal
|
||||
= TriTrue
|
||||
| TriFalse
|
||||
| TriNull
|
||||
| TriUnknown
|
||||
deriving Eq
|
||||
|
||||
Reference in New Issue
Block a user