diff options
author | Masaya Tojo <masaya@tojo.tokyo> | 2023-02-28 22:20:25 +0900 |
---|---|---|
committer | Masaya Tojo <masaya@tojo.tokyo> | 2023-03-02 09:22:36 +0900 |
commit | 58c00ca515142d27e3fb324539dedd75b8740bcf (patch) | |
tree | 1811551fce71b6f37fb097217b3b6bd05b990aad | |
parent | 0854294b374660178c3d62a75bdd9a554359dcb4 (diff) |
Add function to insert item.
-rw-r--r-- | deploy/insert_item.sql | 26 | ||||
-rw-r--r-- | revert/insert_item.sql | 7 | ||||
-rw-r--r-- | sqitch.plan | 1 | ||||
-rw-r--r-- | verify/insert_item.sql | 7 |
4 files changed, 41 insertions, 0 deletions
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; diff --git a/revert/insert_item.sql b/revert/insert_item.sql new file mode 100644 index 0000000..40417f0 --- /dev/null +++ b/revert/insert_item.sql @@ -0,0 +1,7 @@ +-- Revert kakeibo:insert_item from pg + +BEGIN; + +DROP FUNCTION kakeibo.insert_item; + +COMMIT; diff --git a/sqitch.plan b/sqitch.plan index 8bb9a76..ee84944 100644 --- a/sqitch.plan +++ b/sqitch.plan @@ -8,3 +8,4 @@ transactions [appschema transaction_type] 2023-02-27T15:53:02Z Masaya Tojo <masa insert_transaction [appschema transactions] 2023-02-28T01:06:21Z Masaya Tojo <masaya@tojo.tokyo> # Add function to insert transaction. delete_transaction [transactions appschema] 2023-02-28T12:00:07Z Masaya Tojo <masaya@tojo.tokyo> # Create a function to delete a transaction. items [appschema transactions] 2023-02-28T12:08:45Z Masaya Tojo <masaya@tojo.tokyo> # Add items table for tracking individual products in transaction. +insert_item [appschema items] 2023-02-28T13:13:22Z Masaya Tojo <masaya@tojo.tokyo> # Add function to insert item. diff --git a/verify/insert_item.sql b/verify/insert_item.sql new file mode 100644 index 0000000..dac4fba --- /dev/null +++ b/verify/insert_item.sql @@ -0,0 +1,7 @@ +-- Verify kakeibo:insert_item on pg + +BEGIN; + +SELECT has_function_privilege('kakeibo.insert_item(kakeibo.transaction_type, date, text)', 'execute'); + +ROLLBACK; |