Open NathanFlurry opened 3 months ago
To implement the feature to force pg-cloudflare, follow these steps:
Modify src/runtime/deps.ts
:
node-postgres
library to add an option to force pg-cloudflare
.export { QueryClient, Transaction } from "https://your-forked-repo-url/mod.ts";
Update src/runtime/postgres.ts
:
getOrCreatePool
method to accept a flag for forcing pg-cloudflare
.Modify the pool creation logic to use this flag.
public getOrCreatePool(module: Module, forceCloudflare: boolean = false): Pool | undefined {
if (!module.db) return undefined;
if (this.isShutDown) throw new Error("Postgres is shutting down");
if (this.pools.has(module.db.name)) {
return this.pools.get(module.db.name)!;
} else {
const url = getDatabaseUrl(module.db.name).toString();
// Create & insert pool
const output = module.db.createPrisma(url, { forceCloudflare });
const pool = {
prisma: output.prisma,
pgPool: output.pgPool,
} as Pool;
this.pools.set(module.db.name, pool);
return pool;
}
}
Update createPrisma
method in the relevant module:
forceCloudflare
option.
function createPrisma(url: string, options: { forceCloudflare: boolean }) {
// Logic to force pg-cloudflare based on the options
}
@NathanFlurry I would like to work upon this issue
Motivation
Currently, we depend on node-postgres automagically detecting the Cloudflare runtime by:
Implementation
We shouldn't have to force our user agent to Cloudflare. We should allow passing in a string forcing it to use pg-cloudflare.