Created
March 13, 2016 14:05
-
-
Save areski/b6ecafb20a2508230d18 to your computer and use it in GitHub Desktop.
PLLUAU example calling API when new Customer are created
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- PLLUAU example calling API when new Customer are created | |
-- | |
CREATE TABLE customer ( | |
id bigserial primary key, | |
full_name varchar(200) NOT NULL, | |
email varchar(200) NOT NULL, | |
created_date timestamp default NOW() | |
); | |
-- | |
-- Trigger | |
-- | |
CREATE OR REPLACE FUNCTION customer_created() RETURNS trigger AS $$ | |
local row, operation = trigger.row, trigger.operation | |
print(_VERSION) | |
if operation == "insert" then | |
local curl = require "cURL.safe" | |
local api_url = 'http://requestb.in/184vyco1' | |
-- Perform HTTP Post | |
curl.easy() | |
:setopt_url(api_url) | |
:setopt_writefunction(io.stderr) | |
:setopt_httppost( | |
curl.form() | |
:add_content("full_name", row.full_name) | |
:add_content("email", row.email) | |
) | |
:perform() | |
:close() | |
end | |
$$language plluau; | |
DROP TRIGGER customer_create_trigger ON customer; | |
CREATE TRIGGER customer_create_trigger AFTER INSERT ON customer | |
FOR EACH ROW EXECUTE PROCEDURE customer_created(); | |
INSERT INTO customer (full_name, email) VALUES ('Areski Belaid', '[email protected]'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment