Bools are YES/NO in information_schema

This commit is contained in:
Joe Nelson
2014-06-16 23:04:26 -07:00
parent c8e0110755
commit a73ed2c5fd
3 changed files with 55 additions and 1 deletions
+6
View File
@@ -0,0 +1,6 @@
db
dist
.cabal-sandbox
cabal.sandbox.config
hscope.out
codex.tags
+47
View File
@@ -0,0 +1,47 @@
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Database.PostgreSQL.Simple
import Database.PostgreSQL.Simple.FromRow
import Control.Applicative
data View = View {
viewSchema :: String
, viewName :: String
, viewUpdatable :: Bool
, viewInsertable :: Bool
} deriving (Show)
instance FromRow View where
fromRow = View <$> field <*> field <*>
fmap toBool field <*> fmap toBool field
toBool :: String -> Bool
toBool = (== "YES")
data Column = Column {
colSchema :: String
, colTable :: String
, colName :: String
, colPosition :: Int
, colNullable :: Bool
, colType :: String
, colUpdatable :: Bool
, colMaxLen :: Maybe Int
, colPrecision :: Maybe Int
} deriving (Show)
views :: Connection -> String -> IO [View]
views conn s = query conn q $ Only s
where q = "select table_schema, table_name,\
\ is_updatable, is_insertable_into \
\ from information_schema.views\
\ where table_schema = ?"
main :: IO ()
main = do
conn <- connect defaultConnectInfo {
connectDatabase = "dbapi_test"
}
mapM_ print =<< views conn "base"
+2 -1
View File
@@ -13,7 +13,8 @@ cabal-version: >=1.10
executable dbapi
main-is: Main.hs
-- other-modules:
-- other-extensions:
other-extensions: OverloadedStrings
build-depends: base >=4.7 && <4.8
, postgresql-simple
-- hs-source-dirs:
default-language: Haskell2010