Refactor RDBMS store, allow more flexibiltiy
Switch to driver instead of passing GOQU to allow use of other per-driver functionalities.
This commit is contained in:
@@ -44,7 +44,7 @@ func (s *Store) Create{{ .expIdent }}(ctx context.Context, {{ template "extraArg
|
||||
return
|
||||
}
|
||||
|
||||
if err = s.Exec(ctx, {{ .ident }}InsertQuery(s.Dialect, rr[i])); err != nil {
|
||||
if err = s.Exec(ctx, {{ .ident }}InsertQuery(s.Dialect.GOQU(), rr[i])); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ func (s *Store) Update{{ .expIdent }}(ctx context.Context, {{ template "extraArg
|
||||
return
|
||||
}
|
||||
|
||||
if err = s.Exec(ctx, {{ .ident }}UpdateQuery(s.Dialect, rr[i])); err != nil {
|
||||
if err = s.Exec(ctx, {{ .ident }}UpdateQuery(s.Dialect.GOQU(), rr[i])); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ func (s *Store) Upsert{{ .expIdent }}(ctx context.Context, {{ template "extraArg
|
||||
return
|
||||
}
|
||||
|
||||
if err = s.Exec(ctx, {{ .ident }}UpsertQuery(s.Dialect, rr[i])); err != nil {
|
||||
if err = s.Exec(ctx, {{ .ident }}UpsertQuery(s.Dialect.GOQU(), rr[i])); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -92,7 +92,7 @@ func (s *Store) Upsert{{ .expIdent }}(ctx context.Context, {{ template "extraArg
|
||||
// This function is auto-generated
|
||||
func (s *Store) Delete{{ .expIdent }}(ctx context.Context, {{ template "extraArgs" .ident }} rr ...*{{ .goType }}) (err error) {
|
||||
for i := range rr {
|
||||
if err = s.Exec(ctx, {{ .ident }}DeleteQuery(s.Dialect, {{ .ident }}PrimaryKeys(rr[i]))); err != nil {
|
||||
if err = s.Exec(ctx, {{ .ident }}DeleteQuery(s.Dialect.GOQU(), {{ .ident }}PrimaryKeys(rr[i]))); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -105,7 +105,7 @@ func (s *Store) Delete{{ .expIdent }}(ctx context.Context, {{ template "extraArg
|
||||
//
|
||||
// This function is auto-generated
|
||||
func (s *Store) {{ .api.deleteByPK.expFnIdent }}(ctx context.Context, {{ template "extraArgs" .ident }} {{ range .api.deleteByPK.attributes }}{{ .ident }} {{ .goType }},{{ end }}) error {
|
||||
return s.Exec(ctx, {{ .ident }}DeleteQuery(s.Dialect, goqu.Ex{
|
||||
return s.Exec(ctx, {{ .ident }}DeleteQuery(s.Dialect.GOQU(), goqu.Ex{
|
||||
{{- range .api.deleteByPK.attributes }}
|
||||
{{ printf "%q" .storeIdent }}: {{ .ident }},
|
||||
{{- end }}
|
||||
@@ -115,7 +115,7 @@ func (s *Store) {{ .api.deleteByPK.expFnIdent }}(ctx context.Context, {{ templat
|
||||
|
||||
// Truncate{{ .expIdentPlural }} Deletes all rows from the {{ .ident }} collection
|
||||
func (s *Store) Truncate{{ .expIdentPlural }}(ctx context.Context, {{ template "extraArgs" .ident }}) error {
|
||||
return s.Exec(ctx, {{ .ident }}TruncateQuery(s.Dialect))
|
||||
return s.Exec(ctx, {{ .ident }}TruncateQuery(s.Dialect.GOQU()))
|
||||
}
|
||||
|
||||
// Search{{ .expIdentPlural }} returns (filtered) set of {{ .expIdentPlural }}
|
||||
@@ -377,7 +377,7 @@ func (s *Store) Query{{ .expIdentPlural }}(
|
||||
{{ end }}
|
||||
|
||||
|
||||
query := {{ .ident }}SelectQuery(s.Dialect).Where(expr...)
|
||||
query := {{ .ident }}SelectQuery(s.Dialect.GOQU()).Where(expr...)
|
||||
|
||||
{{ if .features.sorting }}
|
||||
// sorting feature is enabled
|
||||
@@ -463,7 +463,7 @@ func (s *Store) Query{{ .expIdentPlural }}(
|
||||
var (
|
||||
rows *sql.Rows
|
||||
aux = new({{ .auxIdent }})
|
||||
lookup = {{ .ident }}SelectQuery(s.Dialect).Where(
|
||||
lookup = {{ .ident }}SelectQuery(s.Dialect.GOQU()).Where(
|
||||
{{- range .args }}
|
||||
{{- if .ignoreCase }}
|
||||
s.Functions.LOWER(goqu.I({{ printf "%q" .storeIdent }})).Eq(strings.ToLower({{ .ident }})),
|
||||
|
||||
@@ -15,7 +15,7 @@ func (s Store) ApplicationMetrics(ctx context.Context) (_ *systemType.Applicatio
|
||||
Valid uint `db:"valid"`
|
||||
}{}
|
||||
|
||||
query = applicationSelectQuery(s.Dialect).
|
||||
query = applicationSelectQuery(s.Dialect.GOQU()).
|
||||
Select(timestampStatExpr("deleted")...)
|
||||
)
|
||||
|
||||
@@ -39,7 +39,7 @@ func (s Store) ReorderApplications(ctx context.Context, order []uint64) (err err
|
||||
f = systemType.ApplicationFilter{}
|
||||
|
||||
query = func(id uint64, weight int) *goqu.UpdateDataset {
|
||||
return s.Dialect.
|
||||
return s.Dialect.GOQU().
|
||||
Update(applicationTable).
|
||||
Set(goqu.Record{"weight": weight}).
|
||||
Where(goqu.C("id").Eq(id))
|
||||
|
||||
@@ -8,21 +8,21 @@ import (
|
||||
)
|
||||
|
||||
func (s Store) DeleteExpiredAuthOA2Tokens(ctx context.Context) error {
|
||||
return s.Exec(ctx, authOa2tokenDeleteQuery(s.Dialect, goqu.C("expires_at").Lt(time.Now())))
|
||||
return s.Exec(ctx, authOa2tokenDeleteQuery(s.Dialect.GOQU(), goqu.C("expires_at").Lt(time.Now())))
|
||||
}
|
||||
|
||||
func (s Store) DeleteAuthOA2TokenByCode(ctx context.Context, code string) error {
|
||||
return s.Exec(ctx, authOa2tokenDeleteQuery(s.Dialect, goqu.C("code").Eq(code)))
|
||||
return s.Exec(ctx, authOa2tokenDeleteQuery(s.Dialect.GOQU(), goqu.C("code").Eq(code)))
|
||||
}
|
||||
|
||||
func (s Store) DeleteAuthOA2TokenByAccess(ctx context.Context, access string) error {
|
||||
return s.Exec(ctx, authOa2tokenDeleteQuery(s.Dialect, goqu.C("access").Eq(access)))
|
||||
return s.Exec(ctx, authOa2tokenDeleteQuery(s.Dialect.GOQU(), goqu.C("access").Eq(access)))
|
||||
}
|
||||
|
||||
func (s Store) DeleteAuthOA2TokenByRefresh(ctx context.Context, refresh string) error {
|
||||
return s.Exec(ctx, authOa2tokenDeleteQuery(s.Dialect, goqu.C("refresh").Eq(refresh)))
|
||||
return s.Exec(ctx, authOa2tokenDeleteQuery(s.Dialect.GOQU(), goqu.C("refresh").Eq(refresh)))
|
||||
}
|
||||
|
||||
func (s Store) DeleteAuthOA2TokenByUserID(ctx context.Context, userID uint64) error {
|
||||
return s.Exec(ctx, authOa2tokenDeleteQuery(s.Dialect, goqu.C("rel_user").Eq(userID)))
|
||||
return s.Exec(ctx, authOa2tokenDeleteQuery(s.Dialect.GOQU(), goqu.C("rel_user").Eq(userID)))
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ import (
|
||||
)
|
||||
|
||||
func (s Store) DeleteExpiredAuthSessions(ctx context.Context) error {
|
||||
return s.Exec(ctx, authSessionDeleteQuery(s.Dialect, goqu.C("expires_at").Lt(time.Now())))
|
||||
return s.Exec(ctx, authSessionDeleteQuery(s.Dialect.GOQU(), goqu.C("expires_at").Lt(time.Now())))
|
||||
}
|
||||
|
||||
func (s Store) DeleteAuthSessionsByUserID(ctx context.Context, userID uint64) error {
|
||||
return s.Exec(ctx, authSessionDeleteQuery(s.Dialect, goqu.C("rel_user").Eq(userID)))
|
||||
return s.Exec(ctx, authSessionDeleteQuery(s.Dialect.GOQU(), goqu.C("rel_user").Eq(userID)))
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ func (s Store) ReorderComposePages(ctx context.Context, namespaceID uint64, pare
|
||||
f = composeType.PageFilter{ParentID: parentID, NamespaceID: namespaceID}
|
||||
|
||||
query = func(id uint64, weight int) *goqu.UpdateDataset {
|
||||
return s.Dialect.
|
||||
return s.Dialect.GOQU().
|
||||
Update(composePageTable).
|
||||
Set(goqu.Record{"weight": weight}).
|
||||
Where(goqu.C("id").Eq(id))
|
||||
|
||||
@@ -18,5 +18,5 @@ func (s Store) DeleteExtraLabels(ctx context.Context, kind string, resourceId ui
|
||||
expr = append(expr, goqu.C("name").NotIn(name))
|
||||
}
|
||||
|
||||
return s.Exec(ctx, labelDeleteQuery(s.Dialect, expr...))
|
||||
return s.Exec(ctx, labelDeleteQuery(s.Dialect.GOQU(), expr...))
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ func (s Store) dailyMetrics(ctx context.Context, tbl exp.IdentifierExpression, e
|
||||
|
||||
return rval, func() (err error) {
|
||||
daily := s.Functions.DATE(goqu.C(field))
|
||||
query := s.Dialect.
|
||||
query := s.Dialect.GOQU().
|
||||
Select(daily, goqu.COUNT(goqu.Star()).As("value")).
|
||||
From(tbl).
|
||||
Where(goqu.C(field).IsNotNull(), goqu.And(expr...)).
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
func (s Store) TransferRbacRules(ctx context.Context, src, dst uint64) (err error) {
|
||||
var (
|
||||
transfer = s.Dialect.Update(rbacRuleTable).
|
||||
transfer = s.Dialect.GOQU().Update(rbacRuleTable).
|
||||
Set(goqu.Record{"rel_role": dst}).
|
||||
Where(goqu.Ex{"rel_role": src})
|
||||
)
|
||||
|
||||
@@ -16,7 +16,7 @@ func (s Store) RoleMetrics(ctx context.Context) (m *systemType.RoleMetrics, err
|
||||
Archived uint `db:"archived"`
|
||||
}{}
|
||||
|
||||
query = roleSelectQuery(s.Dialect).
|
||||
query = roleSelectQuery(s.Dialect.GOQU()).
|
||||
Select(timestampStatExpr("deleted", "archived")...)
|
||||
)
|
||||
|
||||
@@ -57,7 +57,7 @@ func (s Store) RoleMetrics(ctx context.Context) (m *systemType.RoleMetrics, err
|
||||
|
||||
func (s Store) TransferRoleMembers(ctx context.Context, src, dst uint64) (err error) {
|
||||
var (
|
||||
transfer = s.Dialect.Update(roleMemberTable).
|
||||
transfer = s.Dialect.GOQU().Update(roleMemberTable).
|
||||
Set(goqu.Record{"rel_role": dst}).
|
||||
Where(goqu.Ex{"rel_role": src})
|
||||
)
|
||||
|
||||
@@ -15,7 +15,7 @@ func (s *Store) CountUsers(ctx context.Context, f systemType.UserFilter) (c uint
|
||||
|
||||
expr, _, err = s.Filters.User(s, f)
|
||||
|
||||
query = s.Dialect.
|
||||
query = s.Dialect.GOQU().
|
||||
From(userTable).
|
||||
Select(goqu.COUNT(goqu.Star()).As("count"))
|
||||
)
|
||||
@@ -40,7 +40,7 @@ func (s *Store) UserMetrics(ctx context.Context) (m *systemType.UserMetrics, err
|
||||
Suspended uint `db:"suspended"`
|
||||
}{}
|
||||
|
||||
query = userSelectQuery(s.Dialect).
|
||||
query = userSelectQuery(s.Dialect.GOQU()).
|
||||
Select(timestampStatExpr("deleted", "suspended")...)
|
||||
)
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ func Connect(ctx context.Context, dsn string) (_ store.Storer, err error) {
|
||||
|
||||
DAL: dal.Connection(db, Dialect(), DataDefiner(cfg.DBName, db)),
|
||||
|
||||
Dialect: goquDialectWrapper,
|
||||
Dialect: Dialect(),
|
||||
TxRetryErrHandler: txRetryErrHandler,
|
||||
ErrorHandler: errorHandler,
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ func Connect(ctx context.Context, dsn string) (_ store.Storer, err error) {
|
||||
|
||||
DAL: dal.Connection(db, Dialect(), DataDefiner(cfg.DBName, db)),
|
||||
|
||||
Dialect: goquDialectWrapper,
|
||||
Dialect: Dialect(),
|
||||
ErrorHandler: errorHandler,
|
||||
|
||||
DataDefiner: DataDefiner(cfg.DBName, db),
|
||||
|
||||
@@ -71,7 +71,7 @@ func Connect(ctx context.Context, dsn string) (_ store.Storer, err error) {
|
||||
|
||||
DAL: dal.Connection(db, Dialect(), DataDefiner(cfg.DBName, db)),
|
||||
|
||||
Dialect: goquDialectWrapper,
|
||||
Dialect: Dialect(),
|
||||
ErrorHandler: errorHandler,
|
||||
|
||||
TxRetryLimit: -1,
|
||||
|
||||
@@ -199,7 +199,7 @@ func DefaultFilters() (f *extendedFilters) {
|
||||
}
|
||||
|
||||
if f.MemberID > 0 {
|
||||
memberships := roleMemberSelectQuery(s.Dialect).
|
||||
memberships := roleMemberSelectQuery(s.Dialect.GOQU()).
|
||||
Select("rel_role").
|
||||
Where(goqu.C("rel_user").In(f.MemberID))
|
||||
|
||||
@@ -219,7 +219,7 @@ func DefaultFilters() (f *extendedFilters) {
|
||||
}
|
||||
|
||||
if len(f.RoleID) > 0 {
|
||||
members := roleMemberSelectQuery(s.Dialect).
|
||||
members := roleMemberSelectQuery(s.Dialect.GOQU()).
|
||||
Select("rel_user").
|
||||
Where(goqu.C("rel_role").In(f.RoleID))
|
||||
|
||||
|
||||
Generated
+358
-358
File diff suppressed because it is too large
Load Diff
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/cortezaproject/corteza-server/pkg/errors"
|
||||
"github.com/cortezaproject/corteza-server/store"
|
||||
"github.com/cortezaproject/corteza-server/store/adapters/rdbms/ddl"
|
||||
"github.com/cortezaproject/corteza-server/store/adapters/rdbms/drivers"
|
||||
"github.com/doug-martin/goqu/v9"
|
||||
"github.com/doug-martin/goqu/v9/exec"
|
||||
"github.com/doug-martin/goqu/v9/exp"
|
||||
@@ -46,7 +47,7 @@ type (
|
||||
// data definer interface use for schema information lookups and modification
|
||||
DataDefiner ddl.DataDefiner
|
||||
|
||||
Dialect goqu.DialectWrapper
|
||||
Dialect drivers.Dialect
|
||||
|
||||
// set to -1 to disable transactions
|
||||
TxRetryLimit int
|
||||
|
||||
Reference in New Issue
Block a user