aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Store/Query.hs11
-rw-r--r--src/Store/Query/Parser.hs4
-rw-r--r--src/Store/Query/Printer.hs4
-rw-r--r--src/Store/Query/Type.hs2
4 files changed, 14 insertions, 7 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
diff --git a/src/Store/Query/Parser.hs b/src/Store/Query/Parser.hs
index e16c926..99ddc79 100644
--- a/src/Store/Query/Parser.hs
+++ b/src/Store/Query/Parser.hs
@@ -114,9 +114,9 @@ instance IsString Query where
]
comparison = do
- a <- field
+ a <- P.choice [Left <$> value, Right <$> field]
eq
- b <- field
+ b <- P.choice [Left <$> value, Right <$> field]
pure $ Eq a b
fieldSelector =
diff --git a/src/Store/Query/Printer.hs b/src/Store/Query/Printer.hs
index 26f4e8b..cff543f 100644
--- a/src/Store/Query/Printer.hs
+++ b/src/Store/Query/Printer.hs
@@ -102,7 +102,9 @@ showWhereClauseWith wrap (Just (Or ws)) = Just (wrap (intercalate "OR" (mapMaybe
showWhereClauseWith _ (Just (Where p)) = Just (showComparison p)
showComparison :: Comparison -> String
-showComparison (Eq a b) = intercalate " " [showField a, "==", showField b]
+showComparison (Eq a b) = intercalate " " [showArg a, "==", showArg b]
+ where
+ showArg = either showValue showField
showValues :: [J.Value] -> Maybe String
showValues [] = Nothing
diff --git a/src/Store/Query/Type.hs b/src/Store/Query/Type.hs
index 7065267..912d020 100644
--- a/src/Store/Query/Type.hs
+++ b/src/Store/Query/Type.hs
@@ -62,5 +62,5 @@ data WhereClause
deriving (Show)
data Comparison
- = Eq Field Field
+ = Eq (Either J.Value Field) (Either J.Value Field)
deriving (Show)