on 0272bcc help sign in
36 lines 768 B history raw
1module Rel8.Statement.Using
2 ( ppFrom
3 , ppUsing
4 )
5where
7-- base
8import Prelude
10-- pretty
11import Text.PrettyPrint ( Doc, (<+>), parens, text )
13-- rel8
14import Rel8.Query ( Query )
15import Rel8.Schema.Table ( TableSchema(..), ppTable )
16import Rel8.Statement.Select ( Optimized(..), ppPrimSelect )
19ppFrom :: Query a -> Maybe (Doc, a)
20ppFrom = ppJoin "FROM"
23ppUsing :: Query a -> Maybe (Doc, a)
24ppUsing = ppJoin "USING"
27ppJoin :: String -> Query a -> Maybe (Doc, a)
28ppJoin clause join = do
29 doc <- case ofrom of
30 Empty -> Nothing
31 Unit -> Just mempty
32 Optimized doc -> Just $ text clause <+> parens doc <+> ppTable alias
33 pure (doc, a)
34 where
35 alias = TableSchema {name = "T1", schema = Nothing, columns = ()}
36 (ofrom, a) = ppPrimSelect join