From 4e57aeaf8cb67dfdf7cb933a244721e10079aae8 Mon Sep 17 00:00:00 2001 From: Christopher Vollick <0@psycoti.ca> Date: Tue, 24 Jan 2023 11:04:43 -0500 Subject: [PATCH] Transaction Delete and Existance Now that Transaction acts as a kind of repo, there's two other methods I'm going to want for the future. --- lib/transaction.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/transaction.rb b/lib/transaction.rb index 921b9951c1f98c2d79f890f0576556d1846c0275..e4bce70f04bc4904ec08825e5e994a6aff4a41df 100644 --- a/lib/transaction.rb +++ b/lib/transaction.rb @@ -23,6 +23,20 @@ class Transaction end end + def delete + ids = [@transaction_id, "bonus_for_#{@transaction_id}"] + DB.query_defer(<<~SQL, ids) + DELETE FROM transactions WHERE transaction_id IN ($1, $2) + SQL + end + + def exists? + DB.query_one(<<~SQL, @transaction_id).then { |r| r[:count] == 1 } + SELECT COUNT(1) FROM transactions + WHERE transaction_id = $1 + SQL + end + def total amount + bonus end