DSH 0.7.4 → 0.7.5
raw patch · 3 files changed
+39/−1 lines, 3 filesdep +json
Dependencies added: json
Files
- DSH.cabal +3/−1
- src/Database/DSH.hs +3/−0
- src/Database/DSH/JSON.hs +33/−0
DSH.cabal view
@@ -1,5 +1,5 @@ Name: DSH-Version: 0.7.4+Version: 0.7.5 Synopsis: Database Supported Haskell Description: This is a Haskell library for database-supported program execution. Using@@ -63,6 +63,7 @@ template-haskell >= 2.4, HaXml >= 1.22, csv >= 0.1,+ json >= 0.5, Pathfinder >= 0.5.8, FerryCore >= 0.4.6.4 @@ -78,5 +79,6 @@ Database.DSH.Data Database.DSH.Combinators Database.DSH.CSV+ Database.DSH.JSON Database.DSH.Impossible Database.DSH.Compile
src/Database/DSH.hs view
@@ -32,6 +32,7 @@ , generateTableDeclarations , module Database.DSH.CSV+ , module Database.DSH.JSON , module Data.String , module Data.Text@@ -42,7 +43,9 @@ import Database.DSH.Data (Q, QA, TA, table, tableDB, tableCSV, tableWithKeys, BasicType, View, view, fromView, tuple, record) import Database.DSH.TH (generateDatabaseRecordInstances, generateTableRecordInstances, generateRecordInstances, generateTableDeclarations)+ import Database.DSH.CSV+import Database.DSH.JSON import Database.DSH.Combinators
+ src/Database/DSH/JSON.hs view
@@ -0,0 +1,33 @@+module Database.DSH.JSON (jsonExport, jsonExportHandle, jsonExportStdout) where++import Database.DSH.Data++import Text.JSON++import qualified Data.Text as Text++import qualified System.IO as IO+import System.IO (Handle)++jsonExport :: (QA a) => FilePath -> [a] -> IO ()+jsonExport file as = IO.withFile file IO.WriteMode (\handle -> jsonExportHandle handle as)++jsonExportStdout :: (QA a) => [a] -> IO ()+jsonExportStdout = jsonExportHandle IO.stdout++jsonExportHandle :: (QA a) => Handle -> [a] -> IO ()+jsonExportHandle handle as = IO.hPutStr handle (encode $ go $ toNorm as)+ where go :: Norm -> JSValue+ go e = case e of+ UnitN _ -> showJSON "()"+ BoolN b _ -> showJSON b+ CharN c _ -> showJSON c+ IntegerN i _ -> showJSON i+ DoubleN d _ -> showJSON d+ TextN t _ -> showJSON (Text.unpack t)+ TupleN e1 e2 _ -> JSArray $ map go (e1 : deTuple e2)+ ListN es _ -> JSArray $ map go es++deTuple :: Norm -> [Norm]+deTuple (TupleN e1 e2 _) = e1 : deTuple e2+deTuple n = [n]