From 748f82632e5ab6fc2c2f7a6eedb1ac4c467ccb3e Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Tue, 13 Feb 2024 07:50:30 +0100 Subject: explicitly construct objects in SELECT --- src/Store/Query.hs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/Store/Query.hs') 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) -- cgit v1.2.3