2019-01-25 06:31:54 +03:00
|
|
|
type: bulk
|
|
|
|
args:
|
|
|
|
|
|
|
|
#Article table
|
2021-01-06 19:06:24 +03:00
|
|
|
|
2019-01-25 06:31:54 +03:00
|
|
|
- type: run_sql
|
|
|
|
args:
|
|
|
|
sql: |
|
|
|
|
create table post (
|
|
|
|
id serial PRIMARY KEY,
|
|
|
|
title TEXT,
|
|
|
|
content TEXT
|
2021-01-06 19:06:24 +03:00
|
|
|
);
|
2019-01-25 06:31:54 +03:00
|
|
|
create function search_posts(search text)
|
|
|
|
returns setof post as $$
|
|
|
|
select *
|
|
|
|
from post
|
|
|
|
where
|
|
|
|
title ilike ('%' || search || '%') or
|
|
|
|
content ilike ('%' || search || '%')
|
|
|
|
$$ language sql stable;
|
|
|
|
insert into post (title, content)
|
|
|
|
values
|
|
|
|
('post by hasura', 'content for post'),
|
2021-01-06 19:06:24 +03:00
|
|
|
('post by another', 'content for another post');
|
2019-04-08 09:58:56 +03:00
|
|
|
create table test(
|
|
|
|
id serial primary key,
|
|
|
|
name text not null,
|
|
|
|
uuid_col uuid not null
|
|
|
|
);
|
|
|
|
|
|
|
|
insert into test (name, uuid_col) values
|
|
|
|
('clarke', '8e3e4a14-c831-45a2-9e78-8e86028d1ee5')
|
|
|
|
,('michael', '8e3e4a14-c831-45a2-9e78-8e86028d1ee5')
|
|
|
|
,('fitch', '8e3e4a14-c831-45a2-9e78-8e86028d1ee6') ;
|
|
|
|
|
|
|
|
create function get_test(uuid_arg uuid, name_arg text)
|
|
|
|
returns setof test as $$
|
|
|
|
select * from test where uuid_col = uuid_arg and name = name_arg
|
|
|
|
$$ language sql stable;
|
|
|
|
|
2019-12-27 01:32:48 +03:00
|
|
|
create function get_test_session_id(hasura_session json)
|
2021-02-03 17:06:30 +03:00
|
|
|
returns test as $$
|
2019-12-27 01:32:48 +03:00
|
|
|
select * from test where id = (hasura_session ->> 'x-hasura-user-id')::Int
|
|
|
|
$$ language sql stable;
|
2019-06-04 15:43:28 +03:00
|
|
|
CREATE TABLE integer_column
|
|
|
|
(
|
|
|
|
result integer
|
|
|
|
);
|
2019-04-08 09:58:56 +03:00
|
|
|
|
2019-06-04 15:43:28 +03:00
|
|
|
CREATE FUNCTION my_add (first integer, second integer DEFAULT 10)
|
|
|
|
RETURNS SETOF integer_column as $$
|
|
|
|
SELECT q.* FROM (VALUES (first + second)) as q
|
|
|
|
$$ LANGUAGE SQL STABLE;
|
2019-08-28 22:27:15 +03:00
|
|
|
CREATE TABLE "user" (
|
|
|
|
id SERIAL PRIMARY KEY,
|
|
|
|
name TEXT NOT NULL,
|
|
|
|
is_admin BOOLEAN DEFAULT FALSE
|
|
|
|
);
|
|
|
|
INSERT INTO "user" (name, is_admin) VALUES
|
|
|
|
('Starke Blake', true)
|
|
|
|
, ('Bellamy Blake', true)
|
|
|
|
, ('Dora Blake', true)
|
|
|
|
;
|
|
|
|
CREATE FUNCTION get_users(search text, integer default 10, boolean default false)
|
|
|
|
RETURNS SETOF "user" AS $$
|
|
|
|
SELECT *
|
|
|
|
FROM "user"
|
|
|
|
WHERE
|
|
|
|
name ilike ('%' || search || '%')
|
|
|
|
AND is_admin = $3
|
|
|
|
LIMIT $2
|
|
|
|
$$ LANGUAGE sql STABLE;
|
2019-11-20 09:47:06 +03:00
|
|
|
CREATE TABLE text_result(
|
|
|
|
result text
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE FUNCTION get_session_var(hasura_session json, session_var text)
|
|
|
|
RETURNS SETOF text_result AS $$
|
|
|
|
SELECT q.* FROM (VALUES (hasura_session ->> session_var)) q
|
|
|
|
$$ LANGUAGE sql STABLE;
|
2020-10-22 16:26:42 +03:00
|
|
|
CREATE TABLE author(
|
|
|
|
id SERIAL PRIMARY KEY,
|
|
|
|
first_name TEXT,
|
|
|
|
last_name TEXT
|
|
|
|
);
|
|
|
|
|
|
|
|
INSERT INTO author(first_name, last_name) VALUES
|
|
|
|
('enid', 'blyton'),
|
|
|
|
('ruskin', 'bond'),
|
|
|
|
('franz', 'kafka');
|
|
|
|
|
|
|
|
CREATE MATERIALIZED VIEW author_mat_view AS
|
|
|
|
SELECT * FROM author;
|
|
|
|
|
|
|
|
CREATE FUNCTION search_author_mview(query text)
|
|
|
|
RETURNS SETOF author_mat_view AS $FUNCTION$
|
|
|
|
SELECT * FROM author_mat_view WHERE
|
|
|
|
first_name = query OR
|
|
|
|
last_name = query
|
|
|
|
$FUNCTION$ LANGUAGE sql STABLE;
|
|
|
|
|
2021-01-06 19:06:24 +03:00
|
|
|
- type: track_table
|
|
|
|
args:
|
|
|
|
schema: public
|
|
|
|
name: post
|
|
|
|
|
|
|
|
#Search post function
|
|
|
|
- type: track_function
|
|
|
|
args:
|
|
|
|
name: search_posts
|
|
|
|
schema: public
|
|
|
|
|
|
|
|
#Insert values
|
|
|
|
- type: track_table
|
|
|
|
args:
|
|
|
|
name: test
|
|
|
|
schema: public
|
|
|
|
|
|
|
|
- type: track_function
|
|
|
|
args:
|
|
|
|
name: get_test
|
|
|
|
schema: public
|
|
|
|
- type: track_function
|
|
|
|
version: 2
|
|
|
|
args:
|
|
|
|
function:
|
|
|
|
name: get_test_session_id
|
|
|
|
schema: public
|
|
|
|
configuration:
|
|
|
|
session_argument: hasura_session
|
|
|
|
|
|
|
|
# custom add sql function
|
|
|
|
- type: track_table
|
|
|
|
args:
|
|
|
|
name: integer_column
|
|
|
|
schema: public
|
|
|
|
|
|
|
|
- type: track_function
|
|
|
|
args:
|
|
|
|
name: my_add
|
|
|
|
schema: public
|
|
|
|
|
|
|
|
# test functions having multiple defaults
|
|
|
|
- type: track_table
|
|
|
|
args:
|
|
|
|
name: user
|
|
|
|
schema: public
|
|
|
|
|
|
|
|
- type: track_function
|
|
|
|
args:
|
|
|
|
name: get_users
|
|
|
|
schema: public
|
|
|
|
|
|
|
|
# V2 Functions
|
|
|
|
- type: track_table
|
|
|
|
args:
|
|
|
|
name: text_result
|
|
|
|
schema: public
|
|
|
|
|
|
|
|
- type: track_function
|
|
|
|
version: 2
|
|
|
|
args:
|
|
|
|
function:
|
|
|
|
schema: public
|
|
|
|
name: get_session_var
|
|
|
|
configuration:
|
|
|
|
session_argument: hasura_session
|
|
|
|
|
|
|
|
# track & query functions that return SETOF materialized views
|
2020-10-22 16:26:42 +03:00
|
|
|
- type: track_table
|
|
|
|
args:
|
|
|
|
name: author
|
|
|
|
schema: public
|
|
|
|
|
|
|
|
- type: track_table
|
|
|
|
args:
|
|
|
|
name: author_mat_view
|
|
|
|
schema: public
|
|
|
|
|
|
|
|
- type: track_function
|
|
|
|
version: 2
|
|
|
|
args:
|
|
|
|
function:
|
|
|
|
schema: public
|
|
|
|
name: search_author_mview
|