Refactored src and dst account to just account in preparation for a "counter party", instead of a full account.
This commit is contained in:
@@ -26,7 +26,7 @@ where
|
||||
sqlx::query_as!(
|
||||
TransactionRow,
|
||||
r#"
|
||||
SELECT id, description, amount_cents, direction, date
|
||||
SELECT id, account_id, amount_cents, direction, date, description
|
||||
FROM transactions
|
||||
ORDER BY date DESC, id DESC
|
||||
LIMIT $1
|
||||
@@ -50,7 +50,7 @@ where
|
||||
sqlx::query_as!(
|
||||
TransactionRow,
|
||||
r#"
|
||||
SELECT id, description, amount_cents, direction, date
|
||||
SELECT id, account_id, amount_cents, direction, date, description
|
||||
FROM transactions
|
||||
WHERE id = $1
|
||||
"#,
|
||||
@@ -70,26 +70,29 @@ where
|
||||
{
|
||||
let row = sqlx::query!(
|
||||
r#"
|
||||
INSERT INTO transactions (id, description, amount_cents, direction, date)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
INSERT INTO transactions (id, account_id, amount_cents, direction, date, description)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
ON CONFLICT (id) DO UPDATE SET
|
||||
description = EXCLUDED.description,
|
||||
account_id = EXCLUDED.account_id,
|
||||
amount_cents = EXCLUDED.amount_cents,
|
||||
direction = EXCLUDED.direction,
|
||||
date = EXCLUDED.date
|
||||
date = EXCLUDED.date,
|
||||
description = EXCLUDED.description
|
||||
RETURNING WITH (OLD AS old_row, NEW AS new_row)
|
||||
old_row.id AS "old_id?",
|
||||
new_row.id AS "id!",
|
||||
new_row.description AS "description!",
|
||||
new_row.account_id AS "account_id!",
|
||||
new_row.amount_cents AS "amount_cents!",
|
||||
new_row.direction AS "direction!",
|
||||
new_row.date AS "date!"
|
||||
new_row.date AS "date!",
|
||||
new_row.description AS "description!"
|
||||
"#,
|
||||
transaction.id,
|
||||
transaction.description,
|
||||
transaction.account_id,
|
||||
transaction.amount_cents,
|
||||
transaction.direction,
|
||||
transaction.date,
|
||||
transaction.description,
|
||||
)
|
||||
.fetch_one(executor)
|
||||
.await
|
||||
@@ -97,10 +100,11 @@ where
|
||||
|
||||
let transaction = TransactionRow {
|
||||
id: row.id,
|
||||
description: row.description,
|
||||
account_id: row.account_id,
|
||||
amount_cents: row.amount_cents,
|
||||
direction: row.direction,
|
||||
date: row.date,
|
||||
description: row.description,
|
||||
};
|
||||
|
||||
if row.old_id.is_some() {
|
||||
|
||||
Reference in New Issue
Block a user