2013-03-25 12:26:23 +04:00
|
|
|
|
|
|
|
module PgTestDataSource (
|
2013-05-10 21:31:43 +04:00
|
|
|
connect, defineTable
|
2013-03-25 12:26:23 +04:00
|
|
|
) where
|
|
|
|
|
2013-03-27 12:49:10 +04:00
|
|
|
import Language.Haskell.TH (Q, Dec, TypeQ)
|
2013-03-25 12:26:23 +04:00
|
|
|
import Database.HDBC.PostgreSQL (connectPostgreSQL, Connection)
|
|
|
|
import Database.HDBC.Schema.PostgreSQL (driverPostgreSQL)
|
2013-03-27 12:49:10 +04:00
|
|
|
import Database.HDBC.Schema.Driver (typeMap)
|
2013-05-07 11:59:30 +04:00
|
|
|
import Language.Haskell.TH.Name.CamelCase (ConName)
|
2013-05-04 18:56:24 +04:00
|
|
|
import Database.HDBC.TH (defineTableFromDB)
|
2013-03-25 12:26:23 +04:00
|
|
|
|
|
|
|
connect :: IO Connection
|
|
|
|
connect = connectPostgreSQL "dbname=testdb"
|
|
|
|
|
2013-03-27 12:49:10 +04:00
|
|
|
defineTable :: [(String, TypeQ)] -> String -> String -> [ConName] -> Q [Dec]
|
|
|
|
defineTable tmap scm tbl derives = do
|
|
|
|
defineTableFromDB
|
|
|
|
connect
|
|
|
|
(driverPostgreSQL { typeMap = tmap })
|
|
|
|
scm tbl derives
|