Database package, schema and queries

This commit is contained in:
2026-06-04 23:41:15 +02:00
parent 25deebb0e1
commit a400ad31bf
6 changed files with 204 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
-- name: CreateTransaction :one
INSERT INTO fts.transactions (
description, amount, category, transaction_date
) VALUES (
$1, $2, $3, $4
)
RETURNING *;
-- name: ListTransactions :many
SELECT * FROM fts.transactions
ORDER BY transaction_date DESC, transaction_id DESC;
-- name: GetTransaction :one
SELECT * FROM fts.transactions
WHERE transaction_id = $1;
-- name: DeleteTransaction :exec
DELETE FROM fts.transactions
WHERE transaction_id = $1;

View File

@@ -0,0 +1,18 @@
-- +goose Up
CREATE SCHEMA IF NOT EXISTS fts;
CREATE TABLE fts.transactions (
transaction_id SERIAL PRIMARY KEY,
description TEXT NOT NULL,
amount NUMERIC(12, 2) NOT NULL,
category VARCHAR(50) NOT NULL,
transaction_date TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL
);
-- Index for querying transactions by date
CREATE INDEX idx_transactions_date ON fts.transactions(transaction_date);
-- +goose Down
DROP INDEX IF EXISTS fts.idx_transactions_date;
DROP TABLE IF EXISTS fts.transactions;