diff --git a/examples/edge-functions/supabase/.env.local.example b/examples/edge-functions/supabase/.env.local.example index 0031244f9f3..ed44709092f 100644 --- a/examples/edge-functions/supabase/.env.local.example +++ b/examples/edge-functions/supabase/.env.local.example @@ -11,7 +11,8 @@ IPINFO_TOKEN="your https://ipinfo.io token" OPENAI_API_KEY="" # postgres-on-the-edge -DATABASE_URL= +DB_HOSTNAME= +DB_PASSWORD= # puppeteer PUPPETEER_BROWSERLESS_IO_TOKEN= diff --git a/examples/edge-functions/supabase/functions/import_map.json b/examples/edge-functions/supabase/functions/import_map.json index be4b4d84118..de16ef14e67 100644 --- a/examples/edge-functions/supabase/functions/import_map.json +++ b/examples/edge-functions/supabase/functions/import_map.json @@ -11,7 +11,7 @@ "stripe": "https://esm.sh/stripe@11.1.0?target=deno", "sift": "https://deno.land/x/sift@0.6.0/mod.ts", "@supabase/supabase-js": "https://esm.sh/@supabase/supabase-js@2.7.1", - "postgres": "https://deno.land/x/postgres@v0.14.2/mod.ts", + "postgres": "https://deno.land/x/postgres@v0.17.0/mod.ts", "puppeteer": "https://deno.land/x/puppeteer@16.2.0/mod.ts", "React": "https://esm.sh/react@18.2.0?deno-std=0.177.0", "upstash_redis": "https://deno.land/x/upstash_redis@v1.19.3/mod.ts", 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 871d24679fe..2c950dfef4a 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 @@ -1,11 +1,18 @@ -import * as postgres from 'postgres' +import { Pool } from 'postgres' import { serve } from 'std/server' -// Get the connection string from the environment variable "DATABASE_URL" -const databaseUrl = Deno.env.get('DATABASE_URL')! - -// Create a database pool with three connections that are lazily established -const pool = new postgres.Pool(databaseUrl, 3, true) +// Create a database pool with one connection. +const pool = new Pool( + { + tls: { enabled: false }, + database: 'postgres', + hostname: Deno.env.get('DB_HOSTNAME'), + user: 'postgres', + port: 5432, + password: Deno.env.get('DB_PASSWORD'), + }, + 1 +) serve(async (_req) => { try { @@ -16,7 +23,6 @@ serve(async (_req) => { // Run a query const result = await connection.queryObject`SELECT * FROM animals` const animals = result.rows // [{ id: 1, name: "Lion" }, ...] - console.log(animals) // Encode the result as pretty printed JSON const body = JSON.stringify(