Supports coalesce sorting

Updated parse sorting method to support coalesce sorting with multiple columns, by extending the current sortExpr with modifier and multiple columns, IE. `coalesce` as modifier and given arguments will be multiple columns for the sortExpr.

Also, updated cursor to support modifier and multiple column support along with rdbms.go.tpl for the same.
This commit is contained in:
Vivek Patel
2022-12-01 10:45:26 +01:00
committed by Jože Fortun
parent 1bba89a910
commit 79dc5b9a70
9 changed files with 1451 additions and 432 deletions
@@ -10,6 +10,7 @@ import (
"github.com/doug-martin/goqu/v9"
"github.com/doug-martin/goqu/v9/exp"
"github.com/modern-go/reflect2"
"github.com/cortezaproject/corteza/server/pkg/errors"
"github.com/cortezaproject/corteza/server/pkg/filter"
"github.com/cortezaproject/corteza/server/store"
@@ -551,19 +552,35 @@ func (s *Store) {{ .fnIdent }}(res *{{ .goType }}, cc ...*filter.SortExpr) *filt
{{- end }}
collect = func(cc ...*filter.SortExpr) {
for _, c := range cc {
switch c.Column {
getVal := func(col string) interface{} {
switch col {
{{- range .fields }}
case {{ printf "%q" .ident }}:
cur.Set(c.Column, res.{{ .expIdent }}, c.Descending)
{{- if .primaryKey }}
pk{{ .expIdent }} = true
{{- else if .unique }}
hasUnique = true
{{- end }}
pk{{ .expIdent }} = true
{{- else if .unique }}
hasUnique = true
{{- end }}
return res.{{ .expIdent }}
{{- end }}
}
return nil
}
for _, c := range cc {
switch c.Modifier() {
case filter.COALESCE:
var val interface{}
for _, col := range c.Columns() {
if reflect2.IsNil(val) {
val = getVal(col)
}
}
cur.SetModifier(c.Column, val, c.Descending, c.Modifier(), c.Columns()...)
default:
cur.Set(c.Column, getVal(c.Column), c.Descending)
}
}
}
)