2018-10-05 18:13:51 +03:00
|
|
|
type: bulk
|
|
|
|
args:
|
|
|
|
|
|
|
|
#Author table
|
2021-01-06 19:06:24 +03:00
|
|
|
|
2018-10-05 18:13:51 +03:00
|
|
|
- type: run_sql
|
|
|
|
args:
|
|
|
|
sql: |
|
|
|
|
create table author(
|
2019-04-08 10:22:38 +03:00
|
|
|
id serial primary key,
|
|
|
|
name text unique,
|
2019-11-07 08:14:36 +03:00
|
|
|
is_registered boolean not null default false,
|
|
|
|
emails text[] not null default '{}'::text[]
|
2018-10-05 18:13:51 +03:00
|
|
|
);
|
|
|
|
CREATE TABLE article (
|
|
|
|
id SERIAL PRIMARY KEY,
|
|
|
|
title TEXT,
|
|
|
|
content TEXT,
|
|
|
|
author_id INTEGER REFERENCES author(id),
|
|
|
|
is_published BOOLEAN,
|
2020-02-04 18:34:17 +03:00
|
|
|
published_on TIMESTAMP,
|
|
|
|
tags JSON
|
|
|
|
);
|
2021-03-03 16:02:00 +03:00
|
|
|
create table author_detail(
|
|
|
|
id integer primary key references author(id),
|
|
|
|
phone text
|
|
|
|
);
|
2020-02-04 18:34:17 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2021-01-06 19:06:24 +03:00
|
|
|
- type: track_table
|
|
|
|
args:
|
|
|
|
schema: public
|
|
|
|
name: author
|
|
|
|
|
|
|
|
#Article table
|
2018-10-05 18:13:51 +03:00
|
|
|
- type: track_table
|
|
|
|
args:
|
|
|
|
schema: public
|
|
|
|
name: article
|
|
|
|
|
2021-03-03 16:02:00 +03:00
|
|
|
- type: track_table
|
|
|
|
args:
|
|
|
|
schema: public
|
|
|
|
name: author_detail
|
|
|
|
|
2018-10-05 18:13:51 +03:00
|
|
|
#Create relationships
|
|
|
|
- type: create_object_relationship
|
|
|
|
args:
|
|
|
|
table: article
|
|
|
|
name: author
|
|
|
|
using:
|
|
|
|
foreign_key_constraint_on: author_id
|
|
|
|
|
|
|
|
- type: create_array_relationship
|
|
|
|
args:
|
|
|
|
table: author
|
|
|
|
name: articles
|
|
|
|
using:
|
|
|
|
foreign_key_constraint_on:
|
|
|
|
table: article
|
|
|
|
column: author_id
|
2020-02-04 18:34:17 +03:00
|
|
|
|
|
|
|
# add a computed field
|
|
|
|
- type: add_computed_field
|
|
|
|
args:
|
|
|
|
table: author
|
|
|
|
name: fetch_articles
|
|
|
|
definition:
|
|
|
|
function: fetch_articles
|
|
|
|
table_argument: author_row
|
2021-03-03 16:02:00 +03:00
|
|
|
|
|
|
|
#Create relationships
|
|
|
|
- type: create_object_relationship
|
|
|
|
args:
|
|
|
|
table: author
|
|
|
|
name: detail_manual
|
|
|
|
using:
|
|
|
|
manual_configuration:
|
|
|
|
remote_table:
|
|
|
|
name: author_detail
|
|
|
|
schema: public
|
|
|
|
column_mapping:
|
|
|
|
id: id
|
|
|
|
insertion_order: after_parent
|
|
|
|
|
|
|
|
- type: create_object_relationship
|
|
|
|
args:
|
|
|
|
table: author
|
|
|
|
name: detail_fk
|
|
|
|
using:
|
|
|
|
foreign_key_constraint_on:
|
|
|
|
table: author_detail
|
|
|
|
column: id
|