Bools are YES/NO in information_schema
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
db
|
||||
dist
|
||||
.cabal-sandbox
|
||||
cabal.sandbox.config
|
||||
hscope.out
|
||||
codex.tags
|
||||
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user