Nested folder: Fix for PostgreSQL (#59405)
* Nested Folders: Fix PostgreSQL LastInsertId failure * Fix children sorting * Fix store tests
This commit is contained in:
@@ -3,12 +3,14 @@ package sqlstore
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"xorm.io/xorm"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
"github.com/grafana/grafana/pkg/util/retryer"
|
||||
"github.com/mattn/go-sqlite3"
|
||||
@@ -131,6 +133,28 @@ func (sess *DBSession) InsertId(bean interface{}) (int64, error) {
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func (sess *DBSession) WithReturningID(driverName string, query string, args []interface{}) (int64, error) {
|
||||
supported := driverName != migrator.Postgres
|
||||
var id int64
|
||||
if !supported {
|
||||
query = fmt.Sprintf("%s RETURNING id", query)
|
||||
if _, err := sess.SQL(query, args...).Get(&id); err != nil {
|
||||
return id, err
|
||||
}
|
||||
} else {
|
||||
sqlOrArgs := append([]interface{}{query}, args...)
|
||||
res, err := sess.Exec(sqlOrArgs...)
|
||||
if err != nil {
|
||||
return id, err
|
||||
}
|
||||
id, err = res.LastInsertId()
|
||||
if err != nil {
|
||||
return id, err
|
||||
}
|
||||
}
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func getTypeName(bean interface{}) (res string) {
|
||||
t := reflect.TypeOf(bean)
|
||||
for t.Kind() == reflect.Ptr {
|
||||
|
||||
Reference in New Issue
Block a user