Add alias for db type in db package

This commit is contained in:
kolaente 2020-12-23 01:38:30 +01:00
parent 4dce70ac0a
commit c3c7cab045
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 9 additions and 2 deletions

View File

@ -24,6 +24,7 @@ import (
"strconv"
"strings"
"time"
"xorm.io/xorm/schemas"
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/log"
@ -216,3 +217,8 @@ func WipeEverything() error {
func NewSession() *xorm.Session {
return x.NewSession()
}
// Type returns the db type of the currently configured db
func Type() schemas.DBType {
return x.Dialect().URI().DBType
}

View File

@ -67,7 +67,7 @@ func TestSavedFilter_Create(t *testing.T) {
"owner_id": 1,
}
// Postgres can't compare json values directly, see https://dba.stackexchange.com/a/106290/210721
if x.Dialect().URI().DBType == schemas.POSTGRES {
if db.Type() == schemas.POSTGRES {
vals["filters::jsonb"] = vals["filters"].(string) + "::jsonb"
delete(vals, "filters")
}

View File

@ -17,6 +17,7 @@
package models
import (
"code.vikunja.io/api/pkg/db"
"math"
"sort"
"strconv"
@ -253,7 +254,7 @@ func getRawTasksForLists(s *xorm.Session, lists []*List, a web.Auth, opts *taskO
// Postgres sorts by default entries with null values after ones with values.
// To make that consistent with the sort order we have and other dbms, we're adding a separate clause here.
if x.Dialect().URI().DBType == schemas.POSTGRES {
if db.Type() == schemas.POSTGRES {
if param.orderBy == orderAscending {
orderby += " NULLS FIRST"
}