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

@@ -190,6 +190,12 @@ for context.
If a column, or column combination, should be unique, add a corresponding uniqueness constraint through a migration.
### Usage of XORM Session.Insert() and Session.InsertOne()
The [Session.Insert()](https://pkg.go.dev/github.com/go-xorm/xorm#Session.Insert) and [Session.InsertOne()](https://pkg.go.dev/github.com/go-xorm/xorm#Session.InsertOne) are poorly documented and return the number of affected rows contrary to a common mistake that they return the newly introduced primary key. Therefore, contributors should be extra cautious when using them.
The same applies for the respective [Engine.Insert()](https://pkg.go.dev/github.com/go-xorm/xorm#Engine.Insert) and [Engine.InsertOne()](https://pkg.go.dev/github.com/go-xorm/xorm#Engine.InsertOne)
## JSON
The simplejson package is used a lot throughout the backend codebase,