feat(transaction): #66 implement transactions

This commit is contained in:
2025-05-14 23:34:52 +02:00
parent c9adb5e928
commit 1ffe3b3961
14 changed files with 342 additions and 302 deletions

View File

@@ -1,10 +1,38 @@
package db
import (
"database/sql"
"errors"
"spend-sparrow/log"
"spend-sparrow/types"
)
var (
ErrNotFound = errors.New("the value does not exist")
ErrAlreadyExists = errors.New("row already exists")
)
func TransformAndLogDbError(module string, r sql.Result, err error) error {
if err != nil {
if err == sql.ErrNoRows {
return ErrNotFound
}
log.Error("%v: %v", module, err)
return types.ErrInternal
}
if r != nil {
rows, err := r.RowsAffected()
if err != nil {
log.Error("%v: %v", module, err)
return types.ErrInternal
}
if rows == 0 {
log.Info("%v: not found", module)
return ErrNotFound
}
}
return nil
}