Merge pull request #64 from begriffs/cleanup

Cleanup
This commit is contained in:
Adam C. Baker
2014-10-09 15:18:35 -07:00
2 changed files with 31 additions and 33 deletions
+7 -6
View File
@@ -1,4 +1,3 @@
{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
module PgStructure where module PgStructure where
@@ -121,8 +120,10 @@ columns s t conn = do
"select info.table_schema as schema, info.table_name as table_name, \ "select info.table_schema as schema, info.table_name as table_name, \
\ info.column_name as name, info.ordinal_position as position, \ \ info.column_name as name, info.ordinal_position as position, \
\ info.is_nullable as nullable, info.data_type as col_type, \ \ info.is_nullable as nullable, info.data_type as col_type, \
\ info.is_updatable as updatable, info.character_maximum_length as max_len, \ \ info.is_updatable as updatable, \
\ info.numeric_precision as precision, info.column_default as default_value,\ \ info.character_maximum_length as max_len, \
\ info.numeric_precision as precision, \
\ info.column_default as default_value, \
\ array_to_string(enum_info.vals, ',') as enum \ \ array_to_string(enum_info.vals, ',') as enum \
\ from ( \ \ from ( \
\ select table_schema, table_name, column_name, ordinal_position, \ \ select table_schema, table_name, column_name, ordinal_position, \
@@ -130,8 +131,7 @@ columns s t conn = do
\ character_maximum_length, numeric_precision, \ \ character_maximum_length, numeric_precision, \
\ column_default, udt_name \ \ column_default, udt_name \
\ from information_schema.columns \ \ from information_schema.columns \
\ where table_schema = ? \ \ where table_schema = ? and table_name = ? \
\ and table_name = ? \
\ ) as info \ \ ) as info \
\ left outer join ( \ \ left outer join ( \
\ select n.nspname as s, \ \ select n.nspname as s, \
@@ -151,7 +151,6 @@ columns s t conn = do
return cols return cols
where where
--TODO: handle failed pattern match with an appropriate exception
mkColumn [schema, table, name, pos, nullable, colT, updatable, maxlen, precision, defVal, enum] = Column (fromSql schema) mkColumn [schema, table, name, pos, nullable, colT, updatable, maxlen, precision, defVal, enum] = Column (fromSql schema)
(fromSql table) (fromSql table)
(fromSql name) (fromSql name)
@@ -163,6 +162,8 @@ columns s t conn = do
(fromSql precision) (fromSql precision)
(fromSql defVal) (fromSql defVal)
(splitOn "," <$> fromSql enum) (splitOn "," <$> fromSql enum)
mkColumn _ = error $ "Incomplete column data received for table " ++
t ++ " in schema " ++ s ++ "."
printTables :: String -> Connection -> IO BL.ByteString printTables :: String -> Connection -> IO BL.ByteString
printTables schema conn = JSON.encode <$> tables schema conn printTables schema conn = JSON.encode <$> tables schema conn
+3 -6
View File
@@ -1,4 +1,3 @@
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
{-# LANGUAGE OverloadedStrings, QuasiQuotes #-} {-# LANGUAGE OverloadedStrings, QuasiQuotes #-}
module Feature.StructureSpec where module Feature.StructureSpec where
@@ -13,12 +12,10 @@ import Codec.Binary.Base64.String (encode)
import Data.Monoid ((<>)) import Data.Monoid ((<>))
import Data.String.Conversions (cs) import Data.String.Conversions (cs)
uName = "a user"
uPass = "nobody can ever know"
uRole = "dbapi_test"
spec :: Spec spec :: Spec
spec = around withDatabaseConnection $ spec = let {uName = "a user"; uPass = "nobody can ever know";
uRole = "dbapi_test"} in
around withDatabaseConnection $
aroundWith (withUser uName uPass uRole) $ aroundWith withApp $ do aroundWith (withUser uName uPass uRole) $ aroundWith withApp $ do
describe "GET /" $ describe "GET /" $
it "lists views in schema" $ it "lists views in schema" $