diff options
Diffstat (limited to 'src/Store/Query.hs')
-rw-r--r-- | src/Store/Query.hs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/Store/Query.hs b/src/Store/Query.hs index ccca93f..49fa4fb 100644 --- a/src/Store/Query.hs +++ b/src/Store/Query.hs @@ -46,7 +46,12 @@ query (Insert vs c) = do pure [] query (Select fs c js es w) = do c' <- - mapM (fmap (fromValue c) . decodeFile . (c </>)) + mapM + ( \fn -> + fromValue c + . union (J.Object (JM.singleton "$fileName" (J.String (T.pack fn)))) + <$> decodeFile (c </> fn) + ) =<< S.listFiles c js' <- mapM @@ -164,9 +169,9 @@ satisfies :: Maybe WhereClause -> Records J.Value -> Bool satisfies Nothing _ = True satisfies (Just (And ws)) vs = all (\w -> satisfies (Just w) vs) ws satisfies (Just (Or ws)) vs = any (\w -> satisfies (Just w) vs) ws -satisfies (Just (Where (Eq f g))) vs = lookups f vs == lookups g vs +satisfies (Just (Where (Eq f g))) vs = either Just (flip lookups vs) f == either Just (flip lookups vs) g -decodeFile :: J.FromJSON a => Collection -> S.StoreM a +decodeFile :: (J.FromJSON a) => Collection -> S.StoreM a decodeFile fp = fromMaybe (throw DecodeException) . J.decode <$> S.readFile fp |