From 8102191eb96a7f5a7cd2baf2711c273f179a11e4 Mon Sep 17 00:00:00 2001 From: Masaya Tojo Date: Tue, 28 Feb 2023 10:11:02 +0900 Subject: Add function to insert transaction. --- deploy/insert_transaction.sql | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 deploy/insert_transaction.sql (limited to 'deploy') diff --git a/deploy/insert_transaction.sql b/deploy/insert_transaction.sql new file mode 100644 index 0000000..851b38e --- /dev/null +++ b/deploy/insert_transaction.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