Skip to content

Persons

Josef Gabrielsson edited this page Aug 26, 2021 · 32 revisions

Persons

API

URL: https://gqfktgknxmguhxgkajat.supabase.co

Key: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTYyMDc2MTg0NCwiZXhwIjoxOTM2MzM3ODQ0fQ.xEa_GuNypFdHSdQVLCd0beoL_v8jhWKjSTypX6kn-sg

Policies

create policy "Public persons are viewable by everyone." on persons for select using (true);

create policy "Persons can update their own information." on persons for update using (auth.uid() = user_id);

Queries

Living people

https://gqfktgknxmguhxgkajat.supabase.co/rest/v1/persons?count&and=(death.not.is.null)

Dead people

https://gqfktgknxmguhxgkajat.supabase.co/rest/v1/persons?count&and=(death.is.null)

Stored Procedures

Persons

https://gqfktgknxmguhxgkajat.supabase.co/rest/v1/rpc/persons

  • Alive
  • Dead

CREATE OR REPLACE FUNCTION persons()
RETURNS TABLE(alive bigint, dead bigint) AS $$
BEGIN
  RETURN QUERY
  SELECT
  SUM(1) FILTER (WHERE death IS NULL) AS alive,
  SUM(1) FILTER (WHERE death IS NOT NULL) AS dead
  FROM persons;
END
$$ LANGUAGE plpgsql;

Foreign Data Wrappers

X2

CREATE SERVER x2
FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (host 'db.snoulbshaqjnlgwfevpz.supabase.co', port '5432', dbname 'postgres');

CREATE USER MAPPING FOR local_user
SERVER x2
OPTIONS (user 'foreign_user', password 'password');

DROP FOREIGN TABLE foreign_countries;
CREATE FOREIGN TABLE foreign_countries (
id integer NOT NULL,
country json
)
SERVER x2
OPTIONS (schema_name 'public', table_name 'countries');

Persons

Clone this wiki locally