From 29cee46a1436beb9574f34a16e095c3ee0f32ea4 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Mon, 6 Dec 2021 20:47:47 +0000 Subject: [PATCH] Display accounts sorted by name --- postgres/accounts.sql.go | 2 ++ postgres/queries/accounts.sql | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/postgres/accounts.sql.go b/postgres/accounts.sql.go index d41f426..0eb66be 100644 --- a/postgres/accounts.sql.go +++ b/postgres/accounts.sql.go @@ -43,6 +43,7 @@ func (q *Queries) GetAccount(ctx context.Context, id uuid.UUID) (Account, error) const getAccounts = `-- name: GetAccounts :many SELECT accounts.id, accounts.budget_id, accounts.name FROM accounts WHERE accounts.budget_id = $1 +ORDER BY accounts.name ` func (q *Queries) GetAccounts(ctx context.Context, budgetID uuid.UUID) ([]Account, error) { @@ -75,6 +76,7 @@ LEFT JOIN transactions ON transactions.account_id = accounts.id WHERE accounts.budget_id = $1 AND transactions.date < NOW() GROUP BY accounts.id, accounts.name +ORDER BY accounts.name ` type GetAccountsWithBalanceRow struct { diff --git a/postgres/queries/accounts.sql b/postgres/queries/accounts.sql index 40f1433..39e4cb6 100644 --- a/postgres/queries/accounts.sql +++ b/postgres/queries/accounts.sql @@ -10,7 +10,8 @@ WHERE accounts.id = $1; -- name: GetAccounts :many SELECT accounts.* FROM accounts -WHERE accounts.budget_id = $1; +WHERE accounts.budget_id = $1 +ORDER BY accounts.name; -- name: GetAccountsWithBalance :many SELECT accounts.id, accounts.name, SUM(transactions.amount)::decimal(12,2) as balance @@ -18,4 +19,5 @@ FROM accounts LEFT JOIN transactions ON transactions.account_id = accounts.id WHERE accounts.budget_id = $1 AND transactions.date < NOW() -GROUP BY accounts.id, accounts.name; \ No newline at end of file +GROUP BY accounts.id, accounts.name +ORDER BY accounts.name; \ No newline at end of file