2021-10-22 12:48:53 +02:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
// See LICENSE.txt for license information.
|
|
|
|
|
|
|
|
// Code generated by "make generate" from the Store interface
|
|
|
|
// DO NOT EDIT
|
|
|
|
|
|
|
|
// To add a public method, create an entry in the Store interface,
|
|
|
|
// prefix it with a @withTransaction comment if you need it to be
|
|
|
|
// transactional and then add a private method in the store itself
|
|
|
|
// with db sq.BaseRunner as the first parameter before running `make
|
|
|
|
// generate`
|
|
|
|
|
|
|
|
package sqlstore
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-12-10 16:46:37 +01:00
|
|
|
"time"
|
2021-10-22 12:48:53 +02:00
|
|
|
|
|
|
|
"github.com/mattermost/focalboard/server/model"
|
|
|
|
|
|
|
|
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
|
|
|
)
|
|
|
|
|
|
|
|
{{range $index, $element := .Methods}}
|
|
|
|
func (s *SQLStore) {{$index}}({{$element.Params | joinParamsWithType}}) {{$element.Results | joinResultsForSignature}} {
|
|
|
|
{{- if $element.WithTransaction}}
|
2022-03-22 15:24:34 +01:00
|
|
|
if s.dbType == model.SqliteDBType {
|
2022-02-22 22:30:47 +01:00
|
|
|
return s.{{$index | renameStoreMethod}}(s.db, {{$element.Params | joinParams}})
|
|
|
|
}
|
2021-10-22 12:48:53 +02:00
|
|
|
tx, txErr := s.db.BeginTx(context.Background(), nil)
|
|
|
|
if txErr != nil {
|
|
|
|
return {{ genErrorResultsVars $element.Results "txErr"}}
|
|
|
|
}
|
|
|
|
|
|
|
|
{{- if $element.Results | len | eq 0}}
|
|
|
|
s.{{$index | renameStoreMethod}}(tx, {{$element.Params | joinParams}})
|
|
|
|
|
|
|
|
if err := tx.Commit(); err != nil {
|
|
|
|
return {{ genErrorResultsVars $element.Results "err"}}
|
|
|
|
}
|
|
|
|
{{else}}
|
|
|
|
{{genResultsVars $element.Results false }} := s.{{$index | renameStoreMethod}}(tx, {{$element.Params | joinParams}})
|
|
|
|
{{- if $element.Results | errorPresent }}
|
|
|
|
if {{$element.Results | errorVar}} != nil {
|
|
|
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
|
|
|
s.logger.Error("transaction rollback error", mlog.Err(rollbackErr), mlog.String("methodName", "{{$index}}"))
|
|
|
|
}
|
|
|
|
return {{ genErrorResultsVars $element.Results "err"}}
|
|
|
|
}
|
|
|
|
{{end}}
|
|
|
|
if err := tx.Commit(); err != nil {
|
|
|
|
return {{ genErrorResultsVars $element.Results "err"}}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {{ genResultsVars $element.Results true -}}
|
|
|
|
{{end}}
|
|
|
|
{{else}}
|
|
|
|
return s.{{$index | renameStoreMethod}}(s.db, {{$element.Params | joinParams}})
|
|
|
|
{{end}}
|
|
|
|
}
|
|
|
|
{{end}}
|