telesto🌛
telesto🌛
DDeno
Created by telesto🌛 on 2/15/2025 in #help
databaseBindingMismatch when trying to promote a deployment to production
I've given up and deleted the project and just deployed it again, whatever, hope it stays working this time
7 replies
DDeno
Created by telesto🌛 on 2/15/2025 in #help
databaseBindingMismatch when trying to promote a deployment to production
and connection.ts is just
import 'jsr:@std/dotenv/load';
import * as postgres from 'https://deno.land/x/postgres@v0.19.3/mod.ts';

const databaseUrlTemplate = Deno.env.get('DATABASE_URL');
const rawPassword = Deno.env.get('DATABASE_PASSWORD');

if (!databaseUrlTemplate || !rawPassword) {
console.error('DATABASE_URL or DATABASE_PASSWORD is not set');
Deno.exit(1);
}

const databasePassword = encodeURIComponent(rawPassword);
const databaseUrl = databaseUrlTemplate.replace(
'[YOUR-PASSWORD]',
databasePassword,
);

export const pool = new postgres.Pool(databaseUrl, 3, true);
import 'jsr:@std/dotenv/load';
import * as postgres from 'https://deno.land/x/postgres@v0.19.3/mod.ts';

const databaseUrlTemplate = Deno.env.get('DATABASE_URL');
const rawPassword = Deno.env.get('DATABASE_PASSWORD');

if (!databaseUrlTemplate || !rawPassword) {
console.error('DATABASE_URL or DATABASE_PASSWORD is not set');
Deno.exit(1);
}

const databasePassword = encodeURIComponent(rawPassword);
const databaseUrl = databaseUrlTemplate.replace(
'[YOUR-PASSWORD]',
databasePassword,
);

export const pool = new postgres.Pool(databaseUrl, 3, true);
7 replies
DDeno
Created by telesto🌛 on 2/15/2025 in #help
databaseBindingMismatch when trying to promote a deployment to production
none of that tbh :D, I have not touched Deno.KV at all, the endpoints are just sth like
import { pool } from '../connection.ts';

export const getRestaurants = async () => {
const client = await pool.connect();

try {
const result = await client.queryObject(
'SELECT name, city FROM restaurants',
);
return result.rows;
} catch (error) {
console.error('Database query failed: ', error);
return [];
} finally {
client.release();
}
};
import { pool } from '../connection.ts';

export const getRestaurants = async () => {
const client = await pool.connect();

try {
const result = await client.queryObject(
'SELECT name, city FROM restaurants',
);
return result.rows;
} catch (error) {
console.error('Database query failed: ', error);
return [];
} finally {
client.release();
}
};
the Deno.KV differs only as far as I can see from a playground project that it also has a main and preview channel
7 replies
DDeno
Created by telesto🌛 on 2/15/2025 in #help
databaseBindingMismatch when trying to promote a deployment to production
hey đź‘‹ thanks for the reply, if I'm reading this right I should be fine with my async calls as there aren't as many
import { Application, Router } from '@oak/oak';
import { getRestaurants } from './endpoints/restaurants.ts';
import { getDeals } from './endpoints/deals.ts';

const router = new Router();

router.get('/restaurants', async (ctx) => {
const restaurants = await getRestaurants();
ctx.response.body = restaurants;
});

router.get('/deals', async (ctx) => {
const day = ctx.request.url.searchParams.get('day');
const city = ctx.request.url.searchParams.get('city');

if (!day || !city) {
ctx.response.status = 400;
ctx.response.body = {
error: `Both 'day' and 'city' parameters are required`,
};
return;
}

const deals = await getDeals(day, city);
ctx.response.body = deals;
});

const app = new Application();
app.use(router.routes());
app.use(router.allowedMethods());

await app.listen({});
import { Application, Router } from '@oak/oak';
import { getRestaurants } from './endpoints/restaurants.ts';
import { getDeals } from './endpoints/deals.ts';

const router = new Router();

router.get('/restaurants', async (ctx) => {
const restaurants = await getRestaurants();
ctx.response.body = restaurants;
});

router.get('/deals', async (ctx) => {
const day = ctx.request.url.searchParams.get('day');
const city = ctx.request.url.searchParams.get('city');

if (!day || !city) {
ctx.response.status = 400;
ctx.response.body = {
error: `Both 'day' and 'city' parameters are required`,
};
return;
}

const deals = await getDeals(day, city);
ctx.response.body = deals;
});

const app = new Application();
app.use(router.routes());
app.use(router.allowedMethods());

await app.listen({});
do you spot anything that's off?
7 replies
DDeno
Created by telesto🌛 on 2/9/2025 in #help
API server with Postgres on Deno Deploy ConnectionParamsError
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);
2 replies