Avoid unnecessary double wrapping of SELECT statement when used as single function parameter.
This commit is contained in:
parent
22b2901336
commit
d197956271
16 changed files with 97 additions and 77 deletions
|
|
@ -375,9 +375,14 @@ type wrap struct {
|
|||
expressions []Expression
|
||||
}
|
||||
|
||||
func (n *wrap) serialize(statement StatementType, out *SQLBuilder, options ...SerializeOption) {
|
||||
func (n *wrap) serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption) {
|
||||
out.WriteString("(")
|
||||
serializeExpressionList(statement, n.expressions, ", ", out)
|
||||
|
||||
if len(n.expressions) == 1 {
|
||||
options = append(options, NoWrap, Ident)
|
||||
}
|
||||
serializeExpressionList(statementType, n.expressions, ", ", out, options...)
|
||||
|
||||
out.WriteString(")")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,10 @@ type SerializeOption int
|
|||
const (
|
||||
NoWrap SerializeOption = iota
|
||||
SkipNewLine
|
||||
Ident
|
||||
|
||||
fallTroughOptions // fall trough options
|
||||
|
||||
ShortName
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -195,10 +195,19 @@ func (s *statementImpl) serialize(statement StatementType, out *SQLBuilder, opti
|
|||
out.IncreaseIdent()
|
||||
}
|
||||
|
||||
if contains(options, Ident) {
|
||||
out.IncreaseIdent()
|
||||
}
|
||||
|
||||
for _, clause := range s.Clauses {
|
||||
clause.Serialize(statement, out, FallTrough(options)...)
|
||||
}
|
||||
|
||||
if contains(options, Ident) {
|
||||
out.DecreaseIdent()
|
||||
out.NewLine()
|
||||
}
|
||||
|
||||
if !contains(options, NoWrap) {
|
||||
out.DecreaseIdent()
|
||||
out.NewLine()
|
||||
|
|
|
|||
|
|
@ -21,14 +21,19 @@ func SerializeClauseList(statement StatementType, clauses []Serializer, out *SQL
|
|||
}
|
||||
}
|
||||
|
||||
func serializeExpressionList(statement StatementType, expressions []Expression, separator string, out *SQLBuilder) {
|
||||
func serializeExpressionList(
|
||||
statement StatementType,
|
||||
expressions []Expression,
|
||||
separator string,
|
||||
out *SQLBuilder,
|
||||
options ...SerializeOption) {
|
||||
|
||||
for i, value := range expressions {
|
||||
for i, expression := range expressions {
|
||||
if i > 0 {
|
||||
out.WriteString(separator)
|
||||
}
|
||||
|
||||
value.serialize(statement, out)
|
||||
expression.serialize(statement, out, options...)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue