Skip to content

teamreflex/drizzle-pg-proxy-bun

Repository files navigation

drizzle-pg-proxy-bun

Containerized Postgres HTTP proxy for Drizzle ORM, running on Bun with Hono.

Setup

$ git clone [email protected]:teamreflex/drizzle-pg-proxy-bun.git
$ cd drizzle-pg-proxy-bun
$ bun install
$ cp .env.example .env
$ docker compose up -d

Your Drizzle client can now connect to the proxy:

import { drizzle } from "drizzle-orm/pg-proxy";
import * as schema from "./schema";

export const db = drizzle(
  async (sql, params, method) => {
    try {
      const rows = await fetch(`http://localhost:8080/query`, {
        method: "POST",
        headers: {
          "proxy-key": process.env.PROXY_KEY,
        },
        body: JSON.stringify({ sql, params, method }),
        cache: "no-cache",
      }).then((res) => res.json());

      return { rows };
    } catch (err) {
      console.error("Error from Drizzle HTTP proxy: ", err);
      return { rows: [] };
    }
  },
  { schema }
);

License

Licensed under the MIT license.

About

HTTP proxy for Drizzle Postgres, running on Bun

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published