aboutsummaryrefslogtreecommitdiffstats
path: root/src/Store/Query.hs
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-02-13 07:50:30 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-02-13 07:50:30 +0100
commit748f82632e5ab6fc2c2f7a6eedb1ac4c467ccb3e (patch)
tree17467887fd046caf8ca68593a02156489264d39d /src/Store/Query.hs
parent7bb206831b37dde7a0f3208f445c8e645cc36a18 (diff)
explicitly construct objects in SELECT
Diffstat (limited to 'src/Store/Query.hs')
-rw-r--r--src/Store/Query.hs28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/Store/Query.hs b/src/Store/Query.hs
index b63b176..f8575af 100644
--- a/src/Store/Query.hs
+++ b/src/Store/Query.hs
@@ -9,7 +9,7 @@ import Data.Aeson qualified as J
import Data.Aeson.Key qualified as JK
import Data.Aeson.KeyMap qualified as JM
import Data.List (foldl', isSuffixOf)
-import Data.List.NonEmpty qualified as N
+import Data.Map qualified as M
import Data.Maybe (fromMaybe)
import Data.Vector qualified as V
import Store.Exception (DecodeException (DecodeException))
@@ -61,17 +61,12 @@ embed vss (EmbedClause (Record c es) w) =
vs
++ [ fromValue
c
- ( J.Object
- ( JM.singleton
- (JK.fromString c)
- ( J.Array
- ( V.fromList
- [ e
- | e <- es,
- satisfies w (vs ++ [Record c e])
- ]
- )
- )
+ ( J.Array
+ ( V.fromList
+ [ e
+ | e <- es,
+ satisfies w (vs ++ [Record c e])
+ ]
)
)
]
@@ -117,8 +112,13 @@ join vss (JoinClause JoinFull js w) =
js
select :: FieldSelector -> Records J.Value -> J.Value
-select All vs = disjointUnions (map toValue vs)
-select (Only fs) vs = Store.Query.Record.select (N.toList fs) vs
+select (SelectObject kvs) vs =
+ J.Object
+ . JM.fromMap
+ . M.mapKeys JK.fromString
+ . (M.map (\s -> Store.Query.select s vs))
+ $ kvs
+select (SelectField f) vs = fromMaybe J.Null (lookups f vs)
where_ :: Maybe WhereClause -> [Records J.Value] -> [Records J.Value]
where_ w = filter (satisfies w)