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/Record.hs | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) (limited to 'src/Store/Query/Record.hs') diff --git a/src/Store/Query/Record.hs b/src/Store/Query/Record.hs index 71461d5..b00be27 100644 --- a/src/Store/Query/Record.hs +++ b/src/Store/Query/Record.hs @@ -5,7 +5,6 @@ module Store.Query.Record lookup, Records, lookups, - select, disjointUnion, disjointUnions, ) @@ -16,8 +15,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') -import Data.List.NonEmpty qualified as N -import Data.Maybe (fromMaybe, mapMaybe) +import Data.Maybe (mapMaybe) import Data.Text qualified as T import Store.Exception (DuplicateField (DuplicateField)) import Store.Query.Field @@ -36,10 +34,8 @@ toValue :: Record a -> a toValue (Record _ v) = v lookup :: Field -> Record J.Value -> Maybe J.Value -lookup (Unqualified ks) (Record _ v) = - lookup' (N.toList ks) v -lookup (Qualified c' ks) (Record c v) - | c' == c = lookup' (N.toList ks) v +lookup (Field c' ks) (Record c v) + | c' == c = lookup' ks v | otherwise = Nothing lookup' :: [T.Text] -> J.Value -> Maybe J.Value @@ -56,16 +52,6 @@ lookups f rs = [v] -> Just v (_ : _) -> throw (DuplicateField (toString f)) -select :: [Field] -> Records J.Value -> J.Value -select fs rs = - foldl' - union - (J.Object JM.empty) - (map (\f -> prefix f ((fromMaybe J.Null (lookups f rs)))) fs) - -union :: J.Value -> J.Value -> J.Value -union (J.Object r) (J.Object s) = J.Object (JM.unionWith union r s) - disjointUnion :: J.Value -> J.Value -> J.Value disjointUnion (J.Object r) (J.Object s) = J.Object (JM.unionWithKey disjointUnion' r s) -- cgit v1.2.3