Move AliasId module into internal namespace.

--HG--
rename : relational-join/src/Database/Relational/Query/AliasId.hs => relational-join/src/Database/Relational/Query/Internal/AliasId.hs
This commit is contained in:
Kei Hibino 2013-05-21 17:15:51 +09:00
parent 1722d50d25
commit 01867542ac
7 changed files with 67 additions and 66 deletions

View File

@ -17,7 +17,6 @@ library
exposed-modules: exposed-modules:
Database.Relational.Query Database.Relational.Query
Database.Relational.Query.AliasId Database.Relational.Query.AliasId
Database.Relational.Query.AliasId.Unsafe
Database.Relational.Query.Table Database.Relational.Query.Table
Database.Relational.Query.SQL Database.Relational.Query.SQL
Database.Relational.Query.Pi Database.Relational.Query.Pi
@ -42,6 +41,7 @@ library
Database.Relational.Schema.PostgreSQL Database.Relational.Schema.PostgreSQL
other-modules: other-modules:
Database.Relational.Query.Internal.AliasId
Database.Relational.Query.Internal.Product Database.Relational.Query.Internal.Product
Database.Relational.Query.Internal.Context Database.Relational.Query.Internal.Context

View File

@ -1,53 +1,5 @@
module Database.Relational.Query.AliasId ( module Database.Relational.Query.AliasId (
AliasId, newAliasId, Qualified
columnN, aliasName, (<.>), columnFromId,
asColumnN,
Qualified, unQualify, qualifyAlias, qualify,
qualifiedSQLas
) where ) where
import qualified Language.SQL.Keyword as SQL import Database.Relational.Query.Internal.AliasId (Qualified)
import qualified Language.SQL.Keyword.ConcatString as SQLs
import Database.Relational.Query.AliasId.Unsafe (AliasId(AliasId))
newAliasId :: AliasId -> AliasId
newAliasId (AliasId i) = AliasId $ i + 1
columnN :: Int -> String
columnN i = 'f' : show i
aliasName :: AliasId -> String
aliasName (AliasId i) = 'T' : show i
(<.>) :: String -> String -> String
t <.> n = t ++ '.' : n
columnFromId :: AliasId -> Int -> String
columnFromId a i = aliasName a <.> columnN i
asColumnN :: SQL.Keyword -> Int -> SQL.Keyword
f `asColumnN` n = f `SQL.as` SQL.word (columnN n)
-- | Qualified relaltion by alias id
data Qualified fr =
Qualified
{ unQualify :: fr
, qualifyAlias :: !AliasId
}
qualify :: fr -> AliasId -> Qualified fr
qualify = Qualified
instance Functor Qualified where
fmap f (Qualified a i) = Qualified (f a) i
qualifiedSQLas :: Qualified String -> String
qualifiedSQLas q =
unQualify q
`SQLs.as`
(aliasName $ qualifyAlias q)

View File

@ -1,9 +0,0 @@
module Database.Relational.Query.AliasId.Unsafe (
AliasId (AliasId), primAlias
) where
newtype AliasId = AliasId Int deriving (Show, Eq)
primAlias :: AliasId
primAlias = AliasId 0

View File

@ -0,0 +1,59 @@
module Database.Relational.Query.Internal.AliasId (
AliasId (AliasId), primAlias, newAliasId,
columnN, aliasName, (<.>), columnFromId,
asColumnN,
Qualified, unQualify, qualifyAlias, qualify,
qualifiedSQLas
) where
import qualified Language.SQL.Keyword as SQL
import qualified Language.SQL.Keyword.ConcatString as SQLs
newtype AliasId = AliasId Int deriving (Show, Eq)
primAlias :: AliasId
primAlias = AliasId 0
newAliasId :: AliasId -> AliasId
newAliasId (AliasId i) = AliasId $ i + 1
columnN :: Int -> String
columnN i = 'f' : show i
aliasName :: AliasId -> String
aliasName (AliasId i) = 'T' : show i
(<.>) :: String -> String -> String
t <.> n = t ++ '.' : n
columnFromId :: AliasId -> Int -> String
columnFromId a i = aliasName a <.> columnN i
asColumnN :: SQL.Keyword -> Int -> SQL.Keyword
f `asColumnN` n = f `SQL.as` SQL.word (columnN n)
-- | Qualified relaltion by alias id
data Qualified fr =
Qualified
{ unQualify :: fr
, qualifyAlias :: !AliasId
}
qualify :: fr -> AliasId -> Qualified fr
qualify = Qualified
instance Functor Qualified where
fmap f (Qualified a i) = Qualified (f a) i
qualifiedSQLas :: Qualified String -> String
qualifiedSQLas q =
unQualify q
`SQLs.as`
(aliasName $ qualifyAlias q)

View File

@ -16,8 +16,7 @@ module Database.Relational.Query.Internal.Context (
import Prelude hiding (product) import Prelude hiding (product)
import Data.List (foldl') import Data.List (foldl')
import Database.Relational.Query.AliasId.Unsafe (primAlias) import Database.Relational.Query.Internal.AliasId (primAlias, AliasId, newAliasId, asColumnN)
import Database.Relational.Query.AliasId (AliasId, newAliasId, asColumnN)
import Database.Relational.Query.Expr (Expr, showExpr) import Database.Relational.Query.Expr (Expr, showExpr)

View File

@ -27,8 +27,8 @@ import Database.Relational.Query.Internal.Context
(Context, Order(Asc, Desc), primContext, nextAlias, updateProduct, composeSQL) (Context, Order(Asc, Desc), primContext, nextAlias, updateProduct, composeSQL)
import qualified Database.Relational.Query.Internal.Context as Context import qualified Database.Relational.Query.Internal.Context as Context
import Database.Relational.Query.AliasId (AliasId, Qualified) import Database.Relational.Query.Internal.AliasId (AliasId, Qualified)
import qualified Database.Relational.Query.AliasId as AliasId import qualified Database.Relational.Query.Internal.AliasId as AliasId
import Database.Relational.Query.Table (Table) import Database.Relational.Query.Table (Table)

View File

@ -9,10 +9,10 @@ module Database.Relational.Query.Sub (
import Database.Relational.Query.Table (Table, (!)) import Database.Relational.Query.Table (Table, (!))
import qualified Database.Relational.Query.Table as Table import qualified Database.Relational.Query.Table as Table
import Database.Relational.Query.AliasId import Database.Relational.Query.Internal.AliasId
(aliasName, (<.>), (aliasName, (<.>),
Qualified, unQualify, qualifyAlias, qualifiedSQLas) Qualified, unQualify, qualifyAlias, qualifiedSQLas)
import qualified Database.Relational.Query.AliasId as AliasId import qualified Database.Relational.Query.Internal.AliasId as AliasId
import Database.Relational.Query.Expr.Unsafe (Expr(Expr)) import Database.Relational.Query.Expr.Unsafe (Expr(Expr))