chore: import upstream snapshot with attribution
Deploy (to testing) and Test Playground Preview Worker / Deploy Playground Preview Worker (testing) (push) Has been skipped
Deploy Workers Shared Staging / Deploy Workers Shared Staging (push) Failing after 0s
Prerelease / build (push) Has been skipped
Handle Changesets / Handle Changesets (push) Has been cancelled
Semgrep OSS scan / semgrep-oss (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 12:30:11 +08:00
commit 70bf21e064
5213 changed files with 731895 additions and 0 deletions
@@ -0,0 +1,39 @@
import { Client } from "pg";
interface Env {
DB_HOSTNAME: string;
DB_PORT: string;
DB_NAME: string;
DB_USERNAME: string;
DB_PASSWORD: string;
}
export default {
async fetch(request, env, ctx) {
const client = new Client({
user: env.DB_USERNAME,
password: env.DB_PASSWORD,
host: env.DB_HOSTNAME,
port: Number(env.DB_PORT),
database: env.DB_NAME,
});
const url = new URL(request.url);
if (url.pathname == "/send-query") {
return testPostgresLibrary(client, ctx);
} else {
return new Response(client.host);
}
},
} satisfies ExportedHandler<Env>;
async function testPostgresLibrary(client: Client, ctx: ExecutionContext) {
await client.connect();
const result = await client.query(`SELECT * FROM rnacen.rnc_database`);
// Return the first row as JSON
const resp = Response.json(result.rows[0]);
// Clean up the client
ctx.waitUntil(client.end());
return resp;
}
@@ -0,0 +1,16 @@
{
"name": "worker",
"main": "./index.ts",
"compatibility_date": "2024-12-30",
"compatibility_flags": ["nodejs_compat"],
// Default DB connection values point at 127.0.0.1.
// Tests override DB_HOSTNAME and DB_PORT at runtime via the vite config
// customizer to point at a local mock Postgres server.
"vars": {
"DB_HOSTNAME": "127.0.0.1",
"DB_PORT": "5432",
"DB_NAME": "testdb",
"DB_USERNAME": "testuser",
"DB_PASSWORD": "testpassword",
},
}