Add support for NULLS_FIRST and NULLS_LAST sorting order.
This commit is contained in:
parent
0fc51cf402
commit
dab153a739
8 changed files with 882 additions and 19 deletions
|
|
@ -26,7 +26,8 @@ func newDialect() jet.Dialect {
|
|||
ArgumentPlaceholder: func(int) string {
|
||||
return "?"
|
||||
},
|
||||
ReservedWords: reservedWords,
|
||||
ReservedWords: reservedWords,
|
||||
SerializeOrderBy: serializeOrderBy,
|
||||
}
|
||||
|
||||
return jet.NewDialect(mySQLDialectParams)
|
||||
|
|
@ -162,6 +163,53 @@ func mysqlNOTREGEXPLIKEoperator(expressions ...jet.Serializer) jet.SerializerFun
|
|||
}
|
||||
}
|
||||
|
||||
func serializeOrderBy(expression Expression, ascending, nullsFirst *bool) jet.SerializerFunc {
|
||||
return func(statement jet.StatementType, out *jet.SQLBuilder, options ...jet.SerializeOption) {
|
||||
|
||||
if nullsFirst == nil {
|
||||
jet.SerializeForOrderBy(expression, statement, out)
|
||||
|
||||
if ascending != nil {
|
||||
serializeAscending(*ascending, out)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
asc := true
|
||||
|
||||
if ascending != nil {
|
||||
asc = *ascending
|
||||
}
|
||||
|
||||
if asc {
|
||||
if !*nullsFirst {
|
||||
jet.SerializeForOrderBy(expression.IS_NULL(), statement, out)
|
||||
out.WriteString(", ")
|
||||
}
|
||||
jet.SerializeForOrderBy(expression, statement, out)
|
||||
if ascending != nil {
|
||||
serializeAscending(asc, out)
|
||||
}
|
||||
} else {
|
||||
if *nullsFirst {
|
||||
jet.SerializeForOrderBy(expression.IS_NOT_NULL(), statement, out)
|
||||
out.WriteString(", ")
|
||||
}
|
||||
|
||||
jet.SerializeForOrderBy(expression, statement, out)
|
||||
serializeAscending(asc, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func serializeAscending(ascending bool, out *jet.SQLBuilder) {
|
||||
if ascending {
|
||||
out.WriteString("ASC")
|
||||
} else {
|
||||
out.WriteString("DESC")
|
||||
}
|
||||
}
|
||||
|
||||
var reservedWords = []string{
|
||||
"ACCESSIBLE",
|
||||
"ADD",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue