Skip to content

Commit

Permalink
[bugfix] wrap bun.Tx to add our own error processing (#2169)
Browse files Browse the repository at this point in the history
* wrap bun.Tx to add our own error processing

Signed-off-by: kim <grufwub@gmail.com>

* add compile-time check for updateRowError() compatibility with sql.Row, fix wrapTx() not being used properly

Signed-off-by: kim <grufwub@gmail.com>

---------

Signed-off-by: kim <grufwub@gmail.com>
  • Loading branch information
NyaaaWhatsUpDoc committed Aug 31, 2023
1 parent 2ec313a commit 1ee99fc
Show file tree
Hide file tree
Showing 7 changed files with 270 additions and 46 deletions.
6 changes: 3 additions & 3 deletions internal/db/bundb/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func (a *accountDB) PutAccount(ctx context.Context, account *gtsmodel.Account) e
// It is safe to run this database transaction within cache.Store
// as the cache does not attempt a mutex lock until AFTER hook.
//
return a.db.RunInTx(ctx, func(tx bun.Tx) error {
return a.db.RunInTx(ctx, func(tx Tx) error {
// create links between this account and any emojis it uses
for _, i := range account.EmojiIDs {
if _, err := tx.NewInsert().Model(&gtsmodel.AccountToEmoji{
Expand Down Expand Up @@ -327,7 +327,7 @@ func (a *accountDB) UpdateAccount(ctx context.Context, account *gtsmodel.Account
// It is safe to run this database transaction within cache.Store
// as the cache does not attempt a mutex lock until AFTER hook.
//
return a.db.RunInTx(ctx, func(tx bun.Tx) error {
return a.db.RunInTx(ctx, func(tx Tx) error {
// create links between this account and any emojis it uses
// first clear out any old emoji links
if _, err := tx.
Expand Down Expand Up @@ -375,7 +375,7 @@ func (a *accountDB) DeleteAccount(ctx context.Context, id string) error {
return err
}

return a.db.RunInTx(ctx, func(tx bun.Tx) error {
return a.db.RunInTx(ctx, func(tx Tx) error {
// clear out any emoji links
if _, err := tx.
NewDelete().
Expand Down

0 comments on commit 1ee99fc

Please sign in to comment.