Skip to content

Commit f1ec0e0

Browse files
committed
Demo script.
1 parent 15eeeb3 commit f1ec0e0

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

demo.sql

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
\include_relative graphql.sql
2+
\include_relative fb/schema.sql
3+
\include_relative fb/data.sql
4+
5+
\x auto
6+
7+
\C Consumers:
8+
SELECT * FROM consumer;
9+
10+
\C Friendships:
11+
SELECT friendship.*, l._||' -> '||r._ AS who FROM friendship,
12+
LATERAL (SELECT full_name FROM consumer WHERE first = id) AS l(_),
13+
LATERAL (SELECT full_name FROM consumer WHERE second = id) AS r(_);
14+
15+
DO $$
16+
DECLARE
17+
graphql_q text = 'consumer("f3411edc-e1d0-452a-bc19-b42c0d5a0e36") {'
18+
' full_name,'
19+
' friendship'
20+
'}';
21+
sql_q text;
22+
result json;
23+
msg text;
24+
BEGIN
25+
RAISE INFO E'GraphQL to parse:\n%\n', graphql_q;
26+
SELECT * INTO STRICT sql_q FROM graphql.to_sql(graphql_q);
27+
RAISE INFO E'SQL that will be run:\n%\n', sql_q;
28+
EXECUTE sql_q INTO STRICT result;
29+
RAISE INFO E'Result:\n%\n', result;
30+
END
31+
$$;
32+
33+
BEGIN;
34+
SET LOCAL client_min_messages TO ERROR;
35+
DROP SCHEMA graphql CASCADE;
36+
DROP SCHEMA fb CASCADE;
37+
END;

0 commit comments

Comments
 (0)