Turn column info into named hash

This commit is contained in:
Joe Nelson
2014-06-22 16:33:48 -07:00
parent 884f06b8cf
commit dd06232369
2 changed files with 6 additions and 1 deletions
+5 -1
View File
@@ -5,6 +5,7 @@ module PgStructure where
import Control.Applicative
import Data.Text
import Data.HashMap.Strict
import Data.ByteString.Lazy
import Database.PostgreSQL.Simple
@@ -75,8 +76,11 @@ columns t conn = query conn q $ Only t
\ from information_schema.columns\
\ where table_name = ?"
namedColumnHash :: [Column] -> HashMap String Column
namedColumnHash = fromList . (Prelude.zip =<< Prelude.map colName)
printTables :: Connection -> IO ByteString
printTables conn = JSON.encode <$> tables "base" conn
printColumns :: Text -> Connection -> IO ByteString
printColumns table conn = JSON.encode <$> columns table conn
printColumns table conn = JSON.encode . namedColumnHash <$> columns table conn
+1
View File
@@ -19,5 +19,6 @@ executable dbapi
, warp, wai, http-types
, bytestring, aeson, network
, text, optparse-applicative
, unordered-containers
-- hs-source-dirs:
default-language: Haskell2010