mirror of
https://github.com/khibino/haskell-relational-record.git
synced 2024-11-22 03:06:01 +03:00
Compare commits
15 Commits
999adf5318
...
2805670712
Author | SHA1 | Date | |
---|---|---|---|
|
2805670712 | ||
|
02bd6da37a | ||
|
db127a4067 | ||
|
98bfbbb92e | ||
|
55c49a1426 | ||
|
83d1c85976 | ||
|
caa967cb3e | ||
|
5e9e73b499 | ||
|
3b14d08150 | ||
|
0f0a1a2198 | ||
|
ba0a125b5f | ||
|
058e1a56ac | ||
|
74b279f87d | ||
|
85e02bcc27 | ||
|
8f58642b96 |
@ -1,5 +1,5 @@
|
||||
name: HDBC-session
|
||||
version: 0.1.2.0
|
||||
version: 0.1.2.1
|
||||
synopsis: Bracketed connection for HDBC
|
||||
description: This package contains a base bracketed function
|
||||
to call close correctly against opend DB connection.
|
||||
@ -8,11 +8,16 @@ license: BSD3
|
||||
license-file: LICENSE
|
||||
author: Kei Hibino
|
||||
maintainer: ex8k.hibino@gmail.com
|
||||
copyright: Copyright (c) 2013-2020 Kei Hibino
|
||||
copyright: Copyright (c) 2013-2023 Kei Hibino
|
||||
category: Database
|
||||
build-type: Simple
|
||||
cabal-version: >=1.10
|
||||
tested-with: GHC == 8.8.1, GHC == 8.8.2
|
||||
tested-with: GHC == 9.6.2
|
||||
, GHC == 9.4.6
|
||||
, GHC == 9.2.8
|
||||
, GHC == 9.0.2
|
||||
, GHC == 8.10.7
|
||||
, GHC == 8.8.1, GHC == 8.8.2
|
||||
, GHC == 8.6.1, GHC == 8.6.2, GHC == 8.6.3, GHC == 8.6.4, GHC == 8.6.5
|
||||
, GHC == 8.4.1, GHC == 8.4.2, GHC == 8.4.3, GHC == 8.4.4
|
||||
, GHC == 8.2.1, GHC == 8.2.2
|
||||
|
@ -10,6 +10,7 @@ packages: ./HDBC-session
|
||||
./relational-query
|
||||
./relational-query-HDBC
|
||||
./relational-record
|
||||
./relational-record-examples
|
||||
./relational-schemas
|
||||
./sql-words
|
||||
./text-postgresql
|
||||
|
@ -8,11 +8,16 @@ license: BSD3
|
||||
license-file: LICENSE
|
||||
author: Kei Hibino
|
||||
maintainer: ex8k.hibino@gmail.com
|
||||
copyright: Copyright (c) 2013-2020 Kei Hibino, 2015 Shohei Murayama
|
||||
copyright: Copyright (c) 2013-2023 Kei Hibino, 2015 Shohei Murayama
|
||||
category: Development
|
||||
build-type: Simple
|
||||
cabal-version: >=1.10
|
||||
tested-with: GHC == 8.8.1, GHC == 8.8.2
|
||||
tested-with: GHC == 9.6.2
|
||||
, GHC == 9.4.6
|
||||
, GHC == 9.2.8
|
||||
, GHC == 9.0.2
|
||||
, GHC == 8.10.7
|
||||
, GHC == 8.8.1, GHC == 8.8.2
|
||||
, GHC == 8.6.1, GHC == 8.6.2, GHC == 8.6.3, GHC == 8.6.4, GHC == 8.6.5
|
||||
, GHC == 8.4.1, GHC == 8.4.2, GHC == 8.4.3, GHC == 8.4.4
|
||||
, GHC == 8.2.1, GHC == 8.2.2
|
||||
|
@ -1,5 +1,9 @@
|
||||
<!-- -*- Markdown -*- -->
|
||||
|
||||
## 0.6.0.6
|
||||
|
||||
- fix typo.
|
||||
|
||||
## 0.6.0.5
|
||||
|
||||
- apply compat interface packages of TH.
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: persistable-record
|
||||
version: 0.6.0.5
|
||||
version: 0.6.0.6
|
||||
synopsis: Binding between SQL database values and haskell records.
|
||||
description: This package contains types to represent table constraints and
|
||||
interfaces to bind between SQL database values and Haskell records.
|
||||
@ -8,11 +8,16 @@ license: BSD3
|
||||
license-file: LICENSE
|
||||
author: Kei Hibino
|
||||
maintainer: ex8k.hibino@gmail.com
|
||||
copyright: Copyright (c) 2013-2020 Kei Hibino
|
||||
copyright: Copyright (c) 2013-2023 Kei Hibino
|
||||
category: Database
|
||||
build-type: Simple
|
||||
cabal-version: >=1.10
|
||||
tested-with: GHC == 8.8.1, GHC == 8.8.2
|
||||
tested-with: GHC == 9.6.2
|
||||
, GHC == 9.4.6
|
||||
, GHC == 9.2.8
|
||||
, GHC == 9.0.2
|
||||
, GHC == 8.10.7
|
||||
, GHC == 8.8.1, GHC == 8.8.2
|
||||
, GHC == 8.6.1, GHC == 8.6.2, GHC == 8.6.3, GHC == 8.6.4, GHC == 8.6.5
|
||||
, GHC == 8.4.1, GHC == 8.4.2, GHC == 8.4.3, GHC == 8.4.4
|
||||
, GHC == 8.2.1, GHC == 8.2.2
|
||||
|
@ -10,11 +10,16 @@ license: BSD3
|
||||
license-file: LICENSE
|
||||
author: Kei Hibino
|
||||
maintainer: ex8k.hibino@gmail.com
|
||||
copyright: Copyright (c) 2015-2020 Kei Hibino
|
||||
copyright: Copyright (c) 2015-2023 Kei Hibino
|
||||
category: Database
|
||||
build-type: Simple
|
||||
cabal-version: >=1.10
|
||||
tested-with: GHC == 8.8.1, GHC == 8.8.2
|
||||
tested-with: GHC == 9.6.2
|
||||
, GHC == 9.4.6
|
||||
, GHC == 9.2.8
|
||||
, GHC == 9.0.2
|
||||
, GHC == 8.10.7
|
||||
, GHC == 8.8.1, GHC == 8.8.2
|
||||
, GHC == 8.6.1, GHC == 8.6.2, GHC == 8.6.3, GHC == 8.6.4, GHC == 8.6.5
|
||||
, GHC == 8.4.1, GHC == 8.4.2, GHC == 8.4.3, GHC == 8.4.4
|
||||
, GHC == 8.2.1, GHC == 8.2.2
|
||||
|
@ -1,5 +1,9 @@
|
||||
<!-- -*- Markdown -*- -->
|
||||
|
||||
## 0.7.2.1
|
||||
|
||||
- fix typo.
|
||||
|
||||
## 0.7.2.0
|
||||
|
||||
- apply new module names of relational-schema.
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: relational-query-HDBC
|
||||
version: 0.7.2.0
|
||||
version: 0.7.2.1
|
||||
synopsis: HDBC instance of relational-query and typed query interface for HDBC
|
||||
description: This package contains the HDBC instance of relational-query and
|
||||
the typed query interface for HDBC.
|
||||
@ -12,11 +12,16 @@ license: BSD3
|
||||
license-file: LICENSE
|
||||
author: Kei Hibino, Shohei Murayama, Shohei Yasutake, Sho KURODA
|
||||
maintainer: ex8k.hibino@gmail.com, shohei.murayama@gmail.com, amutake.s@gmail.com, krdlab@gmail.com
|
||||
copyright: Copyright (c) 2013-2020 Kei Hibino, 2013 Shohei Murayama, 2013 Shohei Yasutake, 2013 Sho KURODA
|
||||
copyright: Copyright (c) 2013-2023 Kei Hibino, 2013 Shohei Murayama, 2013 Shohei Yasutake, 2013 Sho KURODA
|
||||
category: Database
|
||||
build-type: Simple
|
||||
cabal-version: >=1.10
|
||||
tested-with: GHC == 8.8.1, GHC == 8.8.2
|
||||
tested-with: GHC == 9.6.2
|
||||
, GHC == 9.4.6
|
||||
, GHC == 9.2.8
|
||||
, GHC == 9.0.2
|
||||
, GHC == 8.10.7
|
||||
, GHC == 8.8.1, GHC == 8.8.2
|
||||
, GHC == 8.6.1, GHC == 8.6.2, GHC == 8.6.3, GHC == 8.6.4, GHC == 8.6.5
|
||||
, GHC == 8.4.1, GHC == 8.4.2, GHC == 8.4.3, GHC == 8.4.4
|
||||
, GHC == 8.2.1, GHC == 8.2.2
|
||||
|
@ -1,9 +1,19 @@
|
||||
<!-- -*- Markdown -*- -->
|
||||
|
||||
## 0.12.3.1
|
||||
|
||||
- compat for template-haskell 2.17.0.0
|
||||
- fix typo.
|
||||
|
||||
## 0.12.3.0
|
||||
|
||||
- add module to export SQL string representation for other systems.
|
||||
|
||||
## 0.12.2.4
|
||||
|
||||
- compat for template-haskell 2.17.0.0
|
||||
- fix typo.
|
||||
|
||||
## 0.12.2.3
|
||||
|
||||
- update for GHC 8.8.x.
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: relational-query
|
||||
version: 0.12.3.0
|
||||
version: 0.12.3.1
|
||||
synopsis: Typeful, Modular, Relational, algebraic query engine
|
||||
description: This package contains typeful relation structure and
|
||||
relational-algebraic query building DSL which can
|
||||
@ -16,11 +16,16 @@ license: BSD3
|
||||
license-file: LICENSE
|
||||
author: Kei Hibino
|
||||
maintainer: ex8k.hibino@gmail.com
|
||||
copyright: Copyright (c) 2013-2020 Kei Hibino
|
||||
copyright: Copyright (c) 2013-2023 Kei Hibino
|
||||
category: Database
|
||||
build-type: Simple
|
||||
cabal-version: >=1.10
|
||||
tested-with: GHC == 8.8.1, GHC == 8.8.2
|
||||
tested-with: GHC == 9.6.2
|
||||
, GHC == 9.4.6
|
||||
, GHC == 9.2.8
|
||||
, GHC == 9.0.2
|
||||
, GHC == 8.10.7
|
||||
, GHC == 8.8.1, GHC == 8.8.2
|
||||
, GHC == 8.6.1, GHC == 8.6.2, GHC == 8.6.3, GHC == 8.6.4, GHC == 8.6.5
|
||||
, GHC == 8.4.1, GHC == 8.4.2, GHC == 8.4.3, GHC == 8.4.4
|
||||
, GHC == 8.2.1, GHC == 8.2.2
|
||||
@ -119,6 +124,7 @@ library
|
||||
, template-haskell
|
||||
, th-reify-compat
|
||||
, th-constraint-compat
|
||||
, th-data-compat
|
||||
, product-isomorphic >= 0.0.3
|
||||
, sql-words >=0.1.5
|
||||
, names-th
|
||||
|
@ -27,6 +27,7 @@ import Language.Haskell.TH
|
||||
Dec, sigD, valD, instanceD,
|
||||
TyVarBndr (PlainTV), )
|
||||
import Language.Haskell.TH.Compat.Constraint (classP)
|
||||
import Language.Haskell.TH.Compat.Data (plainTVspecified)
|
||||
import Database.Record.Persistable
|
||||
(PersistableWidth, persistableWidth,
|
||||
PersistableRecordWidth, runPersistableRecordWidth)
|
||||
@ -59,7 +60,7 @@ defineRecordProjections tyRec avs sels cts =
|
||||
template :: TypeQ -> [TypeQ] -> Name -> Q [Dec]
|
||||
template ct pcts selN = do
|
||||
sig <- sigD selN $
|
||||
forallT (map PlainTV avs)
|
||||
forallT (map plainTVspecified avs)
|
||||
(mapM (classP ''PersistableWidth . (:[]) . varT) avs)
|
||||
[t| Pi $tyRec $ct |]
|
||||
let runPW t = [| runPersistableRecordWidth (persistableWidth :: PersistableRecordWidth $t) |]
|
||||
|
@ -61,6 +61,17 @@ account_3_7 = relation $ do
|
||||
asc proj
|
||||
return proj
|
||||
|
||||
-----
|
||||
|
||||
data Account2 = Account2
|
||||
{ a2AccountId :: Int
|
||||
, a2ProductCd :: String
|
||||
, a2OpenDate :: Day
|
||||
, a2AvailBalance :: Maybe Double
|
||||
} deriving (Show, Generic)
|
||||
|
||||
$(makeRelationalRecord ''Account2)
|
||||
|
||||
-- | sql/3.7.1
|
||||
--
|
||||
-- Handwritten SQL:
|
||||
@ -88,14 +99,17 @@ account_3_7_1 = relation $ do
|
||||
|*| #openDate a
|
||||
|*| #availBalance a
|
||||
|
||||
data Account2 = Account2
|
||||
{ a2AccountId :: Int
|
||||
, a2ProductCd :: String
|
||||
, a2OpenDate :: Day
|
||||
, a2AvailBalance :: Maybe Double
|
||||
-----
|
||||
|
||||
data Employee1 = Employee1
|
||||
{ e1EmpId :: Int
|
||||
, e1Title :: Maybe String
|
||||
, e1StartDate :: Day
|
||||
, e1Fname :: String
|
||||
, e1Lname' :: String
|
||||
} deriving (Show, Generic)
|
||||
|
||||
$(makeRelationalRecord ''Account2)
|
||||
$(makeRelationalRecord ''Employee1)
|
||||
|
||||
-- | sql/3.7.3
|
||||
--
|
||||
@ -130,16 +144,6 @@ employee_3_7_3 = relation $ do
|
||||
|*| #fname e
|
||||
|*| #lname e
|
||||
|
||||
data Employee1 = Employee1
|
||||
{ e1EmpId :: Int
|
||||
, e1Title :: Maybe String
|
||||
, e1StartDate :: Day
|
||||
, e1Fname :: String
|
||||
, e1Lname' :: String
|
||||
} deriving (Show, Generic)
|
||||
|
||||
$(makeRelationalRecord ''Employee1)
|
||||
|
||||
-- | sql/4.1.2
|
||||
--
|
||||
-- HRR supports date literal of the SQL standard, such like DATE '2003-01-01'.
|
||||
@ -199,6 +203,17 @@ employee_4_1_2P = relation' . placeholder $ \ph -> do
|
||||
`or'` #startDate e .<. ph
|
||||
return e
|
||||
|
||||
-----
|
||||
|
||||
data Employee2 = Employee2
|
||||
{ e2EmpId :: Int
|
||||
, e2Fname :: String
|
||||
, e2Lname :: String
|
||||
, e2StartDate :: Day
|
||||
} deriving (Show, Generic)
|
||||
|
||||
$(makeRelationalRecord ''Employee2)
|
||||
|
||||
-- | sql/4.3.2
|
||||
--
|
||||
-- Handwritten SQL:
|
||||
@ -213,15 +228,15 @@ employee_4_1_2P = relation' . placeholder $ \ph -> do
|
||||
--
|
||||
-- @
|
||||
-- SELECT ALL T0.emp_id AS f0, T0.fname AS f1, T0.lname AS f2,
|
||||
-- T0.start_date AS f3 FROM MAIN.employee T0 WHERE ((T0.start_date >=
|
||||
-- '2001-01-01') AND (T0.start_date < '2003-01-01'))
|
||||
-- T0.start_date AS f3 FROM MAIN.employee T0 WHERE
|
||||
-- ((T0.start_date >= '2001-01-01') AND (T0.start_date <= '2002-12-31'))
|
||||
-- @
|
||||
--
|
||||
employee_4_3_2 :: Relation () Employee2
|
||||
employee_4_3_2 = relation $ do
|
||||
e <- query employee
|
||||
wheres $ #startDate e .>=. unsafeSQLiteDayValue "2001-01-01"
|
||||
wheres $ #startDate e .<. unsafeSQLiteDayValue "2003-01-01"
|
||||
wheres $ #startDate e .<=. unsafeSQLiteDayValue "2002-12-31"
|
||||
return $ Employee2 |$| #empId e
|
||||
|*| #fname e
|
||||
|*| #lname e
|
||||
@ -234,8 +249,8 @@ employee_4_3_2 = relation $ do
|
||||
--
|
||||
-- @
|
||||
-- SELECT ALL T0.emp_id AS f0, T0.fname AS f1, T0.lname AS f2,
|
||||
-- T0.start_date AS f3 FROM MAIN.employee T0 WHERE ((T0.start_date >= ?)
|
||||
-- AND (T0.start_date <= ?))
|
||||
-- T0.start_date AS f3 FROM MAIN.employee T0 WHERE
|
||||
-- ((T0.start_date >= ?) AND (T0.start_date <= ?))
|
||||
-- @
|
||||
--
|
||||
-- NOTE: Be careful on the order of the placeholders. You must give day
|
||||
@ -252,15 +267,6 @@ employee_4_3_2P = relation' . placeholder $ \ph -> do
|
||||
|*| #lname e
|
||||
|*| date
|
||||
|
||||
data Employee2 = Employee2
|
||||
{ e2EmpId :: Int
|
||||
, e2Fname :: String
|
||||
, e2Lname :: String
|
||||
, e2StartDate :: Day
|
||||
} deriving (Show, Generic)
|
||||
|
||||
$(makeRelationalRecord ''Employee2)
|
||||
|
||||
-- | sql/4.3.3a
|
||||
--
|
||||
-- Handwritten SQL:
|
||||
@ -302,6 +308,17 @@ account_4_3_3aT = relation $ do
|
||||
wheres $ #productCd a `in'` values ["CHK", "SAV", "CD", "MM"]
|
||||
return $ (,,,) |$| #accountId a |*| #productCd a |*| #custId a |*| #availBalance a
|
||||
|
||||
-----
|
||||
|
||||
data Account1 = Account1
|
||||
{ a1AccountId :: Int
|
||||
, a1ProductCd :: String
|
||||
, a1CustId :: Int
|
||||
, a1AvailBalance :: Maybe Double
|
||||
} deriving (Show, Generic)
|
||||
|
||||
$(makeRelationalRecord ''Account1)
|
||||
|
||||
-- |
|
||||
-- Adhoc defined record version of Generated SQL:
|
||||
--
|
||||
@ -322,15 +339,6 @@ account_4_3_3aR = relation $ do
|
||||
|*| #custId a
|
||||
|*| #availBalance a
|
||||
|
||||
data Account1 = Account1
|
||||
{ a1AccountId :: Int
|
||||
, a1ProductCd :: String
|
||||
, a1CustId :: Int
|
||||
, a1AvailBalance :: Maybe Double
|
||||
} deriving (Show, Generic)
|
||||
|
||||
$(makeRelationalRecord ''Account1)
|
||||
|
||||
-- |
|
||||
-- 9.1 What is a subquery?
|
||||
--
|
||||
@ -504,6 +512,17 @@ join_5_1_2aT = relation $ do
|
||||
on $ #deptId e .=. just (#deptId d)
|
||||
return $ (,,) |$| #fname e |*| #lname e |*| #name d
|
||||
|
||||
-----
|
||||
|
||||
data Account4 = Account4
|
||||
{ a4AccountId :: Int
|
||||
, a4CustId :: Int
|
||||
, a4Fname :: Maybe String
|
||||
, a4Lname :: Maybe String
|
||||
} deriving (Show, Generic)
|
||||
|
||||
$(makeRelationalRecord ''Account4)
|
||||
|
||||
-- |
|
||||
-- Left Outer Join
|
||||
--
|
||||
@ -532,15 +551,6 @@ account_LeftOuterJoin = relation $ do
|
||||
|*| (? #fname) i
|
||||
|*| (? #lname) i
|
||||
|
||||
data Account4 = Account4
|
||||
{ a4AccountId :: Int
|
||||
, a4CustId :: Int
|
||||
, a4Fname :: Maybe String
|
||||
, a4Lname :: Maybe String
|
||||
} deriving (Show, Generic)
|
||||
|
||||
$(makeRelationalRecord ''Account4)
|
||||
|
||||
-- |
|
||||
-- Right Outer Join
|
||||
--
|
||||
@ -569,6 +579,17 @@ business_RightOuterJoin = relation $ do
|
||||
on $ (? #custId) c .=. just (#custId b)
|
||||
return ((? #custId) c >< #name b)
|
||||
|
||||
-----
|
||||
|
||||
data Account3 = Account3
|
||||
{ a3AccountId :: Int
|
||||
, a3CustId :: Int
|
||||
, a3OpenDate :: Day
|
||||
, a3ProductCd :: String
|
||||
} deriving (Show, Generic)
|
||||
|
||||
$(makeRelationalRecord ''Account3)
|
||||
|
||||
-- | sql/5.1.3
|
||||
--
|
||||
-- Handwritten SQL:
|
||||
@ -612,15 +633,6 @@ join_5_1_3 = relation $ do
|
||||
|*| #openDate a
|
||||
|*| #productCd a
|
||||
|
||||
data Account3 = Account3
|
||||
{ a3AccountId :: Int
|
||||
, a3CustId :: Int
|
||||
, a3OpenDate :: Day
|
||||
, a3ProductCd :: String
|
||||
} deriving (Show, Generic)
|
||||
|
||||
$(makeRelationalRecord ''Account3)
|
||||
|
||||
-- | sql/5.3a
|
||||
--
|
||||
-- Handwritten SQL:
|
||||
@ -768,6 +780,16 @@ group_8_1a = aggregateRelation $ do
|
||||
asc $ g
|
||||
return $ g >< count (#accountId a)
|
||||
|
||||
-----
|
||||
|
||||
data Customer1 = Customer1
|
||||
{ c1Custid :: Int
|
||||
, c1CustTypeCd :: String
|
||||
, c1City :: Maybe String
|
||||
} deriving (Show, Generic)
|
||||
|
||||
$(makeRelationalRecord ''Customer1)
|
||||
|
||||
-- |
|
||||
-- 9.4 Correlated Subqueries
|
||||
--
|
||||
@ -801,20 +823,12 @@ customer_9_4 = relation $ do
|
||||
wheres $ just (value (2 :: Int64)) .=. ca
|
||||
return (customer1 c)
|
||||
|
||||
data Customer1 = Customer1
|
||||
{ c1Custid :: Int
|
||||
, c1CustTypeCd :: String
|
||||
, c1City :: Maybe String
|
||||
} deriving (Show, Generic)
|
||||
|
||||
customer1 :: SqlContext c
|
||||
=> Record c Customer -> Record c Customer1
|
||||
customer1 c = Customer1 |$| #custId c
|
||||
|*| #custTypeCd c
|
||||
|*| #city c
|
||||
|
||||
$(makeRelationalRecord ''Customer1)
|
||||
|
||||
-- |
|
||||
-- (from script) The insert statement
|
||||
--
|
||||
@ -840,6 +854,18 @@ insertBranch_s1 = insertValueNoPH $ do
|
||||
#state <-# value (Just "MA")
|
||||
#zip <-# value (Just "02451")
|
||||
|
||||
-----
|
||||
|
||||
data Branch1 = Branch1
|
||||
{ b1Name :: String
|
||||
, b1Address :: Maybe String
|
||||
, b1City :: Maybe String
|
||||
, b1State :: Maybe String
|
||||
, b1Zip :: Maybe String
|
||||
} deriving (Generic)
|
||||
|
||||
$(makeRelationalRecord ''Branch1)
|
||||
|
||||
-- |
|
||||
-- Placeholder version of Generated SQL:
|
||||
--
|
||||
@ -858,16 +884,6 @@ piBranch1 = Branch1 |$| #name
|
||||
|*| #state
|
||||
|*| #zip
|
||||
|
||||
data Branch1 = Branch1
|
||||
{ b1Name :: String
|
||||
, b1Address :: Maybe String
|
||||
, b1City :: Maybe String
|
||||
, b1State :: Maybe String
|
||||
, b1Zip :: Maybe String
|
||||
} deriving (Generic)
|
||||
|
||||
$(makeRelationalRecord ''Branch1)
|
||||
|
||||
branch1 :: Branch1
|
||||
branch1 = Branch1
|
||||
{ b1Name = "Headquarters"
|
||||
@ -927,6 +943,18 @@ branchTuple = ("Headquarters",
|
||||
Just "MA",
|
||||
Just "02451")
|
||||
|
||||
-----
|
||||
|
||||
data Employee3 = Employee3
|
||||
{ e3Fname :: String
|
||||
, e3Lname :: String
|
||||
, e3StartDate :: Day
|
||||
, e3DeptId :: Maybe Int
|
||||
, e3Title :: Maybe String
|
||||
, e3AssignedBranchId :: Maybe Int
|
||||
} deriving (Generic)
|
||||
|
||||
$(makeRelationalRecord ''Employee3)
|
||||
|
||||
-- |
|
||||
-- (from script) The insert statement
|
||||
@ -978,17 +1006,6 @@ piEmployee3 = Employee3 |$| #fname
|
||||
|*| #title
|
||||
|*| #assignedBranchId
|
||||
|
||||
data Employee3 = Employee3
|
||||
{ e3Fname :: String
|
||||
, e3Lname :: String
|
||||
, e3StartDate :: Day
|
||||
, e3DeptId :: Maybe Int
|
||||
, e3Title :: Maybe String
|
||||
, e3AssignedBranchId :: Maybe Int
|
||||
} deriving (Generic)
|
||||
|
||||
$(makeRelationalRecord ''Employee3)
|
||||
|
||||
-- |
|
||||
-- In the following code we simulate to use queryScalar with using
|
||||
-- unsafeUnique. By that means we throw away the safety given by HRR
|
||||
@ -1022,6 +1039,8 @@ insertEmployee_s2U = insertQuery piEmployee3 . relation $ do
|
||||
|*| value (Just "President")
|
||||
|*| b
|
||||
|
||||
-----
|
||||
|
||||
-- place the definition of Employee4 that contains template-haskell, before
|
||||
-- insertEmployee_s2P uses the function to be generated.
|
||||
data Employee4 = Employee4
|
||||
|
@ -66,6 +66,17 @@ account_3_7 = relation $ do
|
||||
asc proj
|
||||
return proj
|
||||
|
||||
-----
|
||||
|
||||
data Account2 = Account2
|
||||
{ a2AccountId :: Int
|
||||
, a2ProductCd :: String
|
||||
, a2OpenDate :: Day
|
||||
, a2AvailBalance :: Maybe Double
|
||||
} deriving (Show, Generic)
|
||||
|
||||
$(makeRelationalRecord ''Account2)
|
||||
|
||||
-- | sql/3.7.1
|
||||
--
|
||||
-- Handwritten SQL:
|
||||
@ -93,14 +104,17 @@ account_3_7_1 = relation $ do
|
||||
|*| a ! Account.openDate'
|
||||
|*| a ! Account.availBalance'
|
||||
|
||||
data Account2 = Account2
|
||||
{ a2AccountId :: Int
|
||||
, a2ProductCd :: String
|
||||
, a2OpenDate :: Day
|
||||
, a2AvailBalance :: Maybe Double
|
||||
-----
|
||||
|
||||
data Employee1 = Employee1
|
||||
{ e1EmpId :: Int
|
||||
, e1Title :: Maybe String
|
||||
, e1StartDate :: Day
|
||||
, e1Fname :: String
|
||||
, e1Lname' :: String
|
||||
} deriving (Show, Generic)
|
||||
|
||||
$(makeRelationalRecord ''Account2)
|
||||
$(makeRelationalRecord ''Employee1)
|
||||
|
||||
-- | sql/3.7.3
|
||||
--
|
||||
@ -135,16 +149,6 @@ employee_3_7_3 = relation $ do
|
||||
|*| e ! Employee.fname'
|
||||
|*| e ! Employee.lname'
|
||||
|
||||
data Employee1 = Employee1
|
||||
{ e1EmpId :: Int
|
||||
, e1Title :: Maybe String
|
||||
, e1StartDate :: Day
|
||||
, e1Fname :: String
|
||||
, e1Lname' :: String
|
||||
} deriving (Show, Generic)
|
||||
|
||||
$(makeRelationalRecord ''Employee1)
|
||||
|
||||
-- | sql/4.1.2
|
||||
--
|
||||
-- HRR supports date literal of the SQL standard, such like DATE '2003-01-01'.
|
||||
@ -204,6 +208,17 @@ employee_4_1_2P = relation' . placeholder $ \ph -> do
|
||||
`or'` e ! Employee.startDate' .<. ph
|
||||
return e
|
||||
|
||||
-----
|
||||
|
||||
data Employee2 = Employee2
|
||||
{ e2EmpId :: Int
|
||||
, e2Fname :: String
|
||||
, e2Lname :: String
|
||||
, e2StartDate :: Day
|
||||
} deriving (Show, Generic)
|
||||
|
||||
$(makeRelationalRecord ''Employee2)
|
||||
|
||||
-- | sql/4.3.2
|
||||
--
|
||||
-- Handwritten SQL:
|
||||
@ -218,15 +233,15 @@ employee_4_1_2P = relation' . placeholder $ \ph -> do
|
||||
--
|
||||
-- @
|
||||
-- SELECT ALL T0.emp_id AS f0, T0.fname AS f1, T0.lname AS f2,
|
||||
-- T0.start_date AS f3 FROM MAIN.employee T0 WHERE ((T0.start_date >=
|
||||
-- '2001-01-01') AND (T0.start_date < '2003-01-01'))
|
||||
-- T0.start_date AS f3 FROM MAIN.employee T0 WHERE
|
||||
-- ((T0.start_date >= '2001-01-01') AND (T0.start_date <= '2002-12-31'))
|
||||
-- @
|
||||
--
|
||||
employee_4_3_2 :: Relation () Employee2
|
||||
employee_4_3_2 = relation $ do
|
||||
e <- query employee
|
||||
wheres $ e ! Employee.startDate' .>=. unsafeSQLiteDayValue "2001-01-01"
|
||||
wheres $ e ! Employee.startDate' .<. unsafeSQLiteDayValue "2003-01-01"
|
||||
wheres $ e ! Employee.startDate' .<=. unsafeSQLiteDayValue "2002-12-31"
|
||||
return $ Employee2 |$| e ! Employee.empId'
|
||||
|*| e ! Employee.fname'
|
||||
|*| e ! Employee.lname'
|
||||
@ -239,8 +254,8 @@ employee_4_3_2 = relation $ do
|
||||
--
|
||||
-- @
|
||||
-- SELECT ALL T0.emp_id AS f0, T0.fname AS f1, T0.lname AS f2,
|
||||
-- T0.start_date AS f3 FROM MAIN.employee T0 WHERE ((T0.start_date >= ?)
|
||||
-- AND (T0.start_date <= ?))
|
||||
-- T0.start_date AS f3 FROM MAIN.employee T0 WHERE
|
||||
-- ((T0.start_date >= ?) AND (T0.start_date <= ?))
|
||||
-- @
|
||||
--
|
||||
-- NOTE: Be careful on the order of the placeholders. You must give day
|
||||
@ -257,15 +272,6 @@ employee_4_3_2P = relation' . placeholder $ \ph -> do
|
||||
|*| e ! Employee.lname'
|
||||
|*| date
|
||||
|
||||
data Employee2 = Employee2
|
||||
{ e2EmpId :: Int
|
||||
, e2Fname :: String
|
||||
, e2Lname :: String
|
||||
, e2StartDate :: Day
|
||||
} deriving (Show, Generic)
|
||||
|
||||
$(makeRelationalRecord ''Employee2)
|
||||
|
||||
-- | sql/4.3.3a
|
||||
--
|
||||
-- Handwritten SQL:
|
||||
@ -307,6 +313,17 @@ account_4_3_3aT = relation $ do
|
||||
wheres $ a ! Account.productCd' `in'` values ["CHK", "SAV", "CD", "MM"]
|
||||
return $ (,,,) |$| a ! Account.accountId' |*| a ! Account.productCd' |*| a ! Account.custId' |*| a ! Account.availBalance'
|
||||
|
||||
-----
|
||||
|
||||
data Account1 = Account1
|
||||
{ a1AccountId :: Int
|
||||
, a1ProductCd :: String
|
||||
, a1CustId :: Int
|
||||
, a1AvailBalance :: Maybe Double
|
||||
} deriving (Show, Generic)
|
||||
|
||||
$(makeRelationalRecord ''Account1)
|
||||
|
||||
-- |
|
||||
-- Adhoc defined record version of Generated SQL:
|
||||
--
|
||||
@ -327,15 +344,6 @@ account_4_3_3aR = relation $ do
|
||||
|*| a ! Account.custId'
|
||||
|*| a ! Account.availBalance'
|
||||
|
||||
data Account1 = Account1
|
||||
{ a1AccountId :: Int
|
||||
, a1ProductCd :: String
|
||||
, a1CustId :: Int
|
||||
, a1AvailBalance :: Maybe Double
|
||||
} deriving (Show, Generic)
|
||||
|
||||
$(makeRelationalRecord ''Account1)
|
||||
|
||||
-- |
|
||||
-- 9.1 What is a subquery?
|
||||
--
|
||||
@ -509,6 +517,17 @@ join_5_1_2aT = relation $ do
|
||||
on $ e ! Employee.deptId' .=. just (d ! Department.deptId')
|
||||
return $ (,,) |$| e ! Employee.fname' |*| e ! Employee.lname' |*| d ! Department.name'
|
||||
|
||||
-----
|
||||
|
||||
data Account4 = Account4
|
||||
{ a4AccountId :: Int
|
||||
, a4CustId :: Int
|
||||
, a4Fname :: Maybe String
|
||||
, a4Lname :: Maybe String
|
||||
} deriving (Show, Generic)
|
||||
|
||||
$(makeRelationalRecord ''Account4)
|
||||
|
||||
-- |
|
||||
-- Left Outer Join
|
||||
--
|
||||
@ -537,15 +556,6 @@ account_LeftOuterJoin = relation $ do
|
||||
|*| i ?! Individual.fname'
|
||||
|*| i ?! Individual.lname'
|
||||
|
||||
data Account4 = Account4
|
||||
{ a4AccountId :: Int
|
||||
, a4CustId :: Int
|
||||
, a4Fname :: Maybe String
|
||||
, a4Lname :: Maybe String
|
||||
} deriving (Show, Generic)
|
||||
|
||||
$(makeRelationalRecord ''Account4)
|
||||
|
||||
-- |
|
||||
-- Right Outer Join
|
||||
--
|
||||
@ -574,6 +584,17 @@ business_RightOuterJoin = relation $ do
|
||||
on $ c ?! Customer.custId' .=. just (b ! Business.custId')
|
||||
return (c ?! Customer.custId' >< b ! Business.name')
|
||||
|
||||
-----
|
||||
|
||||
data Account3 = Account3
|
||||
{ a3AccountId :: Int
|
||||
, a3CustId :: Int
|
||||
, a3OpenDate :: Day
|
||||
, a3ProductCd :: String
|
||||
} deriving (Show, Generic)
|
||||
|
||||
$(makeRelationalRecord ''Account3)
|
||||
|
||||
-- | sql/5.1.3
|
||||
--
|
||||
-- Handwritten SQL:
|
||||
@ -617,15 +638,6 @@ join_5_1_3 = relation $ do
|
||||
|*| a ! Account.openDate'
|
||||
|*| a ! Account.productCd'
|
||||
|
||||
data Account3 = Account3
|
||||
{ a3AccountId :: Int
|
||||
, a3CustId :: Int
|
||||
, a3OpenDate :: Day
|
||||
, a3ProductCd :: String
|
||||
} deriving (Show, Generic)
|
||||
|
||||
$(makeRelationalRecord ''Account3)
|
||||
|
||||
-- | sql/5.3a
|
||||
--
|
||||
-- Handwritten SQL:
|
||||
@ -773,6 +785,16 @@ group_8_1a = aggregateRelation $ do
|
||||
asc $ g ! id'
|
||||
return $ g >< count (a ! Account.accountId')
|
||||
|
||||
-----
|
||||
|
||||
data Customer1 = Customer1
|
||||
{ c1Custid :: Int
|
||||
, c1CustTypeCd :: String
|
||||
, c1City :: Maybe String
|
||||
} deriving (Show, Generic)
|
||||
|
||||
$(makeRelationalRecord ''Customer1)
|
||||
|
||||
-- |
|
||||
-- 9.4 Correlated Subqueries
|
||||
--
|
||||
@ -806,20 +828,12 @@ customer_9_4 = relation $ do
|
||||
wheres $ just (value (2 :: Int64)) .=. ca
|
||||
return (customer1 c)
|
||||
|
||||
data Customer1 = Customer1
|
||||
{ c1Custid :: Int
|
||||
, c1CustTypeCd :: String
|
||||
, c1City :: Maybe String
|
||||
} deriving (Show, Generic)
|
||||
|
||||
customer1 :: SqlContext c
|
||||
=> Record c Customer -> Record c Customer1
|
||||
customer1 c = Customer1 |$| c ! Customer.custId'
|
||||
|*| c ! Customer.custTypeCd'
|
||||
|*| c ! Customer.city'
|
||||
|
||||
$(makeRelationalRecord ''Customer1)
|
||||
|
||||
-- |
|
||||
-- (from script) The insert statement
|
||||
--
|
||||
@ -845,6 +859,18 @@ insertBranch_s1 = insertValueNoPH $ do
|
||||
Branch.state' <-# value (Just "MA")
|
||||
Branch.zip' <-# value (Just "02451")
|
||||
|
||||
-----
|
||||
|
||||
data Branch1 = Branch1
|
||||
{ b1Name :: String
|
||||
, b1Address :: Maybe String
|
||||
, b1City :: Maybe String
|
||||
, b1State :: Maybe String
|
||||
, b1Zip :: Maybe String
|
||||
} deriving (Generic)
|
||||
|
||||
$(makeRelationalRecord ''Branch1)
|
||||
|
||||
-- |
|
||||
-- Placeholder version of Generated SQL:
|
||||
--
|
||||
@ -863,16 +889,6 @@ piBranch1 = Branch1 |$| Branch.name'
|
||||
|*| Branch.state'
|
||||
|*| Branch.zip'
|
||||
|
||||
data Branch1 = Branch1
|
||||
{ b1Name :: String
|
||||
, b1Address :: Maybe String
|
||||
, b1City :: Maybe String
|
||||
, b1State :: Maybe String
|
||||
, b1Zip :: Maybe String
|
||||
} deriving (Generic)
|
||||
|
||||
$(makeRelationalRecord ''Branch1)
|
||||
|
||||
branch1 :: Branch1
|
||||
branch1 = Branch1
|
||||
{ b1Name = "Headquarters"
|
||||
@ -932,6 +948,18 @@ branchTuple = ("Headquarters",
|
||||
Just "MA",
|
||||
Just "02451")
|
||||
|
||||
-----
|
||||
|
||||
data Employee3 = Employee3
|
||||
{ e3Fname :: String
|
||||
, e3Lname :: String
|
||||
, e3StartDate :: Day
|
||||
, e3DeptId :: Maybe Int
|
||||
, e3Title :: Maybe String
|
||||
, e3AssignedBranchId :: Maybe Int
|
||||
} deriving (Generic)
|
||||
|
||||
$(makeRelationalRecord ''Employee3)
|
||||
|
||||
-- |
|
||||
-- (from script) The insert statement
|
||||
@ -983,17 +1011,6 @@ piEmployee3 = Employee3 |$| Employee.fname'
|
||||
|*| Employee.title'
|
||||
|*| Employee.assignedBranchId'
|
||||
|
||||
data Employee3 = Employee3
|
||||
{ e3Fname :: String
|
||||
, e3Lname :: String
|
||||
, e3StartDate :: Day
|
||||
, e3DeptId :: Maybe Int
|
||||
, e3Title :: Maybe String
|
||||
, e3AssignedBranchId :: Maybe Int
|
||||
} deriving (Generic)
|
||||
|
||||
$(makeRelationalRecord ''Employee3)
|
||||
|
||||
-- |
|
||||
-- In the following code we simulate to use queryScalar with using
|
||||
-- unsafeUnique. By that means we throw away the safety given by HRR
|
||||
@ -1027,6 +1044,8 @@ insertEmployee_s2U = insertQuery piEmployee3 . relation $ do
|
||||
|*| value (Just "President")
|
||||
|*| b
|
||||
|
||||
-----
|
||||
|
||||
-- place the definition of Employee4 that contains template-haskell, before
|
||||
-- insertEmployee_s2P uses the function to be generated.
|
||||
data Employee4 = Employee4
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: relational-record-examples
|
||||
version: 0.6.0.0
|
||||
version: 0.6.0.1
|
||||
synopsis: Examples of Haskell Relationa Record
|
||||
description: Provides examples of Haskell Relational Record
|
||||
license: BSD3
|
||||
|
@ -7,11 +7,16 @@ license: BSD3
|
||||
license-file: LICENSE
|
||||
author: Kei Hibino
|
||||
maintainer: ex8k.hibino@gmail.com
|
||||
copyright: Copyright (c) 2014-2020 Kei Hibino
|
||||
copyright: Copyright (c) 2014-2023 Kei Hibino
|
||||
category: Database
|
||||
build-type: Simple
|
||||
cabal-version: >=1.10
|
||||
tested-with: GHC == 8.8.1, GHC == 8.8.2
|
||||
tested-with: GHC == 9.6.2
|
||||
, GHC == 9.4.6
|
||||
, GHC == 9.2.8
|
||||
, GHC == 9.0.2
|
||||
, GHC == 8.10.7
|
||||
, GHC == 8.8.1, GHC == 8.8.2
|
||||
, GHC == 8.6.1, GHC == 8.6.2, GHC == 8.6.3, GHC == 8.6.4, GHC == 8.6.5
|
||||
, GHC == 8.4.1, GHC == 8.4.2, GHC == 8.4.3, GHC == 8.4.4
|
||||
, GHC == 8.2.1, GHC == 8.2.2
|
||||
|
@ -1,5 +1,9 @@
|
||||
<!-- -*- Markdown -*- -->
|
||||
|
||||
## 0.1.8.1
|
||||
|
||||
- fix typo.
|
||||
|
||||
## 0.1.8.0
|
||||
|
||||
- update for GHC 8.8.x.
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: relational-schemas
|
||||
version: 0.1.8.0
|
||||
version: 0.1.8.1
|
||||
synopsis: RDBMSs' schema templates for relational-query
|
||||
description: This package contains some RDBMSs' schema structure definitions.
|
||||
.
|
||||
@ -16,11 +16,16 @@ license: BSD3
|
||||
license-file: LICENSE
|
||||
author: Kei Hibino, Shohei Murayama, Shohei Yasutake, Sho KURODA
|
||||
maintainer: ex8k.hibino@gmail.com, shohei.murayama@gmail.com, amutake.s@gmail.com, krdlab@gmail.com
|
||||
copyright: Copyright (c) 2013-2020 Kei Hibino, 2013 Shohei Murayama, 2013 Shohei Yasutake, 2013 Sho KURODA
|
||||
copyright: Copyright (c) 2013-2023 Kei Hibino, 2013 Shohei Murayama, 2013 Shohei Yasutake, 2013 Sho KURODA
|
||||
category: Database
|
||||
build-type: Simple
|
||||
cabal-version: >=1.10
|
||||
tested-with: GHC == 8.8.1, GHC == 8.8.2
|
||||
tested-with: GHC == 9.6.2
|
||||
, GHC == 9.4.6
|
||||
, GHC == 9.2.8
|
||||
, GHC == 9.0.2
|
||||
, GHC == 8.10.7
|
||||
, GHC == 8.8.1, GHC == 8.8.2
|
||||
, GHC == 8.6.1, GHC == 8.6.2, GHC == 8.6.3, GHC == 8.6.4, GHC == 8.6.5
|
||||
, GHC == 8.4.1, GHC == 8.4.2, GHC == 8.4.3, GHC == 8.4.4
|
||||
, GHC == 8.2.1, GHC == 8.2.2
|
||||
|
@ -10,7 +10,7 @@ license: BSD3
|
||||
license-file: LICENSE
|
||||
author: Kei Hibino
|
||||
maintainer: ex8k.hibino@gmail.com
|
||||
copyright: Copyright (c) 2017-2020 Kei Hibino
|
||||
copyright: Copyright (c) 2017-2023 Kei Hibino
|
||||
category: Testing
|
||||
build-type: Simple
|
||||
-- extra-source-files:
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: sql-words
|
||||
version: 0.1.6.4
|
||||
version: 0.1.6.5
|
||||
synopsis: SQL keywords data constructors into OverloadedString
|
||||
description: This package contains SQL keywords constructors defined as
|
||||
OverloadedString literals and helper functions to concate these.
|
||||
@ -8,11 +8,16 @@ license: BSD3
|
||||
license-file: LICENSE
|
||||
author: Kei Hibino
|
||||
maintainer: ex8k.hibino@gmail.com
|
||||
copyright: Copyright (c) 2013-2020 Kei Hibino
|
||||
copyright: Copyright (c) 2013-2023 Kei Hibino
|
||||
category: Database
|
||||
build-type: Simple
|
||||
cabal-version: >=1.10
|
||||
tested-with: GHC == 8.8.1, GHC == 8.8.2
|
||||
tested-with: GHC == 9.6.2
|
||||
, GHC == 9.4.6
|
||||
, GHC == 9.2.8
|
||||
, GHC == 9.0.2
|
||||
, GHC == 8.10.7
|
||||
, GHC == 8.8.1, GHC == 8.8.2
|
||||
, GHC == 8.6.1, GHC == 8.6.2, GHC == 8.6.3, GHC == 8.6.4, GHC == 8.6.5
|
||||
, GHC == 8.4.1, GHC == 8.4.2, GHC == 8.4.3, GHC == 8.4.4
|
||||
, GHC == 8.2.1, GHC == 8.2.2
|
||||
|
@ -10,11 +10,16 @@ license: BSD3
|
||||
license-file: LICENSE
|
||||
author: Kei Hibino
|
||||
maintainer: ex8k.hibino@gmail.com
|
||||
copyright: Copyright (c) 2015-2020 Kei Hibino
|
||||
copyright: Copyright (c) 2015-2023 Kei Hibino
|
||||
category: Database
|
||||
build-type: Simple
|
||||
cabal-version: >=1.10
|
||||
tested-with: GHC == 8.8.1, GHC == 8.8.2
|
||||
tested-with: GHC == 9.6.2
|
||||
, GHC == 9.4.6
|
||||
, GHC == 9.2.8
|
||||
, GHC == 9.0.2
|
||||
, GHC == 8.10.7
|
||||
, GHC == 8.8.1, GHC == 8.8.2
|
||||
, GHC == 8.6.1, GHC == 8.6.2, GHC == 8.6.3, GHC == 8.6.4, GHC == 8.6.5
|
||||
, GHC == 8.4.1, GHC == 8.4.2, GHC == 8.4.3, GHC == 8.4.4
|
||||
, GHC == 8.2.1, GHC == 8.2.2
|
||||
|
Loading…
Reference in New Issue
Block a user