refactor: reduced code duplication
This commit is contained in:
parent
56a148b316
commit
2c94bb4e0a
@ -205,13 +205,7 @@ func Concat(stmts ...interface{}) *expr {
|
|||||||
e.expr += ", "
|
e.expr += ", "
|
||||||
}
|
}
|
||||||
|
|
||||||
if exp, ok := stmt.(*expr); ok {
|
addStatementToExpression(e, stmt)
|
||||||
e.expr += exp.expr
|
|
||||||
e.args = append(e.args, exp.args...)
|
|
||||||
} else {
|
|
||||||
e.expr += "?"
|
|
||||||
e.args = append(e.args, stmt)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
e.expr += ")"
|
e.expr += ")"
|
||||||
@ -384,30 +378,24 @@ func (db *DB) TimestampDiffExpr(unit TimeUnit, timestamp1 interface{}, timestamp
|
|||||||
|
|
||||||
}
|
}
|
||||||
e.expr += unit.String(dialect) + ","
|
e.expr += unit.String(dialect) + ","
|
||||||
|
addStatementToExpression(e, timestamp1)
|
||||||
if exp, ok := timestamp1.(*expr); ok {
|
|
||||||
e.expr += exp.expr
|
|
||||||
e.args = append(e.args, exp.args...)
|
|
||||||
} else {
|
|
||||||
e.expr += "?"
|
|
||||||
e.args = append(e.args, timestamp1)
|
|
||||||
}
|
|
||||||
|
|
||||||
e.expr += ","
|
e.expr += ","
|
||||||
|
addStatementToExpression(e, timestamp2)
|
||||||
if exp, ok := timestamp2.(*expr); ok {
|
|
||||||
e.expr += exp.expr
|
|
||||||
e.args = append(e.args, exp.args...)
|
|
||||||
} else {
|
|
||||||
e.expr += "?"
|
|
||||||
e.args = append(e.args, timestamp2)
|
|
||||||
}
|
|
||||||
|
|
||||||
e.expr += ")"
|
e.expr += ")"
|
||||||
|
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addStatementToExpression(e *expr, stm interface{}) {
|
||||||
|
if exp, ok := stm.(*expr); ok {
|
||||||
|
e.expr += exp.expr
|
||||||
|
e.args = append(e.args, exp.args...)
|
||||||
|
} else {
|
||||||
|
e.expr += "?"
|
||||||
|
e.args = append(e.args, stm)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (db *DB) TimestampDiff(unit TimeUnit, timestamp1 interface{}, timestamp2 interface{}) string {
|
func (db *DB) TimestampDiff(unit TimeUnit, timestamp1 interface{}, timestamp2 interface{}) string {
|
||||||
return db.TimestampDiffExpr(unit, timestamp1, timestamp2).expr
|
return db.TimestampDiffExpr(unit, timestamp1, timestamp2).expr
|
||||||
}
|
}
|
||||||
@ -420,13 +408,7 @@ func (db *DB) CoalesceExpr(stmts ...interface{}) *expr {
|
|||||||
e.expr += ", "
|
e.expr += ", "
|
||||||
}
|
}
|
||||||
|
|
||||||
if exp, ok := stmt.(*expr); ok {
|
addStatementToExpression(e, stmt)
|
||||||
e.expr += exp.expr
|
|
||||||
e.args = append(e.args, exp.args...)
|
|
||||||
} else {
|
|
||||||
e.expr += "?"
|
|
||||||
e.args = append(e.args, stmt)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
e.expr += ")"
|
e.expr += ")"
|
||||||
@ -443,13 +425,7 @@ func Order(stmts ...interface{}) *expr {
|
|||||||
if i != 0 {
|
if i != 0 {
|
||||||
e.expr += ", "
|
e.expr += ", "
|
||||||
}
|
}
|
||||||
if exp, ok := stmt.(*expr); ok {
|
addStatementToExpression(e, stmt)
|
||||||
e.expr += exp.expr
|
|
||||||
e.args = append(e.args, exp.args...)
|
|
||||||
} else {
|
|
||||||
e.expr += "?"
|
|
||||||
e.args = append(e.args, stmt)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user