Created
May 13, 2013 05:00
-
-
Save yuga/5566258 to your computer and use it in GitHub Desktop.
haskell-hdbc-tool #1: とりあえず簡単なクエリを動かすことができた。
(Github 2013-05-11時点のhaskell-hdbc-toolを使用)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE ScopedTypeVariables #-} | |
module Database.Test.PostgreSQL | |
( | |
connect | |
, defineTable | |
) where | |
import Language.Haskell.TH (Dec, Q) | |
import Language.Haskell.TH.Name.CamelCase (ConName) | |
import Database.HDBC.PostgreSQL (Connection, connectPostgreSQL) | |
import Database.HDBC.Schema.PostgreSQL (driverPostgreSQL) | |
import Database.HDBC.TH (defineTableFromDB) | |
{-# ANN module "HLint: ignore Eta reduce" #-} | |
connect :: IO Connection | |
connect = connectPostgreSQL "host=localhost port=50254 dbname=mdm user=postgres password=****" | |
defineTable :: String -> String -> [ConName] -> Q [Dec] | |
defineTable scm tbl derives = | |
defineTableFromDB | |
connect | |
driverPostgreSQL | |
scm tbl derives |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
module Database.Test.Query where | |
import Database.HDBC.Record.Query (runQuery') | |
import Database.HDBC.Session (withConnectionIO) | |
import Database.Relational.Query (Query) | |
import Database.Relational.Query.Join (from, relation) | |
import Database.Relational.Query.Type (fromRelation) | |
import Database.Test.PostgreSQL (connect) | |
import qualified Database.Test.Schema as SC | |
{-# ANN module "HLint: ignore Eta reduce" #-} | |
test1 :: IO [SC.TTenant] | |
test1 = withConnectionIO connect $ \conn -> | |
runQuery' conn () queryTTenant | |
queryTTenant :: Query () SC.TTenant | |
queryTTenant = fromRelation $ relation $ from SC.tableOfTTenant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE EmptyDataDecls #-} | |
{-# LANGUAGE TemplateHaskell #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
module Database.Test.Schema where | |
import Database.Test.PostgreSQL (defineTable) | |
import Language.Haskell.TH.Name.CamelCase (toConName) | |
import Prelude hiding (id) | |
$(defineTable "public" "t_tenant" [toConName "Show"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment