Skip to content

Commit

Permalink
Remove remove some list appends
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Sasarak committed Jul 2, 2019
1 parent d0615fe commit e9fd568
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/Opaleye/Internal/HaskellDB/Sql/Print.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import Data.List (intersperse)
import qualified Data.List.NonEmpty as NEL
import Data.Text.Prettyprint.Doc ((<+>), (<>), comma, dquotes,
equals, hcat, hsep, parens, punctuate,
vcat, brackets, indent, Pretty(..))
vcat, brackets, indent, pretty, Pretty())
import Data.Foldable (toList)
import Data.Monoid ()

Expand Down Expand Up @@ -94,9 +94,9 @@ ppSqlDistinct :: Sql.SqlDistinct -> Doc
ppSqlDistinct Sql.SqlDistinct = text "DISTINCT"
ppSqlDistinct Sql.SqlNotDistinct = empty

ppAs :: Maybe String -> Doc -> Doc
ppAs :: Maybe Doc -> Doc -> Doc
ppAs Nothing expr = expr
ppAs (Just alias) expr = expr <+> hsep [text "as", doubleQuotes (text alias)]
ppAs (Just alias) expr = expr <+> hsep [text "as", doubleQuotes alias]


ppUpdate :: SqlUpdate -> Doc
Expand Down
10 changes: 5 additions & 5 deletions src/Opaleye/Internal/Print.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import qualified Data.Text as ST
import Data.String ()
import Data.Monoid ()

type TableAlias = String
type TableAlias = HSql.Doc
type Doc = HSql.Doc

-- convenience definitions/aliases
Expand Down Expand Up @@ -115,19 +115,19 @@ ppAttrs :: Sql.SelectAttrs -> Doc
ppAttrs Sql.Star = text "*"
ppAttrs (Sql.SelectAttrs xs) = (HPrint.commaV nameAs . NEL.toList) xs
ppAttrs (Sql.SelectAttrsStar xs) =
HPrint.commaV id ((map nameAs . NEL.toList) xs ++ [text "*"])
(HPrint.commaV id ((map nameAs . NEL.toList) xs)) <> text ",*"

-- This is pretty much just nameAs from HaskellDB
nameAs :: (HSql.SqlExpr, Maybe HSql.SqlColumn) -> Doc
nameAs (expr, name) = HPrint.ppAs (fmap unColumn name) (HPrint.ppSqlExpr expr)
where unColumn (HSql.SqlColumn s) = s
where unColumn (HSql.SqlColumn s) = pretty s

ppTables :: [Select] -> Doc
ppTables [] = empty
ppTables ts = text "FROM" <+> HPrint.commaV ppTable (zipWith tableAlias [1..] ts)

tableAlias :: Int -> Select -> (TableAlias, Select)
tableAlias i select = ("T" ++ show i, select)
tableAlias i select = (text "T" <> pretty i, select)

-- TODO: duplication with ppSql
ppTable :: (TableAlias, Select) -> Doc
Expand All @@ -154,7 +154,7 @@ ppOffset Nothing = empty
ppOffset (Just n) = text "OFFSET " ++ pretty n

ppValues :: [[HSql.SqlExpr]] -> Doc
ppValues v = HPrint.ppAs (Just "V") (parens (text "VALUES" $$ HPrint.commaV ppValuesRow v))
ppValues v = HPrint.ppAs (Just (pretty "V")) (parens (text "VALUES" $$ HPrint.commaV ppValuesRow v))

ppValuesRow :: [HSql.SqlExpr] -> Doc
ppValuesRow = parens . HPrint.commaH HPrint.ppSqlExpr
Expand Down

0 comments on commit e9fd568

Please sign in to comment.