diff options
author | Alexander Foremny <aforemny@posteo.de> | 2024-06-05 09:48:57 +0200 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2024-06-05 09:48:57 +0200 |
commit | 97c299fc60c7bde52b69014f0c85a5c4c73a4889 (patch) | |
tree | d5451f474258d4c6e5a087cad446bb80d9915aec /src/Store/Query.hs | |
parent | bbe3b75bfd0767c61bcd436e843b9c785efd289f (diff) |
support comparing `$fileName` against literals
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 |