fixed db issues

This commit is contained in:
2026-02-05 20:07:37 +11:00
parent 59ee880b63
commit 2e2c2af44d
9 changed files with 140 additions and 61 deletions

View File

@@ -46,7 +46,10 @@ func GetRoleByName(ctx context.Context, tx bun.Tx, name roles.Role) (*Role, erro
Where("name = ?", name).
Limit(1).
Scan(ctx)
if err != nil && err != sql.ErrNoRows {
if err != nil {
if err == sql.ErrNoRows {
return nil, nil
}
return nil, errors.Wrap(err, "tx.NewSelect")
}
return role, nil
@@ -65,7 +68,10 @@ func GetRoleByID(ctx context.Context, tx bun.Tx, id int) (*Role, error) {
Where("id = ?", id).
Limit(1).
Scan(ctx)
if err != nil && err != sql.ErrNoRows {
if err != nil {
if err == sql.ErrNoRows {
return nil, nil
}
return nil, errors.Wrap(err, "tx.NewSelect")
}
return role, nil
@@ -84,7 +90,10 @@ func GetRoleWithPermissions(ctx context.Context, tx bun.Tx, id int) (*Role, erro
Relation("Permissions").
Limit(1).
Scan(ctx)
if err != nil && err != sql.ErrNoRows {
if err != nil {
if err == sql.ErrNoRows {
return nil, nil
}
return nil, errors.Wrap(err, "tx.NewSelect")
}
return role, nil
@@ -112,6 +121,7 @@ func CreateRole(ctx context.Context, tx bun.Tx, role *Role) error {
_, err := tx.NewInsert().
Model(role).
Returning("id").
Exec(ctx)
if err != nil {
return errors.Wrap(err, "tx.NewInsert")