refactor: sqlstore inTransaction consolidated to one version, fixes #8376
This commit is contained in:
@@ -6,8 +6,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/components/securejsondata"
|
||||
m "github.com/grafana/grafana/pkg/models"
|
||||
|
||||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -52,7 +50,7 @@ func GetDataSources(query *m.GetDataSourcesQuery) error {
|
||||
}
|
||||
|
||||
func DeleteDataSourceById(cmd *m.DeleteDataSourceByIdCommand) error {
|
||||
return inTransaction(func(sess *xorm.Session) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
var rawSql = "DELETE FROM data_source WHERE id=? and org_id=?"
|
||||
_, err := sess.Exec(rawSql, cmd.Id, cmd.OrgId)
|
||||
return err
|
||||
@@ -60,7 +58,7 @@ func DeleteDataSourceById(cmd *m.DeleteDataSourceByIdCommand) error {
|
||||
}
|
||||
|
||||
func DeleteDataSourceByName(cmd *m.DeleteDataSourceByNameCommand) error {
|
||||
return inTransaction(func(sess *xorm.Session) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
var rawSql = "DELETE FROM data_source WHERE name=? and org_id=?"
|
||||
_, err := sess.Exec(rawSql, cmd.Name, cmd.OrgId)
|
||||
return err
|
||||
@@ -69,7 +67,7 @@ func DeleteDataSourceByName(cmd *m.DeleteDataSourceByNameCommand) error {
|
||||
|
||||
func AddDataSource(cmd *m.AddDataSourceCommand) error {
|
||||
|
||||
return inTransaction(func(sess *xorm.Session) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
existing := m.DataSource{OrgId: cmd.OrgId, Name: cmd.Name}
|
||||
has, _ := sess.Get(&existing)
|
||||
|
||||
@@ -109,7 +107,7 @@ func AddDataSource(cmd *m.AddDataSourceCommand) error {
|
||||
})
|
||||
}
|
||||
|
||||
func updateIsDefaultFlag(ds *m.DataSource, sess *xorm.Session) error {
|
||||
func updateIsDefaultFlag(ds *m.DataSource, sess *DBSession) error {
|
||||
// Handle is default flag
|
||||
if ds.IsDefault {
|
||||
rawSql := "UPDATE data_source SET is_default=? WHERE org_id=? AND id <> ?"
|
||||
@@ -122,7 +120,7 @@ func updateIsDefaultFlag(ds *m.DataSource, sess *xorm.Session) error {
|
||||
|
||||
func UpdateDataSource(cmd *m.UpdateDataSourceCommand) error {
|
||||
|
||||
return inTransaction(func(sess *xorm.Session) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
ds := &m.DataSource{
|
||||
Id: cmd.Id,
|
||||
OrgId: cmd.OrgId,
|
||||
|
||||
Reference in New Issue
Block a user