diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..230092cfd --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +db +dist +.cabal-sandbox +cabal.sandbox.config +hscope.out +codex.tags diff --git a/Main.hs b/Main.hs new file mode 100644 index 000000000..981abc7e5 --- /dev/null +++ b/Main.hs @@ -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" diff --git a/dbapi.cabal b/dbapi.cabal index 67ad269ec..48add8935 100644 --- a/dbapi.cabal +++ b/dbapi.cabal @@ -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