3
0

Fix Postgres timestamp sort inconsistencies

This commit is contained in:
Mumbi Francis 2024-07-01 15:33:24 +03:00 committed by Mumbi Francis
parent a56b825528
commit 36faf60b93
6 changed files with 43 additions and 19 deletions

View File

@ -63,6 +63,8 @@ type (
// comparison or soring expression // comparison or soring expression
AttributeCast(*dal.Attribute, exp.Expression) (exp.Expression, error) 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 returns table codec (encodes & decodes data to/from db table)
TableCodec(*dal.Model) TableCodec TableCodec(*dal.Model) TableCodec

View File

@ -162,6 +162,10 @@ func (mssqlDialect) AttributeCast(attr *dal.Attribute, val exp.Expression) (expr
return 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) { func (mssqlDialect) AttributeToColumn(attr *dal.Attribute) (col *ddl.Column, err error) {
col = &ddl.Column{ col = &ddl.Column{
Ident: attr.StoreIdent(), Ident: attr.StoreIdent(),

View File

@ -162,6 +162,10 @@ func (mysqlDialect) AttributeCast(attr *dal.Attribute, val exp.Expression) (exp.
return exp.NewLiteralExpression("?", c), nil 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) { func (mysqlDialect) AttributeToColumn(attr *dal.Attribute) (col *ddl.Column, err error) {
col = &ddl.Column{ col = &ddl.Column{
Ident: attr.StoreIdent(), Ident: attr.StoreIdent(),

View File

@ -107,6 +107,18 @@ func (postgresDialect) AttributeCast(attr *dal.Attribute, val exp.Expression) (e
return 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) { func (postgresDialect) AttributeToColumn(attr *dal.Attribute) (col *ddl.Column, err error) {
col = &ddl.Column{ col = &ddl.Column{
Ident: attr.StoreIdent(), Ident: attr.StoreIdent(),

View File

@ -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) { func (sqliteDialect) AttributeToColumn(attr *dal.Attribute) (col *ddl.Column, err error) {
col = &ddl.Column{ col = &ddl.Column{

View File

@ -2,7 +2,6 @@ package drivers
import ( import (
"fmt" "fmt"
"github.com/cortezaproject/corteza/server/pkg/dal" "github.com/cortezaproject/corteza/server/pkg/dal"
"github.com/doug-martin/goqu/v9/exp" "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) { switch s := attr.Store.(type) {
case *dal.CodecAlias: case *dal.CodecAlias:
// using column directly return t.dialect.AttributeExpression(attr, t.model.Ident, s.Ident)
return exp.NewLiteralExpression("?", exp.NewIdentifierExpression("", t.model.Ident, s.Ident)), nil
case *dal.CodecRecordValueSetJSON: case *dal.CodecRecordValueSetJSON:
// using JSON to handle embedded values // using JSON to handle embedded values