a tool for shared writing and social publishing
at feature/thread-viewer 32 lines 850 B view raw
1alter type public."pull_result" add attribute "publications" json; 2 3set check_function_bodies = off; 4 5CREATE OR REPLACE FUNCTION public.pull_data(token_id uuid, client_group_id text) 6 RETURNS pull_result 7 LANGUAGE plpgsql 8AS $function$DECLARE 9 result pull_result; 10BEGIN 11 -- Get client group data as JSON array 12 SELECT json_agg(row_to_json(rc)) 13 FROM replicache_clients rc 14 WHERE rc.client_group = client_group_id 15 INTO result.client_groups; 16 17 -- Get facts as JSON array 18 SELECT json_agg(row_to_json(f)) 19 FROM permission_tokens pt, 20 get_facts(pt.root_entity) f 21 WHERE pt.id = token_id 22 INTO result.facts; 23 24 -- Get publication data 25 SELECT json_agg(row_to_json(lip)) 26 FROM leaflets_in_publications lip 27 WHERE lip.leaflet = token_id 28 INTO result.publications; 29 30 RETURN result; 31END;$function$ 32;