From 593a53511ec170c67fd3453c88dcda960eac44fe Mon Sep 17 00:00:00 2001
From: Alexander Foremny <aforemny@posteo.de>
Date: Wed, 18 Dec 2024 19:11:57 +0100
Subject: add `LIMIT`, `ORDER BY` clauses

---
 app/Main.hs | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

(limited to 'app')

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"
-- 
cgit v1.2.3