Update document for Qualified type in SubQuery module.

This commit is contained in:
Kei Hibino 2013-06-06 11:01:29 +09:00
parent 83eda8f7ad
commit e190e0192e

View File

@ -67,32 +67,40 @@ unitSQL = fst . toSQLs
toSQL :: SubQuery -> String toSQL :: SubQuery -> String
toSQL = snd . toSQLs toSQL = snd . toSQLs
-- | Qualifier type.
newtype Qualifier = Qualifier Int newtype Qualifier = Qualifier Int
-- | Qualified query.
data Qualified a = Qualified a Qualifier data Qualified a = Qualified a Qualifier
-- | 'Functor' instance of 'Qualified' -- | 'Functor' instance of 'Qualified'
instance Functor Qualified where instance Functor Qualified where
fmap f (Qualified a i) = Qualified (f a) i fmap f (Qualified a i) = Qualified (f a) i
-- | Get qualifier
qualifier :: Qualified a -> Qualifier qualifier :: Qualified a -> Qualifier
qualifier (Qualified _ i) = i qualifier (Qualified _ i) = i
-- | Unqualify.
unQualify :: Qualified a -> a unQualify :: Qualified a -> a
unQualify (Qualified a _) = a unQualify (Qualified a _) = a
-- | Add qualifier
qualify :: a -> Qualifier -> Qualified a qualify :: a -> Qualifier -> Qualified a
qualify = Qualified qualify = Qualified
columnN :: Int -> String columnN :: Int -> String
columnN i = 'f' : show i columnN i = 'f' : show i
-- | Alias string from qualifier
showQualifier :: Qualifier -> String showQualifier :: Qualifier -> String
showQualifier (Qualifier i) = 'T' : show i showQualifier (Qualifier i) = 'T' : show i
-- | Binary operator to qualify.
(<.>) :: Qualifier -> String -> String (<.>) :: Qualifier -> String -> String
i <.> n = showQualifier i ++ '.' : n i <.> n = showQualifier i ++ '.' : n
-- | Qualified expression from qualifier and projection index.
columnFromId :: Qualifier -> Int -> String columnFromId :: Qualifier -> Int -> String
columnFromId qi i = qi <.> columnN i columnFromId qi i = qi <.> columnN i