From 58c00ca515142d27e3fb324539dedd75b8740bcf Mon Sep 17 00:00:00 2001
From: Masaya Tojo <masaya@tojo.tokyo>
Date: Tue, 28 Feb 2023 22:20:25 +0900
Subject: Add function to insert item.

---
 deploy/insert_item.sql | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100644 deploy/insert_item.sql

(limited to 'deploy/insert_item.sql')

diff --git a/deploy/insert_item.sql b/deploy/insert_item.sql
new file mode 100644
index 0000000..a0a5b5c
--- /dev/null
+++ b/deploy/insert_item.sql
@@ -0,0 +1,26 @@
+-- Deploy kakeibo:insert_item to pg
+-- requires: appschema
+-- requires: items
+
+BEGIN;
+
+CREATE OR REPLACE FUNCTION kakeibo.insert_transaction(
+  p_transaction_id INTEER,
+  p_category TEXT,
+  p_subcategory TEXT,
+  p_amount INTEGER,
+  p_note TEXT
+) RETURNS INTEGER AS $$
+DECLARE
+  inserted_id INTEGER;
+BEGIN
+  INSERT INTO kakeibo.items (
+    transaction_id, category, subcategory, amount, note
+  ) VALUES (
+    p_transaction_id, p_category, p_subcategory, p_amount, p_note
+  ) RETURNING id INTO inserted_id;
+  RETURN inserted_id;
+END;
+$$ LANGUAGE plpgsql SECURITY DEFINER;
+
+COMMIT;
-- 
cgit v1.2.3

