mirror of
https://github.com/grafana/grafana.git
synced 2026-08-12 06:05:02 -05:00
Chore: Deduplicate sqlstore transaction code (#17069)
* Deduplicate transaction code * More deduplication
This commit is contained in:
@@ -18,6 +18,11 @@ func (sess *DBSession) publishAfterCommit(msg interface{}) {
|
||||
sess.events = append(sess.events, msg)
|
||||
}
|
||||
|
||||
// NewSession returns a new DBSession
|
||||
func (ss *SqlStore) NewSession() *DBSession {
|
||||
return &DBSession{Session: ss.engine.NewSession()}
|
||||
}
|
||||
|
||||
func newSession() *DBSession {
|
||||
return &DBSession{Session: x.NewSession()}
|
||||
}
|
||||
@@ -41,6 +46,16 @@ func startSession(ctx context.Context, engine *xorm.Engine, beginTran bool) (*DB
|
||||
return newSess, nil
|
||||
}
|
||||
|
||||
// WithDbSession calls the callback with an session attached to the context.
|
||||
func (ss *SqlStore) WithDbSession(ctx context.Context, callback dbTransactionFunc) error {
|
||||
sess, err := startSession(ctx, ss.engine, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return callback(sess)
|
||||
}
|
||||
|
||||
func withDbSession(ctx context.Context, callback dbTransactionFunc) error {
|
||||
sess, err := startSession(ctx, x, false)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user