telesto🌛
telesto🌛2w ago

API server with Postgres on Deno Deploy ConnectionParamsError

Hi everyone, I’ve been following the "API server with Postgres" tutorial (https://docs.deno.com/deploy/tutorials/tutorial-postgres/) and have set everything up successfully. For my project, I decided to go with Supabase. However, when I try to test the setup in the playground, I’m running into an error:
ConnectionParamsError: Missing connection parameters: database at assertRequiredOptions (https://deno.land/x/postgres@v0.19.3/connection/connection_params.ts:250:11) at createParams (https://deno.land/x/postgres@v0.19.3/connection/connection_params.ts:538:3) at new Pool (https://deno.land/x/postgres@v0.19.3/pool.ts:100:31) at file:///src/main.ts:11:14
this isn't mentioned anywhere how you would to this, the only env variable I've set is the one mentioned in the tutorial, has anyone tried this one before and can help me? I even tried a slightly different setup which fails in the same way
import { Pool } from "https://deno.land/x/postgres@v0.19.3/mod.ts";

Deno.serve(async (req) => {
return new Response("Not Found", { status: 404 });
});

// 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 Pool(databaseUrl, 3, true);

Deno.serve(async (_req) => {
try {
// Grab a connection from the pool
const connection = await pool.connect()

try {
// Run a query
const result = await connection.queryObject`SELECT * FROM animals`
const animals = result.rows
} finally {
// Release the connection back into the pool
connection.release()
}
} catch (err) {
console.error(err)
return new Response(String(err?.message ?? err), { status: 500 })
}
})
import { Pool } from "https://deno.land/x/postgres@v0.19.3/mod.ts";

Deno.serve(async (req) => {
return new Response("Not Found", { status: 404 });
});

// 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 Pool(databaseUrl, 3, true);

Deno.serve(async (_req) => {
try {
// Grab a connection from the pool
const connection = await pool.connect()

try {
// Run a query
const result = await connection.queryObject`SELECT * FROM animals`
const animals = result.rows
} finally {
// Release the connection back into the pool
connection.release()
}
} catch (err) {
console.error(err)
return new Response(String(err?.message ?? err), { status: 500 })
}
})
The screenshot is displayed next to the playground editor
No description
1 Reply
telesto🌛
telesto🌛OP2w ago
I found my mistake—it was caused by my password containing special characters that are not valid in a URL. This led to the admittedly confusing error. I'm now doing something like this:
const rawPassword = Deno.env.get('DATABASE_PASSWORD');
const databasePassword = encodeURIComponent(rawPassword);
const rawPassword = Deno.env.get('DATABASE_PASSWORD');
const databasePassword = encodeURIComponent(rawPassword);

Did you find this page helpful?