I just can't get it to work 😦 trying postgres package, also no success, error ``` [wrangler:err] Er

I just can't get it to work 😦 trying postgres package, also no success, error
[wrangler:err] Error: internal error
    at cachedError (/x/node_modules/postgres/cf/src/query.js:170:23)
    at new Query (/x/node_modules/postgres/cf/src/query.js:36:24)
    at sql2 (/x/node_modules/postgres/cf/src/index.js:113:11)
    at Object.fetch (/x/index.ts:9:23)


index.ts
import postgres from 'postgres';

export default {
  async fetch(request: Request, env: any) {
    const connectionString =
      env.DATABASE_URL || env.HYPERDRIVE.connectionString;
    console.log('fetch', request.url, env.DATABASE_URL);
    const sql = postgres(connectionString);
    const abc = await sql`SELECT * FROM tenant LIMIT 10`;
    console.log('abc', abc);

    return new Response(JSON.stringify({ ok: true }));
  },
};


package.json
{
  "name": "x",
  "dependencies": {
    "postgres": "^3.4.3"
  }
}


wrangler.toml
name = "xyz"
compatibility_flags = ["nodejs_compat"]
Was this page helpful?