Correctly parenthesize and put ON clauses.

This commit is contained in:
Felipe Lessa 2012-09-05 16:47:33 -03:00
parent 8973d650a4
commit c0f5993be7

View File

@ -303,15 +303,16 @@ makeFrom esc fs = ret
where where
ret = case collectOnClauses fs of ret = case collectOnClauses fs of
Left expr -> throw $ mkExc expr Left expr -> throw $ mkExc expr
Right fs' -> first ("\nFROM " <>) $ uncommas' (map mk fs') Right fs' -> first ("\nFROM " <>) $ uncommas' (map (mk False mempty) fs')
mk (FromStart (I i) def) = base i def mk _ onClause (FromStart (I i) def) = base i def <> onClause
mk (FromJoin lhs kind rhs monClause) = mk paren onClause (FromJoin lhs kind rhs monClause) =
mconcat [ mk lhs (if paren then first parens else id) $
mconcat [ mk True onClause lhs
, (fromKind kind, mempty) , (fromKind kind, mempty)
, mk rhs , mk False (maybe mempty makeOnClause monClause) rhs
, maybe mempty makeOnClause monClause ] ]
mk (OnClause _) = error "Esqueleto/Sql/makeFrom: never here (is collectOnClauses working?)" mk _ _ (OnClause _) = error "Esqueleto/Sql/makeFrom: never here (is collectOnClauses working?)"
base i def = (esc (entityDB def) <> (" AS " <> i), mempty) base i def = (esc (entityDB def) <> (" AS " <> i), mempty)