@bubblydoo/cloudflare-workers-postgres-client
    TypeScript icon, indicating that this package has built-in type declarations

    0.0.8 • Public • Published

    npm

    Cloudflare Workers Postgres Client

    This is an experimental module.

    Heavily based on cloudflare/worker-template-postgres, but cleaned up and bundled into a single module.

    This needs a Cloudflare Tunnel to your database running. To setup a Cloudflare Tunnel, you can use this docker-compose.yml.

    npm i @bubblydoo/cloudflare-workers-postgres-client
    # or
    yarn add @bubblydoo/cloudflare-workers-postgres-client
    import { Client } from '@bubblydoo/cloudflare-workers-postgres-client';
    
    const createClient = () => {
      return new Client({
        user: 'postgres',
        database: 'postgres',
        hostname: 'https://<YOUR CLOUDFLARE TUNNEL>',
        password: 'keyboardcat',
        port: 5432,
      });
    }
    
    const worker = {
      async fetch(request, env, ctx) {
        const client = createClient();
    
        await client.connect()
    
        const userIds = await client.queryArray('select id from "Users" limit 10');
    
        ctx.waitUntil(client.end());
    
        return new Response(JSON.stringify(userIds));
      }
    }
    
    export default worker;

    How it works

    It uses the postgres Deno module, bundles it, and adds some code to make it work with Cloudflare Workers.

    Keywords

    none

    Install

    npm i @bubblydoo/cloudflare-workers-postgres-client

    DownloadsWeekly Downloads

    34

    Version

    0.0.8

    License

    none

    Unpacked Size

    287 kB

    Total Files

    64

    Last publish

    Collaborators

    • siemenvdm
    • izidormaklary
    • oliverobrien
    • hansottowirtz