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,7 +63,9 @@ type (
// comparison or soring expression
AttributeCast(*dal.Attribute, exp.Expression) (exp.Expression, error)
// TableCodec returns table codec (encodes & decodes data to/from db table)
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
// TypeWrap returns driver's type implementation for a particular attribute type

View File

@ -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(),

View File

@ -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(),

View File

@ -1,19 +1,19 @@
package postgres
import (
"fmt"
"strings"
"fmt"
"strings"
"github.com/cortezaproject/corteza/server/pkg/dal"
"github.com/cortezaproject/corteza/server/pkg/expr"
"github.com/cortezaproject/corteza/server/store/adapters/rdbms/ddl"
"github.com/cortezaproject/corteza/server/store/adapters/rdbms/drivers"
"github.com/cortezaproject/corteza/server/store/adapters/rdbms/ql"
"github.com/doug-martin/goqu/v9"
"github.com/doug-martin/goqu/v9/dialect/postgres"
"github.com/doug-martin/goqu/v9/exp"
"github.com/doug-martin/goqu/v9/sqlgen"
"github.com/spf13/cast"
"github.com/cortezaproject/corteza/server/pkg/dal"
"github.com/cortezaproject/corteza/server/pkg/expr"
"github.com/cortezaproject/corteza/server/store/adapters/rdbms/ddl"
"github.com/cortezaproject/corteza/server/store/adapters/rdbms/drivers"
"github.com/cortezaproject/corteza/server/store/adapters/rdbms/ql"
"github.com/doug-martin/goqu/v9"
"github.com/doug-martin/goqu/v9/dialect/postgres"
"github.com/doug-martin/goqu/v9/exp"
"github.com/doug-martin/goqu/v9/sqlgen"
"github.com/spf13/cast"
)
type (
@ -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(),

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) {
col = &ddl.Column{

View File

@ -1,10 +1,9 @@
package drivers
import (
"fmt"
"github.com/cortezaproject/corteza/server/pkg/dal"
"github.com/doug-martin/goqu/v9/exp"
"fmt"
"github.com/cortezaproject/corteza/server/pkg/dal"
"github.com/doug-martin/goqu/v9/exp"
)
type (
@ -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