Added OrderByCase Expression (#14)

This commit is contained in:
FFuchsi 2023-09-26 09:35:25 +02:00 committed by GitHub
parent 3ca61d4d7b
commit 3b1dc9c328
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -559,6 +559,20 @@ func (e *expr) NotIn(values ...interface{}) *expr {
return e.in(" NOT", values...)
}
func (e *expr) OrderByCase(conditions ...interface{}) *expr {
e.expr = "(CASE " + e.expr
for i, condition := range conditions {
e.expr += " WHEN ? THEN ?"
e.args = append(e.args, condition, i+1)
}
e.expr += " ELSE ? END)"
e.args = append(e.args, len(conditions)+1)
return e
}
func (e *expr) OrderAsc() string {
return e.expr + " ASC "
}