Rename functions which expand relation into SQL string.

This commit is contained in:
Kei Hibino 2013-05-23 17:10:23 +09:00
parent 04c0848370
commit 9a3e990459
3 changed files with 13 additions and 13 deletions

View File

@ -15,9 +15,9 @@ module Database.Relational.Query.Join (
inner', left', right', full', inner', left', right', full',
inner, left, right, full, inner, left, right, full,
toSQL, sqlFromRelation,
toSubQuery, subQueryFromRelation,
nested, width nested, width
) where ) where
@ -250,22 +250,22 @@ full = join queryMaybe queryMaybe
infix 8 `inner'`, `left'`, `right'`, `full'`, `inner`, `left`, `right`, `full` infix 8 `inner'`, `left'`, `right'`, `full'`, `inner`, `left`, `right`, `full`
toSQL :: PrimeRelation p r -> String sqlFromRelation :: PrimeRelation p r -> String
toSQL = d where sqlFromRelation = d where
d (SubQuery sub) = SubQuery.toSQL sub d (SubQuery sub) = SubQuery.toSQL sub
d (PrimeRelation qp) = uncurry composeSQL (runQueryPrime qp) d (PrimeRelation qp) = uncurry composeSQL (runQueryPrime qp)
instance Show (PrimeRelation p r) where instance Show (PrimeRelation p r) where
show = toSQL show = sqlFromRelation
toSubQuery :: PrimeRelation p r -> SubQuery subQueryFromRelation :: PrimeRelation p r -> SubQuery
toSubQuery = d where subQueryFromRelation = d where
d (SubQuery sub) = sub d (SubQuery sub) = sub
d (PrimeRelation qp) = SubQuery.subQuery (composeSQL pj c) (Projection.width pj) where d (PrimeRelation qp) = SubQuery.subQuery (composeSQL pj c) (Projection.width pj) where
(pj, c) = runQueryPrime qp (pj, c) = runQueryPrime qp
width :: PrimeRelation p r -> Int width :: PrimeRelation p r -> Int
width = SubQuery.width . toSubQuery width = SubQuery.width . subQueryFromRelation
nested :: PrimeRelation p r -> PrimeRelation p r nested :: PrimeRelation p r -> PrimeRelation p r
nested = SubQuery . toSubQuery nested = SubQuery . subQueryFromRelation

View File

@ -49,7 +49,7 @@ import Database.Record.TH
import Database.Relational.Query import Database.Relational.Query
(Table, Pi, Relation, PrimeRelation, (Table, Pi, Relation, PrimeRelation,
toSQL, Query, fromRelation, Update, Insert, typedInsert, sqlFromRelation, Query, fromRelation, Update, Insert, typedInsert,
HasConstraintKey(constraintKey), projectionKey, Primary, NotNull) HasConstraintKey(constraintKey), projectionKey, Primary, NotNull)
import qualified Database.Relational.Query as Query import qualified Database.Relational.Query as Query
@ -293,6 +293,6 @@ inlineQuery relVar' rel qVar' = do
| prn == ''PrimeRelation -> do | prn == ''PrimeRelation -> do
simpleValD qVar simpleValD qVar
[t| Query $(return p) $(return r) |] [t| Query $(return p) $(return r) |]
[| unsafeTypedQuery $(stringE . toSQL $ rel) |] [| unsafeTypedQuery $(stringE . sqlFromRelation $ rel) |]
_ -> _ ->
compileError $ "expandRelation: Variable must have PrimeRelation type: " ++ show relVar compileError $ "expandRelation: Variable must have PrimeRelation type: " ++ show relVar

View File

@ -6,7 +6,7 @@ module Database.Relational.Query.Type (
Insert(untypeInsert), unsafeTypedInsert, typedInsert Insert(untypeInsert), unsafeTypedInsert, typedInsert
) where ) where
import Database.Relational.Query.Join (PrimeRelation, toSQL) import Database.Relational.Query.Join (PrimeRelation, sqlFromRelation)
import Database.Relational.Query.Table (Table) import Database.Relational.Query.Table (Table)
import Database.Relational.Query.SQL (singleKeyUpdateSQL, insertSQL) import Database.Relational.Query.SQL (singleKeyUpdateSQL, insertSQL)
@ -20,7 +20,7 @@ instance Show (Query p a) where
show = untypeQuery show = untypeQuery
fromRelation :: PrimeRelation p r -> Query p r fromRelation :: PrimeRelation p r -> Query p r
fromRelation = unsafeTypedQuery . toSQL fromRelation = unsafeTypedQuery . sqlFromRelation
newtype Update p a = Update { untypeUpdate :: String } newtype Update p a = Update { untypeUpdate :: String }