feat: include transaktions for writing in db to improve security and prevent data loss

This commit is contained in:
Patryk Hegenberg 2025-09-24 11:43:53 +02:00
parent 2f20c58400
commit 553a85562b

View file

@ -251,6 +251,11 @@ func (s *SQLiteStorage) MarkAsExported(ctx context.Context, ids []int64) error {
return nil
}
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
return err
}
placeholders := strings.Repeat("?,", len(ids))
placeholders = placeholders[:len(placeholders)-1]
@ -261,7 +266,17 @@ func (s *SQLiteStorage) MarkAsExported(ctx context.Context, ids []int64) error {
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
}