i think that should do it
This commit is contained in:
parent
cf7a6e50ae
commit
d2d52566bb
@ -727,20 +727,25 @@ testFilterOperators =
|
||||
testInclusion :: Spec
|
||||
testInclusion = do
|
||||
describe "@>" $ do
|
||||
it "creates sane SQL" $
|
||||
it "creates sane SQL" $ do
|
||||
let obj = object ["a" .= False, "b" .= True]
|
||||
encoded = BSL.toStrct $ encode obj
|
||||
createSaneSQL
|
||||
(jsonbVal (object ["a" .= False, "b" .= True]) @>. jsonbVal (object ["a" .= False]))
|
||||
(jsonbVal obj @>. jsonbVal (object ["a" .= False]))
|
||||
"SELECT (? @> ?)\nFROM \"Json\"\n"
|
||||
[ PersistLiteralEscaped "{\"a\":false,\"b\":true}"
|
||||
, PersistLiteralEscaped "{\"a\":false}" ]
|
||||
[ PersistLiteralEscaped encoded
|
||||
, PersistLiteralEscaped "{\"a\":false}"
|
||||
]
|
||||
it "creates sane SQL (chained)" $ do
|
||||
let obj = object ["a" .= [object ["b" .= True]]]
|
||||
encoded = BSL.toStrct $ encode obj
|
||||
createSaneSQL
|
||||
(jsonbVal obj ->. "a" @>. jsonbVal (object ["b" .= True]))
|
||||
"SELECT ((? -> ?) @> ?)\nFROM \"Json\"\n"
|
||||
[ PersistLiteralEscaped "{\"a\":[{\"b\":true}]}"
|
||||
[ PersistLiteralEscaped encoded
|
||||
, PersistText "a"
|
||||
, PersistLiteralEscaped "{\"b\":true}" ]
|
||||
, PersistLiteralEscaped "{\"b\":true}"
|
||||
]
|
||||
it "works as expected" $ run $ do
|
||||
x <- selectJSONwhere $ \v -> v @>. jsonbVal (Number 1)
|
||||
y <- selectJSONwhere $ \v -> v @>. jsonbVal (toJSON [object ["a" .= Number 3.14]])
|
||||
@ -750,19 +755,25 @@ testInclusion = do
|
||||
liftIO $ length z `shouldBe` 1
|
||||
describe "<@" $ do
|
||||
it "creates sane SQL" $
|
||||
let obj = object ["a" .= False, "b" .= True]
|
||||
encoded = BSL.toStrct $ encode obj
|
||||
createSaneSQL
|
||||
(jsonbVal (object ["a" .= False]) <@. jsonbVal (object ["a" .= False, "b" .= True]))
|
||||
(jsonbVal (object ["a" .= False]) <@. jsonbVal obj )
|
||||
"SELECT (? <@ ?)\nFROM \"Json\"\n"
|
||||
[ PersistLiteralEscaped "{\"a\":false}"
|
||||
, PersistLiteralEscaped "{\"a\":false,\"b\":true}" ]
|
||||
, PersistLiteralEscaped encoded
|
||||
]
|
||||
it "creates sane SQL (chained)" $ do
|
||||
let obj = object ["a" .= [object ["b" .= True]]]
|
||||
obj' = object ["b" .= True, "c" .= Null]
|
||||
encoded = encode obj'
|
||||
createSaneSQL
|
||||
(jsonbVal obj ->. "a" <@. jsonbVal (object ["b" .= True, "c" .= Null]))
|
||||
(jsonbVal obj ->. "a" <@. jsonbVal )
|
||||
"SELECT ((? -> ?) <@ ?)\nFROM \"Json\"\n"
|
||||
[ PersistLiteralEscaped "{\"a\":[{\"b\":true}]}"
|
||||
, PersistText "a"
|
||||
, PersistLiteralEscaped "{\"b\":true,\"c\":null}" ]
|
||||
, PersistLiteralEscaped encoded'
|
||||
]
|
||||
it "works as expected" $ run $ do
|
||||
x <- selectJSONwhere $ \v -> v <@. jsonbVal (toJSON [Number 1])
|
||||
y <- selectJSONwhere $ \v -> v <@. jsonbVal (object ["a" .= (1 :: Int), "b" .= False, "c" .= Null])
|
||||
@ -772,22 +783,27 @@ testInclusion = do
|
||||
liftIO $ length z `shouldBe` 1
|
||||
|
||||
testQMark :: Spec
|
||||
testQMark =
|
||||
testQMark = do
|
||||
describe "Question Mark" $ do
|
||||
it "creates sane SQL" $
|
||||
it "creates sane SQL" $ do
|
||||
let obj = object ["a" .= False, "b" .= True]
|
||||
encoded = BSL.toStrict $ encode obj
|
||||
createSaneSQL
|
||||
(jsonbVal (object ["a" .= False, "b" .= True]) JSON.?. "a")
|
||||
(jsonbVal obj JSON.?. "a")
|
||||
"SELECT (? ?? ?)\nFROM \"Json\"\n"
|
||||
[ PersistLiteralEscaped "{\"a\":false,\"b\":true}"
|
||||
, PersistText "a" ]
|
||||
[ PersistLiteralEscaped encoded
|
||||
, PersistText "a"
|
||||
]
|
||||
it "creates sane SQL (chained)" $ do
|
||||
let obj = object ["a" .= [object ["b" .= True]]]
|
||||
encoded = BSL.toStrict $ encode obj
|
||||
createSaneSQL
|
||||
(jsonbVal obj #>. ["a","0"] JSON.?. "b")
|
||||
"SELECT ((? #> ?) ?? ?)\nFROM \"Json\"\n"
|
||||
[ PersistLiteralEscaped "{\"a\":[{\"b\":true}]}"
|
||||
[ PersistLiteralEscaped encoded
|
||||
, persistTextArray ["a","0"]
|
||||
, PersistText "b" ]
|
||||
, PersistText "b"
|
||||
]
|
||||
it "works as expected" $ run $ do
|
||||
x <- selectJSONwhere (JSON.?. "a")
|
||||
y <- selectJSONwhere (JSON.?. "test")
|
||||
@ -797,22 +813,27 @@ testQMark =
|
||||
liftIO $ length z `shouldBe` 1
|
||||
|
||||
testQMarkAny :: Spec
|
||||
testQMarkAny =
|
||||
testQMarkAny = do
|
||||
describe "Question Mark (Any)" $ do
|
||||
it "creates sane SQL" $
|
||||
it "creates sane SQL" $ do
|
||||
let obj = (object ["a" .= False, "b" .= True])
|
||||
encoded = BSL.toStrict $ encode obj
|
||||
createSaneSQL
|
||||
(jsonbVal (object ["a" .= False, "b" .= True]) ?|. ["a","c"])
|
||||
(jsonbVal obj ?|. ["a","c"])
|
||||
"SELECT (? ??| ?)\nFROM \"Json\"\n"
|
||||
[ PersistLiteralEscaped "{\"a\":false,\"b\":true}"
|
||||
, persistTextArray ["a","c"] ]
|
||||
[ PersistLiteralEscaped encoded
|
||||
, persistTextArray ["a","c"]
|
||||
]
|
||||
it "creates sane SQL (chained)" $ do
|
||||
let obj = object ["a" .= [object ["b" .= True]]]
|
||||
encoded = BSL.toStrct $ encode obj
|
||||
createSaneSQL
|
||||
(jsonbVal obj #>. ["a","0"] ?|. ["b","c"])
|
||||
"SELECT ((? #> ?) ??| ?)\nFROM \"Json\"\n"
|
||||
[ PersistLiteralEscaped "{\"a\":[{\"b\":true}]}"
|
||||
[ PersistLiteralEscaped encoded
|
||||
, persistTextArray ["a","0"]
|
||||
, persistTextArray ["b","c"] ]
|
||||
, persistTextArray ["b","c"]
|
||||
]
|
||||
it "works as expected" $ run $ do
|
||||
x <- selectJSONwhere (?|. ["b","test"])
|
||||
y <- selectJSONwhere (?|. ["a"])
|
||||
@ -824,22 +845,27 @@ testQMarkAny =
|
||||
liftIO $ length w `shouldBe` 0
|
||||
|
||||
testQMarkAll :: Spec
|
||||
testQMarkAll =
|
||||
testQMarkAll = do
|
||||
describe "Question Mark (All)" $ do
|
||||
it "creates sane SQL" $
|
||||
it "creates sane SQL" $ do
|
||||
let obj = object ["a" .= False, "b" .= True]
|
||||
encoded = BSL.toStrct $ encode obj
|
||||
createSaneSQL
|
||||
(jsonbVal (object ["a" .= False, "b" .= True]) ?&. ["a","c"])
|
||||
(jsonbVal obj ?&. ["a","c"])
|
||||
"SELECT (? ??& ?)\nFROM \"Json\"\n"
|
||||
[ PersistLiteralEscaped "{\"a\":false,\"b\":true}"
|
||||
, persistTextArray ["a","c"] ]
|
||||
[ PersistLiteralEscaped encoded
|
||||
, persistTextArray ["a","c"]
|
||||
]
|
||||
it "creates sane SQL (chained)" $ do
|
||||
let obj = object ["a" .= [object ["b" .= True]]]
|
||||
encoded = BSL.toStrct $ encode obj
|
||||
createSaneSQL
|
||||
(jsonbVal obj #>. ["a","0"] ?&. ["b","c"])
|
||||
"SELECT ((? #> ?) ??& ?)\nFROM \"Json\"\n"
|
||||
[ PersistLiteralEscaped "{\"a\":[{\"b\":true}]}"
|
||||
[ PersistLiteralEscaped encoded
|
||||
, persistTextArray ["a","0"]
|
||||
, persistTextArray ["b","c"] ]
|
||||
, persistTextArray ["b","c"]
|
||||
]
|
||||
it "works as expected" $ run $ do
|
||||
x <- selectJSONwhere (?&. ["test"])
|
||||
y <- selectJSONwhere (?&. ["a","b"])
|
||||
@ -850,7 +876,6 @@ testQMarkAll =
|
||||
liftIO $ length z `shouldBe` 1
|
||||
liftIO $ length w `shouldBe` 9
|
||||
|
||||
|
||||
testConcatDeleteOperators :: Spec
|
||||
testConcatDeleteOperators = do
|
||||
describe "Concatenation Operator" testConcatenationOperator
|
||||
@ -860,23 +885,28 @@ testConcatDeleteOperators = do
|
||||
testHashMinusOperator
|
||||
|
||||
testConcatenationOperator :: Spec
|
||||
testConcatenationOperator =
|
||||
testConcatenationOperator = do
|
||||
describe "Concatenation" $ do
|
||||
it "creates sane SQL" $
|
||||
it "creates sane SQL" $ do
|
||||
let objAB = object ["a" .= False, "b" .= True]
|
||||
objC = object ["c" .= Null]
|
||||
createSaneSQL @JSONValue
|
||||
(jsonbVal (object ["a" .= False, "b" .= True])
|
||||
JSON.||. jsonbVal (object ["c" .= Null]))
|
||||
(jsonbVal objAB
|
||||
JSON.||. jsonbVal objC)
|
||||
"SELECT (? || ?)\nFROM \"Json\"\n"
|
||||
[ PersistLiteralEscaped "{\"a\":false,\"b\":true}"
|
||||
, PersistLiteralEscaped "{\"c\":null}" ]
|
||||
[ PersistLiteralEscaped $ BSL.toStrict $ encode objAB
|
||||
, PersistLiteralEscaped $ BSL.toStrict $ encode objC
|
||||
]
|
||||
it "creates sane SQL (chained)" $ do
|
||||
let obj = object ["a" .= [object ["b" .= True]]]
|
||||
encoded = BSL.toStrct $ encode obj
|
||||
createSaneSQL @JSONValue
|
||||
(jsonbVal obj ->. "a" JSON.||. jsonbVal (toJSON [Null]))
|
||||
"SELECT ((? -> ?) || ?)\nFROM \"Json\"\n"
|
||||
[ PersistLiteralEscaped "{\"a\":[{\"b\":true}]}"
|
||||
[ PersistLiteralEscaped encoded
|
||||
, PersistText "a"
|
||||
, PersistLiteralEscaped "[null]" ]
|
||||
, PersistLiteralEscaped "[null]"
|
||||
]
|
||||
it "works as expected" $ run $ do
|
||||
x <- selectJSON $ \v -> do
|
||||
where_ $ v @>. jsonbVal (object [])
|
||||
@ -942,22 +972,27 @@ testMinusOperator =
|
||||
where_ $ f v
|
||||
|
||||
testMinusOperatorV10 :: Spec
|
||||
testMinusOperatorV10 =
|
||||
testMinusOperatorV10 = do
|
||||
describe "Minus Operator (PSQL >= v10)" $ do
|
||||
it "creates sane SQL" $
|
||||
it "creates sane SQL" $ do
|
||||
let obj = object ["a" .= False, "b" .= True]
|
||||
encoded = BSL.toStrct $ encode obj
|
||||
createSaneSQL @JSONValue
|
||||
(jsonbVal (object ["a" .= False, "b" .= True]) --. ["a","b"])
|
||||
(jsonbVal obj --. ["a","b"])
|
||||
"SELECT (? - ?)\nFROM \"Json\"\n"
|
||||
[ PersistLiteralEscaped "{\"a\":false,\"b\":true}"
|
||||
, persistTextArray ["a","b"] ]
|
||||
[ PersistLiteralEscaped encoded
|
||||
, persistTextArray ["a","b"]
|
||||
]
|
||||
it "creates sane SQL (chained)" $ do
|
||||
let obj = object ["a" .= [object ["b" .= True]]]
|
||||
encoded = BSL.toStrct $ encode obj
|
||||
createSaneSQL @JSONValue
|
||||
(jsonbVal obj #>. ["a","0"] --. ["b"])
|
||||
"SELECT ((? #> ?) - ?)\nFROM \"Json\"\n"
|
||||
[ PersistLiteralEscaped "{\"a\":[{\"b\":true}]}"
|
||||
[ PersistLiteralEscaped encoded
|
||||
, persistTextArray ["a","0"]
|
||||
, persistTextArray ["b"] ]
|
||||
, persistTextArray ["b"]
|
||||
]
|
||||
it "works as expected" $ run $ do
|
||||
x <- selectJSON $ \v -> do
|
||||
where_ $ v @>. jsonbVal (toJSON ([] :: [Int]))
|
||||
@ -974,7 +1009,8 @@ testMinusOperatorV10 =
|
||||
liftIO $ length w `shouldBe` 0
|
||||
sqlFailWith "22023" $ selectJSONwhere $ \v ->
|
||||
v --. ["a"] @>. jsonbVal (toJSON ([] :: [Int]))
|
||||
where selectJSON_ f = selectJSON $ \v -> do
|
||||
where
|
||||
selectJSON_ f = selectJSON $ \v -> do
|
||||
where_ $ v @>. jsonbVal (object [])
|
||||
||. v @>. jsonbVal (toJSON ([] :: [Int]))
|
||||
where_ $ f v
|
||||
|
||||
Loading…
Reference in New Issue
Block a user