···11+create type "public"."pull_result" as ("client_groups" json, "facts" json);
22+CREATE OR REPLACE FUNCTION public.pull_data(token_id uuid, client_group_id text)
33+ RETURNS pull_result
44+ LANGUAGE plpgsql
55+AS $function$
66+DECLARE
77+ result pull_result;
88+BEGIN
99+ -- Get client group data as JSON array
1010+ SELECT json_agg(row_to_json(rc))
1111+ FROM replicache_clients rc
1212+ WHERE rc.client_group = client_group_id
1313+ INTO result.client_groups;
1414+1515+ -- Get facts as JSON array
1616+ SELECT json_agg(row_to_json(f))
1717+ FROM permission_tokens pt,
1818+ get_facts(pt.root_entity) f
1919+ WHERE pt.id = token_id
2020+ INTO result.facts;
2121+2222+ RETURN result;
2323+END;
2424+$function$
2525+;