mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 04:51:35 +03:00
72 lines
1.7 KiB
YAML
72 lines
1.7 KiB
YAML
|
type: bulk
|
||
|
args:
|
||
|
|
||
|
- type: run_sql
|
||
|
args:
|
||
|
sql: |
|
||
|
create table author(
|
||
|
id serial primary key,
|
||
|
name text unique,
|
||
|
is_registered boolean not null default false,
|
||
|
remarks_internal text
|
||
|
);
|
||
|
|
||
|
INSERT INTO author (name, remarks_internal)
|
||
|
VALUES
|
||
|
('Author 1', 'remark 1'),
|
||
|
('Author 2', 'remark 2'),
|
||
|
('Author 3', 'remark 3');
|
||
|
|
||
|
CREATE TABLE article (
|
||
|
id SERIAL PRIMARY KEY,
|
||
|
title TEXT,
|
||
|
content TEXT,
|
||
|
author_id INTEGER NOT NULL REFERENCES author(id),
|
||
|
is_published BOOLEAN NOT NULL default FALSE,
|
||
|
published_on TIMESTAMP
|
||
|
);
|
||
|
|
||
|
INSERT INTO article (title, content, author_id, is_published)
|
||
|
VALUES
|
||
|
('Article 1', 'Sample article content 1', 1, false),
|
||
|
('Article 2', 'Sample article content 2', 1, true),
|
||
|
('Article 3', 'Sample article content 3', 2, true),
|
||
|
('Article 4', 'Sample article content 4', 3, false);
|
||
|
|
||
|
CREATE FUNCTION get_articles(search text)
|
||
|
RETURNS SETOF article AS $$
|
||
|
SELECT *
|
||
|
FROM article
|
||
|
WHERE
|
||
|
title ilike ('%' || search || '%')
|
||
|
OR content ilike ('%' || search || '%')
|
||
|
$$ LANGUAGE sql STABLE;
|
||
|
|
||
|
- type: track_table
|
||
|
args:
|
||
|
table: author
|
||
|
|
||
|
- type: track_table
|
||
|
args:
|
||
|
table: article
|
||
|
|
||
|
- type: track_function
|
||
|
args:
|
||
|
name: get_articles
|
||
|
schema: public
|
||
|
|
||
|
- type: create_select_permission
|
||
|
args:
|
||
|
table: article
|
||
|
role: user
|
||
|
permission:
|
||
|
columns:
|
||
|
- title
|
||
|
- content
|
||
|
- is_published
|
||
|
filter:
|
||
|
_or:
|
||
|
- id: X-HASURA-USER-ID
|
||
|
- is_published:
|
||
|
_eq: true
|