Containerized Postgres HTTP proxy for Drizzle ORM, running on Bun with Hono.
$ 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 }
);
Licensed under the MIT license.