diff options
author | Alexander Foremny <aforemny@posteo.de> | 2024-12-18 19:11:57 +0100 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2024-12-18 19:12:01 +0100 |
commit | 593a53511ec170c67fd3453c88dcda960eac44fe (patch) | |
tree | ba9ce2d062649809959a4e21708db6e86fae6b97 /app/Main.hs | |
parent | 58e1cf274e80d8dbd4889bb2c99d3a009b590282 (diff) |
add `LIMIT`, `ORDER BY` clausesmain
Diffstat (limited to 'app/Main.hs')
-rw-r--r-- | app/Main.hs | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/app/Main.hs b/app/Main.hs index 945bfc9..3b7f59d 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE LambdaCase #-} + module Main ( main, ) @@ -9,6 +11,7 @@ import Data.Aeson qualified as J import Data.ByteString.Lazy.Char8 qualified as LB import Data.ByteString.Lazy.UTF8 qualified as LB import Data.String (IsString (fromString)) +import Data.Vector qualified as V import Network.HTTP.Types.Method qualified as W import Network.HTTP.Types.Status qualified as W import Network.Wai qualified as W @@ -63,7 +66,12 @@ main = do R.evalRepl (const . pure $ ">>> ") ( liftIO - . (mapM_ (LB.putStrLn . J.encode) =<<) + . ( ( \case + J.Array xs -> mapM_ (LB.putStrLn . J.encode) (V.toList xs) + x -> LB.putStrLn (J.encode x) + ) + =<< + ) . Q.withStore root ref . Q.query . fromString @@ -77,12 +85,12 @@ main = do Args {cmd = Serve} -> do W.runEnv 8080 $ \req respond -> do if - | W.requestMethod req == W.methodPost -> do - q <- - fromString @Q.Query . LB.toString - <$> W.lazyRequestBody req - r <- liftIO $ Q.withStore root ref (Q.query q) - respond . W.responseLBS W.status200 [] $ - J.encode r - | otherwise -> - respond $ W.responseLBS W.status200 [] "OK" + | W.requestMethod req == W.methodPost -> do + q <- + fromString @Q.Query . LB.toString + <$> W.lazyRequestBody req + r <- liftIO $ Q.withStore root ref (Q.query q) + respond . W.responseLBS W.status200 [] $ + J.encode r + | otherwise -> + respond $ W.responseLBS W.status200 [] "OK" |