mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 12:31:52 +03:00
312e56dfa6
GitOrigin-RevId: fbf99816a70e666bb9b02fca92a0ee7d419cdff8
187 lines
4.3 KiB
YAML
187 lines
4.3 KiB
YAML
type: bulk
|
|
args:
|
|
|
|
#Article table
|
|
|
|
- type: run_sql
|
|
args:
|
|
sql: |
|
|
create table post (
|
|
id serial PRIMARY KEY,
|
|
title TEXT,
|
|
content TEXT
|
|
);
|
|
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'),
|
|
('post by another', 'content for another post');
|
|
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;
|
|
|
|
create function get_test_session_id(hasura_session json)
|
|
returns test as $$
|
|
select * from test where id = (hasura_session ->> 'x-hasura-user-id')::Int
|
|
$$ language sql stable;
|
|
CREATE TABLE integer_column
|
|
(
|
|
result integer
|
|
);
|
|
|
|
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;
|
|
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;
|
|
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;
|
|
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;
|
|
|
|
- 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
|
|
- 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
|