2019-10-18 11:29:47 +03:00
|
|
|
type: bulk
|
|
|
|
args:
|
2021-01-06 19:06:24 +03:00
|
|
|
|
2019-10-18 11:29:47 +03:00
|
|
|
- type: run_sql
|
|
|
|
args:
|
|
|
|
sql: |
|
|
|
|
CREATE TABLE author(
|
|
|
|
id SERIAL PRIMARY KEY,
|
|
|
|
first_name TEXT NOT NULL,
|
|
|
|
last_name TEXT
|
|
|
|
);
|
|
|
|
|
|
|
|
INSERT INTO author (first_name, last_name)
|
|
|
|
VALUES ('Roger', 'Chris'), ('Daniel', NULL);
|
|
|
|
|
|
|
|
CREATE TABLE article(
|
|
|
|
id SERIAL PRIMARY KEY,
|
|
|
|
title TEXT NOT NULL,
|
|
|
|
content TEXT,
|
|
|
|
author_id INTEGER NOT NULL REFERENCES author(id)
|
|
|
|
);
|
|
|
|
|
|
|
|
INSERT INTO article (title, content, author_id)
|
|
|
|
VALUES
|
|
|
|
('Article 1', 'Content for Article 1', 1),
|
|
|
|
('Article 2', 'Content for Article 2', 2),
|
|
|
|
('Article 3', 'Content for Article 3', 2);
|
|
|
|
|
|
|
|
CREATE FUNCTION fetch_articles(search text, author_row author)
|
|
|
|
RETURNS SETOF article AS $$
|
|
|
|
SELECT *
|
|
|
|
FROM article
|
|
|
|
WHERE
|
|
|
|
( title ilike ('%' || search || '%')
|
|
|
|
OR content ilike ('%' || search || '%')
|
|
|
|
) AND author_id = author_row.id
|
|
|
|
$$ LANGUAGE sql STABLE;
|
|
|
|
|
|
|
|
CREATE FUNCTION fetch_articles_volatile(search text, author_row author)
|
|
|
|
RETURNS SETOF article AS $$
|
|
|
|
SELECT *
|
|
|
|
FROM article
|
|
|
|
WHERE
|
|
|
|
( title ilike ('%' || search || '%')
|
|
|
|
OR content ilike ('%' || search || '%')
|
|
|
|
) AND author_id = author_row.id
|
|
|
|
$$ LANGUAGE sql VOLATILE;
|
|
|
|
|
|
|
|
CREATE FUNCTION full_name(author)
|
|
|
|
RETURNS TEXT AS $$
|
|
|
|
DECLARE
|
|
|
|
first_name text;
|
|
|
|
last_name text;
|
|
|
|
full_name text;
|
|
|
|
BEGIN
|
|
|
|
first_name := $1.first_name;
|
|
|
|
last_name := $1.last_name;
|
|
|
|
IF last_name IS NULL THEN
|
|
|
|
full_name := first_name;
|
|
|
|
ELSE full_name := first_name || ' ' || last_name;
|
|
|
|
END IF;
|
|
|
|
RETURN full_name;
|
|
|
|
END;
|
|
|
|
$$ LANGUAGE plpgsql STABLE;
|
|
|
|
|
|
|
|
CREATE FUNCTION hello_world()
|
|
|
|
RETURNS TEXT AS $$
|
|
|
|
SELECT 'Hello, World!'::text
|
|
|
|
$$ LANGUAGE sql STABLE;
|
|
|
|
|
2020-04-27 18:07:03 +03:00
|
|
|
CREATE FUNCTION test_session(author_row author, key text, session json)
|
|
|
|
RETURNS TEXT AS $$
|
|
|
|
SELECT $3->>$2
|
|
|
|
$$ LANGUAGE sql STABLE;
|
|
|
|
|
2019-10-18 11:29:47 +03:00
|
|
|
- type: track_table
|
|
|
|
args:
|
|
|
|
name: author
|
|
|
|
schema: public
|
|
|
|
|
|
|
|
- type: track_table
|
|
|
|
args:
|
|
|
|
name: article
|
|
|
|
schema: public
|