SQLStore: Fix wrong usage of xorm's insert functions in tests (#63850)

* SQLStore: Fix InsertId

* Prefs: Fix Insert return value

* Fix tests

* Add guidelines
This commit is contained in:
Sofia Papagiannaki
2023-03-02 13:01:36 +02:00
committed by GitHub
parent afd5f41780
commit 89569be3a6
7 changed files with 21 additions and 11 deletions

View File

@@ -126,21 +126,21 @@ func (ss *SQLStore) withDbSession(ctx context.Context, engine *xorm.Engine, call
return retryer.Retry(ss.retryOnLocks(ctx, callback, sess, retry), ss.dbCfg.QueryRetries, time.Millisecond*time.Duration(10), time.Second)
}
func (sess *DBSession) InsertId(bean interface{}, dialect migrator.Dialect) (int64, error) {
func (sess *DBSession) InsertId(bean interface{}, dialect migrator.Dialect) error {
table := sess.DB().Mapper.Obj2Table(getTypeName(bean))
if err := dialect.PreInsertId(table, sess.Session); err != nil {
return 0, err
return err
}
id, err := sess.Session.InsertOne(bean)
_, err := sess.Session.InsertOne(bean)
if err != nil {
return 0, err
return err
}
if err := dialect.PostInsertId(table, sess.Session); err != nil {
return 0, err
return err
}
return id, nil
return nil
}
func (sess *DBSession) WithReturningID(driverName string, query string, args []interface{}) (int64, error) {