From 85aa0f7fa89cad0cd81af87336d7f9d31bb19422 Mon Sep 17 00:00:00 2001 From: Masaya Tojo Date: Sat, 4 Mar 2023 19:44:11 +0900 Subject: Change insert_transaction signature to use integer. --- deploy/insert_transaction.sql | 3 ++- deploy/insert_transaction@v1.0.0-dev1.sql | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 deploy/insert_transaction@v1.0.0-dev1.sql (limited to 'deploy') diff --git a/deploy/insert_transaction.sql b/deploy/insert_transaction.sql index 851b38e..42e825d 100644 --- a/deploy/insert_transaction.sql +++ b/deploy/insert_transaction.sql @@ -4,8 +4,9 @@ BEGIN; +DROP FUNCTION kakeibo.insert_transaction(kakeibo.transaction_type, DATE, TEXT); CREATE OR REPLACE FUNCTION kakeibo.insert_transaction( - p_type kakeibo.transaction_type, + p_type INTEGER, p_date DATE, p_note TEXT ) RETURNS INTEGER AS $$ diff --git a/deploy/insert_transaction@v1.0.0-dev1.sql b/deploy/insert_transaction@v1.0.0-dev1.sql new file mode 100644 index 0000000..851b38e --- /dev/null +++ b/deploy/insert_transaction@v1.0.0-dev1.sql @@ -0,0 +1,24 @@ +-- Deploy kakeibo:insert_transaction to pg +-- requires: appschema +-- requires: transactions + +BEGIN; + +CREATE OR REPLACE FUNCTION kakeibo.insert_transaction( + p_type kakeibo.transaction_type, + p_date DATE, + p_note TEXT +) RETURNS INTEGER AS $$ +DECLARE + inserted_id INTEGER; +BEGIN + INSERT INTO kakeibo.transactions ( + type, date, note + ) VALUES ( + p_type, p_date, p_note + ) RETURNING id INTO inserted_id; + RETURN inserted_id; +END; +$$ LANGUAGE plpgsql SECURITY DEFINER; + +COMMIT; -- cgit v1.2.3