Turn column info into named hash
This commit is contained in:
+5
-1
@@ -5,6 +5,7 @@ module PgStructure where
|
|||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
|
|
||||||
import Data.Text
|
import Data.Text
|
||||||
|
import Data.HashMap.Strict
|
||||||
import Data.ByteString.Lazy
|
import Data.ByteString.Lazy
|
||||||
|
|
||||||
import Database.PostgreSQL.Simple
|
import Database.PostgreSQL.Simple
|
||||||
@@ -75,8 +76,11 @@ columns t conn = query conn q $ Only t
|
|||||||
\ from information_schema.columns\
|
\ from information_schema.columns\
|
||||||
\ where table_name = ?"
|
\ where table_name = ?"
|
||||||
|
|
||||||
|
namedColumnHash :: [Column] -> HashMap String Column
|
||||||
|
namedColumnHash = fromList . (Prelude.zip =<< Prelude.map colName)
|
||||||
|
|
||||||
printTables :: Connection -> IO ByteString
|
printTables :: Connection -> IO ByteString
|
||||||
printTables conn = JSON.encode <$> tables "base" conn
|
printTables conn = JSON.encode <$> tables "base" conn
|
||||||
|
|
||||||
printColumns :: Text -> Connection -> IO ByteString
|
printColumns :: Text -> Connection -> IO ByteString
|
||||||
printColumns table conn = JSON.encode <$> columns table conn
|
printColumns table conn = JSON.encode . namedColumnHash <$> columns table conn
|
||||||
|
|||||||
@@ -19,5 +19,6 @@ executable dbapi
|
|||||||
, warp, wai, http-types
|
, warp, wai, http-types
|
||||||
, bytestring, aeson, network
|
, bytestring, aeson, network
|
||||||
, text, optparse-applicative
|
, text, optparse-applicative
|
||||||
|
, unordered-containers
|
||||||
-- hs-source-dirs:
|
-- hs-source-dirs:
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
|||||||
Reference in New Issue
Block a user