haskell-relational-record/relational-query/test/Model.hs

66 lines
1.6 KiB
Haskell
Raw Normal View History

2015-11-29 15:06:48 +03:00
{-# OPTIONS_GHC -fno-warn-orphans #-}
2014-12-10 19:52:07 +03:00
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
2017-03-16 09:33:37 +03:00
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DataKinds #-}
2014-12-10 19:52:07 +03:00
module Model where
2017-03-16 09:33:37 +03:00
import GHC.Generics (Generic)
2014-12-10 19:52:07 +03:00
import Data.Int (Int32, Int64)
import Database.Relational (defaultConfig)
import Database.Relational.TH (defineTable, makeRelationalRecordDefault, defineScalarDegree)
2014-12-10 19:52:07 +03:00
2016-02-12 14:50:58 +03:00
$(defineTable defaultConfig "TEST" "set_a"
2014-12-10 19:52:07 +03:00
[ ("int_a0" , [t| Int32 |])
, ("str_a1" , [t| String |])
, ("str_a2" , [t| String |]) ]
2017-03-16 09:33:37 +03:00
[''Generic] [0] $ Just 0)
2014-12-10 19:52:07 +03:00
2016-02-12 14:50:58 +03:00
$(defineTable defaultConfig "TEST" "set_b"
2014-12-10 19:52:07 +03:00
[ ("int_b0" , [t| Int32 |])
, ("may_str_b1" , [t| Maybe String |])
, ("str_b2" , [t| String |]) ]
2017-03-16 09:33:37 +03:00
[''Generic] [0] $ Just 0)
2014-12-10 19:52:07 +03:00
2016-02-12 14:50:58 +03:00
$(defineTable defaultConfig "TEST" "set_c"
2014-12-10 19:52:07 +03:00
[ ("int_c0" , [t| Int32 |])
, ("str_c1" , [t| String |])
, ("int_c2" , [t| Int64 |])
, ("may_str_c3" , [t| Maybe String |]) ]
2017-03-16 09:33:37 +03:00
[''Generic] [0] $ Just 0)
2014-12-10 19:52:07 +03:00
2023-04-02 17:24:36 +03:00
-- column name conflict with Conflict.conflictB
$(defineTable defaultConfig "TEST" "conflict_a"
[ ("foo" , [t| String |])
, ("bar" , [t| Int32 |])
, ("baz" , [t| Int32 |]) ]
[''Generic] [0] $ Just 0)
2016-02-12 14:50:58 +03:00
$(defineTable defaultConfig "TEST" "set_i"
[ ("int_i0" , [t| Int32 |]) ]
2017-03-16 09:33:37 +03:00
[''Generic] [0] $ Just 0)
2014-12-10 19:52:07 +03:00
data ABC =
ABC
{ xJustA :: SetA
, xJustB :: SetB
, xJustC :: SetC
2017-03-16 09:33:37 +03:00
} deriving Generic
2014-12-10 19:52:07 +03:00
$(makeRelationalRecordDefault ''ABC)
data Abc =
Abc
{ yJustA :: SetA
, yMayB :: Maybe SetB
, yMayC :: Maybe SetC
2017-03-16 09:33:37 +03:00
} deriving Generic
2014-12-10 19:52:07 +03:00
$(makeRelationalRecordDefault ''Abc)
2015-11-29 15:06:48 +03:00
$(defineScalarDegree [t| Int32 |])