1
0

Make DeleteReply() return count of affected rows.

This commit is contained in:
Alexander Andreev 2023-03-23 17:03:23 +04:00
parent 506a010b23
commit 723d2d4772
Signed by: Arav
GPG Key ID: D22A817D95815393
2 changed files with 8 additions and 8 deletions

View File

@ -279,26 +279,26 @@ func (d *SQLiteDatabase) UpdateReply(reply *guestbook.Reply) error {
return nil return nil
} }
func (d *SQLiteDatabase) DeleteReply(entryID int64) error { func (d *SQLiteDatabase) DeleteReply(entryID int64) (int64, error) {
tx, err := d.db.Begin() tx, err := d.db.Begin()
if err != nil { if err != nil {
return err return -1, err
} }
defer tx.Rollback() defer tx.Rollback()
res, err := tx.Stmt(stmtDeleteReply).Exec(entryID) res, err := tx.Stmt(stmtDeleteReply).Exec(entryID)
if err != nil { if err != nil {
return err return -1, err
} }
_, err = res.RowsAffected() ra, err := res.RowsAffected()
if err != nil { if err != nil {
return err return -1, err
} }
tx.Commit() tx.Commit()
return nil return ra, nil
} }
func (d *SQLiteDatabase) Close() error { func (d *SQLiteDatabase) Close() error {

View File

@ -7,9 +7,9 @@ type Guestbook interface {
Count() (int64, error) Count() (int64, error)
NewEntry(entry *Entry) error NewEntry(entry *Entry) error
UpdateEntry(entry *Entry) error UpdateEntry(entry *Entry) error
DeleteEntry(entryID int64) error DeleteEntry(entryID int64) (int64, error)
NewReply(reply *Reply) error NewReply(reply *Reply) error
UpdateReply(reply *Reply) error UpdateReply(reply *Reply) error
DeleteReply(entryID int64) error DeleteReply(entryID int64) (int64, error)
Close() error Close() error
} }