mirror of
https://github.com/khibino/haskell-relational-record.git
synced 2024-12-12 12:09:08 +03:00
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:
parent
1722d50d25
commit
01867542ac
@ -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
|
||||||
|
|
||||||
|
@ -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)
|
|
||||||
|
@ -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
|
|
@ -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)
|
@ -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)
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
|
||||||
|
@ -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))
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user