cabalize relational-record-examples

This commit is contained in:
Shohei Murayama 2014-12-12 11:37:29 +09:00
parent 4b8dac476a
commit 1e1aa96a44
16 changed files with 112 additions and 25 deletions

View File

@ -0,0 +1,30 @@
Copyright (c) 2014, Shohei Murayama
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Shohei Murayama nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1,54 @@
name: relational-record-examples
version: 0.1.0.0
synopsis: Examples of Haskell Relationa Record
description: Provides examples of Haskell Relational Record
license: BSD3
license-file: LICENSE
author: Kazu Yamamoto <kazu@iij.ad.jp>
Shohei Murayama <shohei.murayama@gmail.com>
maintainer: Shohei Murayama <shohei.murayama@gmail.com>
category: Database
build-type: Simple
cabal-version: >=1.10
library
hs-source-dirs: src
exposed-modules: Account
Branch
Business
Customer
DataSource
Department
Employee
Individual
Officer
Product
ProductType
Transaction
build-depends: base <5
, time
, template-haskell
, HDBC
, HDBC-sqlite3
, names-th
, sql-words
, HDBC-session
, persistable-record
, relational-query
, relational-schemas
, relational-query-HDBC
default-language: Haskell2010
executable query
hs-source-dirs: mains
main-is: Query.hs
build-depends: base <5
, HDBC
, HDBC-sqlite3
, HDBC-session
, persistable-record
, relational-query
, relational-query-HDBC
, relational-record-examples
default-language: Haskell2010

View File

@ -5,7 +5,7 @@ module Account where
import Prelude hiding (id)
import Database.Record.TH (derivingShow)
import DataSource (convTypes, defineTable)
import DataSource (defineTable)
$(defineTable convTypes
$(defineTable
"main" "account" [derivingShow])

View File

@ -5,7 +5,7 @@ module Branch where
import Prelude hiding (id, zip)
import Database.Record.TH (derivingShow)
import DataSource (convTypes, defineTable)
import DataSource (defineTable)
$(defineTable convTypes
$(defineTable
"main" "branch" [derivingShow])

View File

@ -5,7 +5,7 @@ module Business where
import Prelude hiding (id)
import Database.Record.TH (derivingShow)
import DataSource (convTypes, defineTable)
import DataSource (defineTable)
$(defineTable convTypes
$(defineTable
"main" "business" [derivingShow])

View File

@ -5,7 +5,7 @@ module Customer where
import Prelude hiding (id)
import Database.Record.TH (derivingShow)
import DataSource (convTypes, defineTable)
import DataSource (defineTable)
$(defineTable convTypes
$(defineTable
"main" "customer" [derivingShow])

View File

@ -24,8 +24,9 @@ convTypes =
, ("varchar", [t|String|])
]
defineTable :: [(String, TypeQ)] -> String -> String -> [ConName] -> Q [Dec]
defineTable tmap =
defineTable :: String -> String -> [ConName] -> Q [Dec]
defineTable =
defineTableFromDB
connect
(driverSQLite3 { typeMap = tmap })
(driverSQLite3 { typeMap = convTypes }) -- overwrite the default type map with yours

View File

@ -5,7 +5,7 @@ module Department where
import Prelude hiding (id)
import Database.Record.TH (derivingShow)
import DataSource (convTypes, defineTable)
import DataSource (defineTable)
$(defineTable convTypes
$(defineTable
"main" "department" [derivingShow])

View File

@ -5,7 +5,7 @@ module Employee where
import Prelude hiding (id)
import Database.Record.TH (derivingShow)
import DataSource (convTypes, defineTable)
import DataSource (defineTable)
$(defineTable convTypes
$(defineTable
"main" "employee" [derivingShow])

View File

@ -5,7 +5,7 @@ module Individual where
import Prelude hiding (id)
import Database.Record.TH (derivingShow)
import DataSource (convTypes, defineTable)
import DataSource (defineTable)
$(defineTable convTypes
$(defineTable
"main" "individual" [derivingShow])

View File

@ -5,7 +5,7 @@ module Officer where
import Prelude hiding (id)
import Database.Record.TH (derivingShow)
import DataSource (convTypes, defineTable)
import DataSource (defineTable)
$(defineTable convTypes
$(defineTable
"main" "officer" [derivingShow])

View File

@ -6,7 +6,7 @@ module Product where
import Prelude hiding (id, product)
import Database.Record.TH (derivingShow)
import DataSource (convTypes, defineTable)
import DataSource (defineTable)
$(defineTable convTypes
$(defineTable
"main" "product" [derivingShow])

View File

@ -6,7 +6,7 @@ module ProductType where
import Prelude hiding (id)
import Database.Record.TH (derivingShow)
import DataSource (convTypes, defineTable)
import DataSource (defineTable)
$(defineTable convTypes
$(defineTable
"main" "product_type" [derivingShow])

View File

@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain

View File

@ -5,9 +5,9 @@ module Transaction where
import Prelude hiding (id)
import Database.Record.TH (derivingShow)
import DataSource (convTypes, defineTable)
import DataSource (defineTable)
$(defineTable convTypes
$(defineTable
"main" "transaction0" [derivingShow])
type Transaction = Transaction0