feat: include transaktions for writing in db to improve security and prevent data loss
This commit is contained in:
parent
2f20c58400
commit
553a85562b
1 changed files with 16 additions and 1 deletions
|
|
@ -251,6 +251,11 @@ func (s *SQLiteStorage) MarkAsExported(ctx context.Context, ids []int64) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tx, err := s.db.BeginTx(ctx, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
placeholders := strings.Repeat("?,", len(ids))
|
placeholders := strings.Repeat("?,", len(ids))
|
||||||
placeholders = placeholders[:len(placeholders)-1]
|
placeholders = placeholders[:len(placeholders)-1]
|
||||||
|
|
||||||
|
|
@ -261,7 +266,17 @@ func (s *SQLiteStorage) MarkAsExported(ctx context.Context, ids []int64) error {
|
||||||
args[i] = id
|
args[i] = id
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := s.db.ExecContext(ctx, sqlQuery, args...)
|
_, err = tx.ExecContext(ctx, sqlQuery, args...)
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = tx.Commit()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue