From 01867542acf4403416ef146ec9049089091f9109 Mon Sep 17 00:00:00 2001 From: Kei Hibino Date: Tue, 21 May 2013 17:15:51 +0900 Subject: [PATCH] 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 --- relational-join/relational-join.cabal | 2 +- .../src/Database/Relational/Query/AliasId.hs | 52 +--------------- .../Relational/Query/AliasId/Unsafe.hs | 9 --- .../Relational/Query/Internal/AliasId.hs | 59 +++++++++++++++++++ .../Relational/Query/Internal/Context.hs | 3 +- .../src/Database/Relational/Query/Join.hs | 4 +- .../src/Database/Relational/Query/Sub.hs | 4 +- 7 files changed, 67 insertions(+), 66 deletions(-) delete mode 100644 relational-join/src/Database/Relational/Query/AliasId/Unsafe.hs create mode 100644 relational-join/src/Database/Relational/Query/Internal/AliasId.hs diff --git a/relational-join/relational-join.cabal b/relational-join/relational-join.cabal index 6cfbfdaa..82268689 100644 --- a/relational-join/relational-join.cabal +++ b/relational-join/relational-join.cabal @@ -17,7 +17,6 @@ library exposed-modules: Database.Relational.Query Database.Relational.Query.AliasId - Database.Relational.Query.AliasId.Unsafe Database.Relational.Query.Table Database.Relational.Query.SQL Database.Relational.Query.Pi @@ -42,6 +41,7 @@ library Database.Relational.Schema.PostgreSQL other-modules: + Database.Relational.Query.Internal.AliasId Database.Relational.Query.Internal.Product Database.Relational.Query.Internal.Context diff --git a/relational-join/src/Database/Relational/Query/AliasId.hs b/relational-join/src/Database/Relational/Query/AliasId.hs index 7c5fb074..0f222eef 100644 --- a/relational-join/src/Database/Relational/Query/AliasId.hs +++ b/relational-join/src/Database/Relational/Query/AliasId.hs @@ -1,53 +1,5 @@ - module Database.Relational.Query.AliasId ( - AliasId, newAliasId, - - columnN, aliasName, (<.>), columnFromId, - asColumnN, - - Qualified, unQualify, qualifyAlias, qualify, - - qualifiedSQLas + Qualified ) where -import qualified Language.SQL.Keyword as SQL -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) +import Database.Relational.Query.Internal.AliasId (Qualified) diff --git a/relational-join/src/Database/Relational/Query/AliasId/Unsafe.hs b/relational-join/src/Database/Relational/Query/AliasId/Unsafe.hs deleted file mode 100644 index e4de3894..00000000 --- a/relational-join/src/Database/Relational/Query/AliasId/Unsafe.hs +++ /dev/null @@ -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 diff --git a/relational-join/src/Database/Relational/Query/Internal/AliasId.hs b/relational-join/src/Database/Relational/Query/Internal/AliasId.hs new file mode 100644 index 00000000..df271f09 --- /dev/null +++ b/relational-join/src/Database/Relational/Query/Internal/AliasId.hs @@ -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) diff --git a/relational-join/src/Database/Relational/Query/Internal/Context.hs b/relational-join/src/Database/Relational/Query/Internal/Context.hs index 70adf7f4..d8c0977d 100644 --- a/relational-join/src/Database/Relational/Query/Internal/Context.hs +++ b/relational-join/src/Database/Relational/Query/Internal/Context.hs @@ -16,8 +16,7 @@ module Database.Relational.Query.Internal.Context ( import Prelude hiding (product) import Data.List (foldl') -import Database.Relational.Query.AliasId.Unsafe (primAlias) -import Database.Relational.Query.AliasId (AliasId, newAliasId, asColumnN) +import Database.Relational.Query.Internal.AliasId (primAlias, AliasId, newAliasId, asColumnN) import Database.Relational.Query.Expr (Expr, showExpr) diff --git a/relational-join/src/Database/Relational/Query/Join.hs b/relational-join/src/Database/Relational/Query/Join.hs index d8f6caaf..4214077c 100644 --- a/relational-join/src/Database/Relational/Query/Join.hs +++ b/relational-join/src/Database/Relational/Query/Join.hs @@ -27,8 +27,8 @@ import Database.Relational.Query.Internal.Context (Context, Order(Asc, Desc), primContext, nextAlias, updateProduct, composeSQL) import qualified Database.Relational.Query.Internal.Context as Context -import Database.Relational.Query.AliasId (AliasId, Qualified) -import qualified Database.Relational.Query.AliasId as AliasId +import Database.Relational.Query.Internal.AliasId (AliasId, Qualified) +import qualified Database.Relational.Query.Internal.AliasId as AliasId import Database.Relational.Query.Table (Table) diff --git a/relational-join/src/Database/Relational/Query/Sub.hs b/relational-join/src/Database/Relational/Query/Sub.hs index 4324f04a..874d7f47 100644 --- a/relational-join/src/Database/Relational/Query/Sub.hs +++ b/relational-join/src/Database/Relational/Query/Sub.hs @@ -9,10 +9,10 @@ module Database.Relational.Query.Sub ( import Database.Relational.Query.Table (Table, (!)) import qualified Database.Relational.Query.Table as Table -import Database.Relational.Query.AliasId +import Database.Relational.Query.Internal.AliasId (aliasName, (<.>), 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))