Giter Site home page Giter Site logo

neondatabase / serverless-cfworker-demo Goto Github PK

View Code? Open in Web Editor NEW
23.0 2.0 5.0 225 KB

Demo app for @neondatabase/serverless — details at https://blog.cloudflare.com/neon-postgres-database-from-workers/

Home Page: https://places-neon-demo.pages.dev/

TypeScript 33.06% HTML 66.94%
cloudflare cloudflare-workers database javascript neon pg postgres postgresql serverless sql

serverless-cfworker-demo's People

Contributors

jawj avatar kelvich avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

serverless-cfworker-demo's Issues

I am getting the following error, how to resolve?

code:

import { Client } from '@neondatabase/serverless';
interface Env { DATABASE_URL: string; }

export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext) {
const client = new Client(env.DATABASE_URL);
await client.connect();
const { rows: [{ now }] } = await client.query('select now();');
ctx.waitUntil(client.end()); // this doesn’t hold up the response
return new Response(now);
}
}

error:

wrangler dev
Delegating to locally-installed [email protected] over global [email protected]...
Run npx wrangler dev to use the local version directly.

⛅️ wrangler 2.12.0 (update available 2.13.0)

⬣ Listening at http://0.0.0.0:8787

  • http://127.0.0.1:8787
  • http://192.168.1.19:8787
    Total Upload: 220.65 KiB / gzip: 54.03 KiB
    A hanging Promise was canceled. This happens when the worker runtime is waiting for a Promise from JavaScript to resolve, but has detected that the Promise cannot possibly ever resolve because all code and events related to the Promise's I/O context have already finished.
    1:28:37 AM GET / 500
    ✘ [ERROR] Uncaught (in response) Error: The script will never generate a response.

Connection Pool Instead of (or in addition to) Client

Creating a new client / calling client.connect() for every request / cron trigger in a Cloudflare worker (or any codebase) is not ideal. I suggest updating the demo to use a connection pool instead. Alternatively, give a second demo with connection pools.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.