Skip to content

Instantly share code, notes, and snippets.

@yuga

yuga/exmaples.hs

Last active Aug 29, 2015
Embed
What would you like to do?
追加しようと思うexample
account1'' :: Relation () Account1
account1'' = relation $ do
a <- query account
wheres $ a ! Account.productCd' `in'` values ["CHK", "SAV", "CD", "MM"]
return $ Account1 |$| a ! Account.accountId'
|*| a ! Account.productCd'
|*| a ! Account.custId'
|*| a ! Account.availBalance'
data Account1 = Account1
{ a1AccountId :: Int64
, a1ProductCd :: String
, a1CustId :: Int64
, a1AvailBalance :: Maybe Double
} deriving (Show)
$(makeRecordPersistableDefault ''Account1)
-- | sql/4.3.3b.sh
--
-- @
-- SELECT account_id, product_cd, cust_id, avail_balance
-- FROM account
-- WHERE product_cd IN (SELECT product_cd FROM product
-- WHERE product_type_cd = 'ACCOUNT')
-- @
productSubQuery :: Relation String String
productSubQuery = relation' $ do
p <- query product
(phProductCd,()) <- placeholder (\ph -> wheres $ p ! Product.productTypeCd' .=. ph)
let productCd = p ! Product.productCd'
return (phProductCd, productCd)
account1b :: Relation String Account
account1b = relation' $ do
a <- query account
(phProductCd,p) <- queryList' productSubQuery
wheres $ a ! Account.productCd' `in'` p
return (phProductCd, a)
account1b' :: Relation String (((Int64, String), Int64), Maybe Double)
account1b' = undefined
account1b'' :: Relation String Account
account1b'' = undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment