Skip to content

make database.DB transactable

Warren Gifford requested to merge cc/make-db-transactable into main

Created by: camdencheek

This PR makes database.DB transactable by wrapping a basestore.Store rather than a dbutil.DB directly. This allows us to run db.Transact(), get a new transaction, then call tx.Repos() or whatever to get a more specific store. It also allows us to use transactions for small tasks that don't have a store associated with them, such as GetFirstServiceVersion. This makes it now possible to remove the dbconn.Global reference in that function, and migrate those tests to use dbtest.NewDB() rather than dbtesting.SetupGlobalDB().

Example:

db := database.NewDB(sqlDB)
tx, _ := db.Transact(ctx)
tx.Repos() // do something with repos
tx.Users() // do something with users in the same transaction

Merge request reports

Loading