From dd06232369b6892950045712d0c6cd20e9987269 Mon Sep 17 00:00:00 2001 From: Joe Nelson Date: Sun, 22 Jun 2014 16:33:48 -0700 Subject: [PATCH] Turn column info into named hash --- PgStructure.hs | 6 +++++- dbapi.cabal | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/PgStructure.hs b/PgStructure.hs index 91071ab28..821e89241 100644 --- a/PgStructure.hs +++ b/PgStructure.hs @@ -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 diff --git a/dbapi.cabal b/dbapi.cabal index d796ac721..721b6bf86 100644 --- a/dbapi.cabal +++ b/dbapi.cabal @@ -19,5 +19,6 @@ executable dbapi , warp, wai, http-types , bytestring, aeson, network , text, optparse-applicative + , unordered-containers -- hs-source-dirs: default-language: Haskell2010