@byebyebymyai/database-proxy-sdk-prisma
v1.0.0
Published
Prisma driver adapter for database-proxy Connect RPC (multi-datasource SQL gateway)
Downloads
33
Maintainers
Readme
@byebyebymyai/database-proxy-sdk-prisma
Prisma driver adapter that runs all SQL through database-proxy over Connect RPC. Use it when Prisma should talk to your databases only via the gateway (auth, audit, pooling, multi–data-source routing).
Requirements
- Node.js 18+
- Prisma ORM 6.6+ or 7.x (driver adapters) with matching
@prisma/driver-adapter-utils(integration tests in this repo use Prisma 7 config layout) - A running database-proxy instance compatible with
proto/sqlgateway/v1/sqlgateway.proto - By default the client uses Connect JSON over HTTP (same as
curlwithContent-Type: application/json). SetuseBinaryFormat: trueonly if your server expects the binary codec.
Install
npm install @byebyebymyai/database-proxy-sdk-prismaPeer dependencies (install in your app):
@prisma/client@prisma/driver-adapter-utils
Prisma setup
- Set
datasource.providerto the real SQL dialect behind the gateway (postgresql,mysql, etc.). Prisma still generates that dialect; the gateway only executes SQL. - In Prisma 7, set
datasource.urlinprisma.config.tsto a syntactically valid URL for your provider (it can be a placeholder host; Prisma does not need a real TCP connection forprisma generate). Runtime SQL and migrations go through the adapter + gateway, not that URL. - Pass
DatabaseProxyAdapterFactorytoPrismaClientasadapter.
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model User {
id Int @id @default(autoincrement())
name String
}import { PrismaClient } from "@prisma/client";
import { DatabaseProxyAdapterFactory } from "@byebyebymyai/database-proxy-sdk-prisma";
const prisma = new PrismaClient({
adapter: new DatabaseProxyAdapterFactory({
baseUrl: "http://127.0.0.1:8080",
datasource: "dev",
provider: "postgres",
}),
});Multiple datasources
Use one factory (or adapter) per logical datasource—for example two PrismaClient instances with different datasource ids, matching how you configure DATABASE_PROXY_DATABASES_JSON on the gateway.
Auth (JWT)
import {
DatabaseProxyAdapterFactory,
getAuthorizationBearerInterceptor,
} from "@byebyebymyai/database-proxy-sdk-prisma";
const prisma = new PrismaClient({
adapter: new DatabaseProxyAdapterFactory({
baseUrl: "https://gateway.example.com",
datasource: "prod",
provider: "postgres",
interceptors: [getAuthorizationBearerInterceptor(() => process.env["GATEWAY_JWT"]!)],
}),
});For static headers (e.g. API keys), use getStaticHeadersInterceptor.
Migrations
executeScript sends the entire migration SQL in one gateway Execute call. Whether multi-statement scripts work depends on your database-proxy / JDBC backend (same as a single client batch).
For prisma migrate dev, set shadowDatasource on DatabaseProxyAdapterFactory to a second logical datasource id on the gateway that points at an isolated shadow database. Without it, connectToShadowDb throws. Never use the same datasource id as your main database.
Prisma + driver-adapter migrate remains sensitive to ORM version; this package is tested against the Prisma 7.x line used in this repo.
Updating generated RPC types
Protos are vendored under proto/ and compiled to src/gen/ with Buf.
npm run codegenWhen upstream sqlgateway.proto changes, copy the file into proto/sqlgateway/v1/sqlgateway.proto, then run npm run codegen, bump the package version, and test.
Testing
- Unit tests (CI default):
npm test/npm run test:unit— runsvitest.config.ts(src/**/*.test.ts,test/unit/**/*.test.ts). No external services. - Typecheck including tests:
npm run typecheck:test— runsprisma generatefor the integration schema (placeholder URL intest/integration/prisma/prisma.config.ts), thentsc -p tsconfig.test.json. - Integration tests (local / manual CI):
npm run test:integration— requires env vars and a live database-proxy; seetest/integration/README.md. Migration-oriented checks (Connect JSON wire +executeScript) live intest/integration/migrations.integration.test.ts.
Scripts
| Script | Description |
| ------------- | -------------------------- |
| npm run build | Build ESM + CJS + types |
| npm run test / test:unit | Unit tests (Vitest) |
| npm run test:integration | Integration tests + Prisma generate |
| npm run typecheck | tsc for src only |
| npm run typecheck:test | tsc for src + tests |
| npm run lint | Biome check |
| npm run codegen | Regenerate src/gen |
License
MIT. See LICENSE.
