From a4d4f6879783aae38f16d4725ebc7be8b10a0866 Mon Sep 17 00:00:00 2001 From: Charis <26616127+charislam@users.noreply.github.com> Date: Tue, 30 Jan 2024 18:28:05 -0500 Subject: [PATCH] fix db connections for example edge functions (#20889) --- examples/edge-functions/supabase/.env.local.example | 6 ++++-- .../supabase/functions/kysely-postgres/index.ts | 4 ++-- .../supabase/functions/postgres-on-the-edge/.env.example | 2 +- .../supabase/functions/postgres-on-the-edge/index.ts | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/examples/edge-functions/supabase/.env.local.example b/examples/edge-functions/supabase/.env.local.example index a15cee971a7..d3f3566510b 100644 --- a/examples/edge-functions/supabase/.env.local.example +++ b/examples/edge-functions/supabase/.env.local.example @@ -11,11 +11,13 @@ IPINFO_TOKEN="your https://ipinfo.io token" OPENAI_API_KEY="" # postgres-on-the-edge & kysely-postgres +# get your DB params and cert from the project dashboard +# https://supabase.com/dashboard/project/_/settings/database +# enable `Use connection pooling` and use `Transaction` mode DB_HOSTNAME= DB_PASSWORD= +DB_USER= DB_SSL_CERT="-----BEGIN CERTIFICATE----- -GET YOUR CERT FROM YOUR PROJECT DASHBOARD -https://supabase.com/dashboard/project/_/settings/database -----END CERTIFICATE-----" # puppeteer diff --git a/examples/edge-functions/supabase/functions/kysely-postgres/index.ts b/examples/edge-functions/supabase/functions/kysely-postgres/index.ts index 4e91ef1df5b..c0d257dcee9 100644 --- a/examples/edge-functions/supabase/functions/kysely-postgres/index.ts +++ b/examples/edge-functions/supabase/functions/kysely-postgres/index.ts @@ -31,8 +31,8 @@ const pool = new Pool( tls: { caCertificates: [Deno.env.get('DB_SSL_CERT')!] }, database: 'postgres', hostname: Deno.env.get('DB_HOSTNAME'), - user: 'postgres', - port: 5432, + user: Deno.env.get('DB_USER'), + port: 6543, password: Deno.env.get('DB_PASSWORD'), }, 1 diff --git a/examples/edge-functions/supabase/functions/postgres-on-the-edge/.env.example b/examples/edge-functions/supabase/functions/postgres-on-the-edge/.env.example index 638351bc2c8..9cd063de1a6 100644 --- a/examples/edge-functions/supabase/functions/postgres-on-the-edge/.env.example +++ b/examples/edge-functions/supabase/functions/postgres-on-the-edge/.env.example @@ -1,2 +1,2 @@ #Use PolyScale connection string with application_name parameter to get code-free database caching -DATABASE_URL="postgresql:/DB_USERNAME:DB_PASSWORD@psedge.global:5432/postgres?application_name=POLYSCALE_CACHE_ID" \ No newline at end of file +DATABASE_URL="postgres://postgres.[PROJECT_REF]:[DB_PASSWORD]@psedge.global:5432?application_name=[APPLICATION_NAME]" diff --git a/examples/edge-functions/supabase/functions/postgres-on-the-edge/index.ts b/examples/edge-functions/supabase/functions/postgres-on-the-edge/index.ts index e8524f8a329..f8883ce3fb0 100644 --- a/examples/edge-functions/supabase/functions/postgres-on-the-edge/index.ts +++ b/examples/edge-functions/supabase/functions/postgres-on-the-edge/index.ts @@ -6,8 +6,8 @@ const pool = new Pool( tls: { enabled: false }, database: 'postgres', hostname: Deno.env.get('DB_HOSTNAME'), - user: 'postgres', - port: 5432, + user: Deno.env.get('DB_USER'), + port: 6543, password: Deno.env.get('DB_PASSWORD'), }, 1