-- Deploy kakeibo:insert_transaction to pg
-- requires: appschema
-- requires: transactions

BEGIN;

CREATE OR REPLACE FUNCTION kakeibo.insert_transaction(
  p_type INTEGER,
  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;
