diff options
author | Jordan <me@jordan.im> | 2021-12-16 19:23:25 -0700 |
---|---|---|
committer | Jordan <me@jordan.im> | 2021-12-16 19:23:25 -0700 |
commit | bef78585658692e65d823594e8d6fc2bc18c1fd3 (patch) | |
tree | 0a953e69758a89813c1cbe5a5840f42062c14e97 | |
parent | a123ee5039d56a29c98ec8e9d182dfbb976b1f11 (diff) | |
download | keep-bef78585658692e65d823594e8d6fc2bc18c1fd3.tar.gz keep-bef78585658692e65d823594e8d6fc2bc18c1fd3.zip |
db: defer tx.Rollback() (cleaner)
-rw-r--r-- | db.go | 6 |
1 files changed, 1 insertions, 5 deletions
@@ -78,6 +78,7 @@ func addArchived(db *sql.DB, m *Message, status_code int) { if err != nil { log.Fatal(err) } + defer tx.Rollback() // Insert new entries in users, guilds, channels tables for new values, // ignoring those already present @@ -87,7 +88,6 @@ func addArchived(db *sql.DB, m *Message, status_code int) { INSERT OR IGNORE INTO channels(channel_id) VALUES(?);`, m.Author, m.Guild, m.Channel) if err != nil { - _ = tx.Rollback() log.Fatal(err) } @@ -100,13 +100,11 @@ func addArchived(db *sql.DB, m *Message, status_code int) { err = tx.QueryRow("SELECT id FROM users WHERE user_id = ?;", m.Author).Scan(&user_string_id) if err != nil { - _ = tx.Rollback() log.Fatal(err) } err = tx.QueryRow("SELECT id FROM guilds WHERE guild_id = ?;", m.Guild).Scan(&guild_string_id) if err != nil { - _ = tx.Rollback() log.Fatal(err) } err = tx.QueryRow("SELECT id FROM channels WHERE channel_id = ?;", @@ -121,13 +119,11 @@ func addArchived(db *sql.DB, m *Message, status_code int) { VALUES(?, ?, ?, ?, ?);`, m.URL, user_string_id, guild_string_id, channel_string_id, status_code) if err != nil { - _ = tx.Rollback() log.Fatal(err) } // Finally commit the transaction if err := tx.Commit(); err != nil { - _ = tx.Rollback() log.Fatal(err) } } |