Refactor store migration/upgrade proc
This commit is contained in:
@@ -37,7 +37,7 @@ type (
|
||||
Tx(context.Context, func(context.Context, Storer) error) error
|
||||
|
||||
// Upgrade store's schema to the latest version
|
||||
Upgrade(context.Context, *zap.Logger) error
|
||||
Upgrade(context.Context) error
|
||||
|
||||
{{- range .types }}
|
||||
{{ .expIdentPlural }}
|
||||
|
||||
@@ -46,7 +46,7 @@ func (aux {{ .auxIdent }}) decode() (res *{{ .goType }}, _ error) {
|
||||
// scans row and fills {{ .auxIdent }} fields
|
||||
//
|
||||
// This function is auto-generated
|
||||
func (aux *{{ .auxIdent }})scan(row scalable) (error) {
|
||||
func (aux *{{ .auxIdent }})scan(row scanner) (error) {
|
||||
return row.Scan(
|
||||
{{- range .auxStruct }}
|
||||
&aux.{{ .expIdent }},
|
||||
|
||||
@@ -44,7 +44,7 @@ func (s *Store) Create{{ .expIdent }}(ctx context.Context, {{ template "extraArg
|
||||
return
|
||||
}
|
||||
|
||||
if err = s.Exec(ctx, {{ .ident }}InsertQuery(s.config.Dialect, rr[i])); err != nil {
|
||||
if err = s.Exec(ctx, {{ .ident }}InsertQuery(s.Dialect, 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.config.Dialect, rr[i])); err != nil {
|
||||
if err = s.Exec(ctx, {{ .ident }}UpdateQuery(s.Dialect, 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.config.Dialect, rr[i])); err != nil {
|
||||
if err = s.Exec(ctx, {{ .ident }}UpsertQuery(s.Dialect, 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.config.Dialect, {{ .ident }}PrimaryKeys(rr[i]))); err != nil {
|
||||
if err = s.Exec(ctx, {{ .ident }}DeleteQuery(s.Dialect, {{ .ident }}PrimaryKeys(rr[i]))); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -104,7 +104,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.primaryKeys }}{{ .ident }} {{ .goType }},{{ end }}) error {
|
||||
return s.Exec(ctx, {{ .ident }}DeleteQuery(s.config.Dialect, goqu.Ex{
|
||||
return s.Exec(ctx, {{ .ident }}DeleteQuery(s.Dialect, goqu.Ex{
|
||||
{{- range .api.deleteByPK.primaryKeys }}
|
||||
{{ printf "%q" .storeIdent }}: {{ .ident }},
|
||||
{{- end }}
|
||||
@@ -112,8 +112,8 @@ 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.config.Dialect))
|
||||
func (s Store) Truncate{{ .expIdentPlural }}(ctx context.Context, {{ template "extraArgs" .ident }}) error {
|
||||
return s.Exec(ctx, {{ .ident }}TruncateQuery(s.Dialect))
|
||||
}
|
||||
|
||||
// Search{{ .expIdentPlural }} returns (filtered) set of {{ .expIdentPlural }}
|
||||
@@ -324,9 +324,9 @@ func (s *Store) Query{{ .expIdentPlural }}(
|
||||
{{ end }}
|
||||
)
|
||||
|
||||
if s.config.Filters.{{ .expIdent }} != nil {
|
||||
if s.Filters.{{ .expIdent }} != nil {
|
||||
// extended filter set
|
||||
tExpr, f, err = s.config.Filters.{{ .expIdent }}(s, f)
|
||||
tExpr, f, err = s.Filters.{{ .expIdent }}(s, f)
|
||||
} else {
|
||||
// using generated filter
|
||||
tExpr, f, err = {{ .expIdent }}Filter(f)
|
||||
@@ -351,7 +351,7 @@ func (s *Store) Query{{ .expIdentPlural }}(
|
||||
{{ end }}
|
||||
|
||||
|
||||
query := {{ .ident }}SelectQuery(s.config.Dialect).Where(expr...)
|
||||
query := {{ .ident }}SelectQuery(s.Dialect).Where(expr...)
|
||||
|
||||
{{ if .features.sorting }}
|
||||
// sorting feature is enabled
|
||||
@@ -437,10 +437,10 @@ func (s *Store) Query{{ .expIdentPlural }}(
|
||||
var (
|
||||
rows *sql.Rows
|
||||
aux = new({{ .auxIdent }})
|
||||
lookup = {{ .ident }}SelectQuery(s.config.Dialect).Where(
|
||||
lookup = {{ .ident }}SelectQuery(s.Dialect).Where(
|
||||
{{- range .args }}
|
||||
{{- if .ignoreCase }}
|
||||
s.config.Functions.LOWER(goqu.I({{ printf "%q" .storeIdent }})).Eq(strings.ToLower({{ .ident }})),
|
||||
s.Functions.LOWER(goqu.I({{ printf "%q" .storeIdent }})).Eq(strings.ToLower({{ .ident }})),
|
||||
{{- else }}
|
||||
goqu.I({{ printf "%q" .storeIdent }}).Eq({{ .ident }}),
|
||||
{{- end }}
|
||||
|
||||
Reference in New Issue
Block a user