From 7824af3a781729f76235bf39a8effc7bf7d54947 Mon Sep 17 00:00:00 2001 From: Kei Hibino Date: Wed, 8 May 2013 17:42:14 +0900 Subject: [PATCH] Move default definitions of column selector. --- .../src/Database/Relational/Query/TH.hs | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/relational-join/src/Database/Relational/Query/TH.hs b/relational-join/src/Database/Relational/Query/TH.hs index 4210ea7b..1610df3e 100644 --- a/relational-join/src/Database/Relational/Query/TH.hs +++ b/relational-join/src/Database/Relational/Query/TH.hs @@ -60,24 +60,26 @@ defineTable tableVar' relVar' recordType table columns = do let tableVar = varName tableVar' tableDs <- simpleValD tableVar [t| Table $(recordType) |] [| Table.table $(stringE table) $(listE $ map stringE (map fst columns)) |] - let defCol i (name, typ) = defineColumnDefault recordType name i typ - colsDs <- fmap concat . sequence . zipWith defCol [0..] $ columns let relVar = varName relVar' relDs <- simpleValD relVar [t| Relation $(recordType) |] [| fromTable $(varE tableVar) |] - return $ tableDs ++ colsDs ++ relDs + return $ tableDs ++ relDs defineTableDefault :: String -- ^ Schema name -> String -- ^ Table name -> [(String, TypeQ)] -- ^ Column names and types -> Q [Dec] -- ^ Result declarations -defineTableDefault schema table columns = - defineTable - (table `varNameWithPrefix` "tableOf") - (varCamelcaseName table) - (recordTypeDefault table) - (tableSQL schema table) - columns +defineTableDefault schema table columns = do + let recordType = recordTypeDefault table + tableDs <- defineTable + (table `varNameWithPrefix` "tableOf") + (varCamelcaseName table) + recordType + (tableSQL schema table) + columns + let defCol i (name, typ) = defineColumnDefault recordType name i typ + colsDs <- fmap concat . sequence . zipWith defCol [0..] $ columns + return $ tableDs ++ colsDs defineRecordAndTableDefault :: TypeQ -- ^ SQL value type -> String -- ^ Schema name