Fix Postgres timestamp sort inconsistencies
This commit is contained in:
parent
a56b825528
commit
36faf60b93
@ -63,6 +63,8 @@ type (
|
||||
// comparison or soring expression
|
||||
AttributeCast(*dal.Attribute, exp.Expression) (exp.Expression, error)
|
||||
|
||||
AttributeExpression(attr *dal.Attribute, modelIdent string, ident string) (expr exp.Expression, err error)
|
||||
|
||||
// TableCodec returns table codec (encodes & decodes data to/from db table)
|
||||
TableCodec(*dal.Model) TableCodec
|
||||
|
||||
|
||||
@ -162,6 +162,10 @@ func (mssqlDialect) AttributeCast(attr *dal.Attribute, val exp.Expression) (expr
|
||||
return
|
||||
}
|
||||
|
||||
func (mssqlDialect) AttributeExpression(attr *dal.Attribute, modelIdent string, ident string) (expr exp.Expression, err error) {
|
||||
return exp.NewLiteralExpression("?", exp.NewIdentifierExpression("", modelIdent, ident)), nil
|
||||
}
|
||||
|
||||
func (mssqlDialect) AttributeToColumn(attr *dal.Attribute) (col *ddl.Column, err error) {
|
||||
col = &ddl.Column{
|
||||
Ident: attr.StoreIdent(),
|
||||
|
||||
@ -162,6 +162,10 @@ func (mysqlDialect) AttributeCast(attr *dal.Attribute, val exp.Expression) (exp.
|
||||
return exp.NewLiteralExpression("?", c), nil
|
||||
}
|
||||
|
||||
func (mysqlDialect) AttributeExpression(attr *dal.Attribute, modelIdent string, ident string) (expr exp.Expression, err error) {
|
||||
return exp.NewLiteralExpression("?", exp.NewIdentifierExpression("", modelIdent, ident)), nil
|
||||
}
|
||||
|
||||
func (mysqlDialect) AttributeToColumn(attr *dal.Attribute) (col *ddl.Column, err error) {
|
||||
col = &ddl.Column{
|
||||
Ident: attr.StoreIdent(),
|
||||
|
||||
@ -107,6 +107,18 @@ func (postgresDialect) AttributeCast(attr *dal.Attribute, val exp.Expression) (e
|
||||
return
|
||||
}
|
||||
|
||||
func (postgresDialect) AttributeExpression(attr *dal.Attribute, modelIdent string, ident string) (expr exp.Expression, err error) {
|
||||
identExpr := exp.NewIdentifierExpression("", modelIdent, ident)
|
||||
|
||||
// truncate timestamp data type to second mark precision
|
||||
if attr.Type.Type() == dal.AttributeTypeTimestamp {
|
||||
return exp.NewLiteralExpression("date_trunc(?, ?)", "second", identExpr), nil
|
||||
}
|
||||
|
||||
// using column directly
|
||||
return exp.NewLiteralExpression("?", identExpr), nil
|
||||
}
|
||||
|
||||
func (postgresDialect) AttributeToColumn(attr *dal.Attribute) (col *ddl.Column, err error) {
|
||||
col = &ddl.Column{
|
||||
Ident: attr.StoreIdent(),
|
||||
|
||||
@ -147,6 +147,10 @@ func (sqliteDialect) AttributeCast(attr *dal.Attribute, val exp.Expression) (exp
|
||||
|
||||
}
|
||||
|
||||
func (sqliteDialect) AttributeExpression(attr *dal.Attribute, modelIdent string, ident string) (expr exp.Expression, err error) {
|
||||
return exp.NewLiteralExpression("?", exp.NewIdentifierExpression("", modelIdent, ident)), nil
|
||||
}
|
||||
|
||||
func (sqliteDialect) AttributeToColumn(attr *dal.Attribute) (col *ddl.Column, err error) {
|
||||
|
||||
col = &ddl.Column{
|
||||
|
||||
@ -2,7 +2,6 @@ package drivers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/dal"
|
||||
"github.com/doug-martin/goqu/v9/exp"
|
||||
)
|
||||
@ -132,8 +131,7 @@ func (t *GenericTableCodec) AttributeExpression(ident string) (exp.Expression, e
|
||||
|
||||
switch s := attr.Store.(type) {
|
||||
case *dal.CodecAlias:
|
||||
// using column directly
|
||||
return exp.NewLiteralExpression("?", exp.NewIdentifierExpression("", t.model.Ident, s.Ident)), nil
|
||||
return t.dialect.AttributeExpression(attr, t.model.Ident, s.Ident)
|
||||
|
||||
case *dal.CodecRecordValueSetJSON:
|
||||
// using JSON to handle embedded values
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user