a tool for shared writing and social publishing
1create type "public"."pull_result" as ("client_groups" json, "facts" json);
2CREATE OR REPLACE FUNCTION public.pull_data(token_id uuid, client_group_id text)
3 RETURNS pull_result
4 LANGUAGE plpgsql
5AS $function$
6DECLARE
7 result pull_result;
8BEGIN
9 -- Get client group data as JSON array
10 SELECT json_agg(row_to_json(rc))
11 FROM replicache_clients rc
12 WHERE rc.client_group = client_group_id
13 INTO result.client_groups;
14
15 -- Get facts as JSON array
16 SELECT json_agg(row_to_json(f))
17 FROM permission_tokens pt,
18 get_facts(pt.root_entity) f
19 WHERE pt.id = token_id
20 INTO result.facts;
21
22 RETURN result;
23END;
24$function$
25;