Registry / database / postgresdk

postgresdk

JSON →
library0.19.6jsnpmunverified

postgresdk is a code generation tool that produces a typed server/client SDK from a PostgreSQL database schema. At version 0.19.6 (under active development, not stable for production), it generates TypeScript types, Zod runtime validation, and a Hono server router with full CRUD, relationship loading, filtering, transactions, and built-in auth. Key differentiators: schema-driven generation eliminates boilerplate; includes pgvector vector search support; output is ESM-only with good tree-shaking. Release cadence is irregular (pre-v1). Alternative to Prisma, Drizzle ORM, or tRPC-style approaches.

npm install postgresdk
INSTALL
IMPORT
SIG · POSTGRESDK
P
postgresdk
databasejavascriptv0.19.6
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createRouter
import { createRouter } from './api/server/router'
const { createRouter } = require('./api/server/router')
Generated SDK is ESM-only. The path depends on your outDir config (default: `./api/server/router`).
SDK
import { SDK } from './api/client'
import SDK from './api/client'
SDK is a named export, not a default export. Ensure you use named import syntax.
postgresdk
npx postgresdk@latest generate
import postgresdk from 'postgresdk'
postgresdk is a CLI tool, not a library to import. Use via npx/pnpm dlx/bunx.

Shows how to set up a Hono server using the generated createRouter and use the client SDK to perform CRUD operations with relationship loading.

import { Hono } from 'hono'; import { Client } from 'pg'; import { createRouter } from './api/server/router'; import { SDK } from './api/client'; const app = new Hono(); const pg = new Client({ connectionString: process.env.DATABASE_URL ?? 'postgres://user:pass@localhost:5432/mydb' }); await pg.connect(); const api = createRouter({ pg }); app.route('/', api); // Client usage const sdk = new SDK({ baseUrl: 'http://localhost:3000' }); const user = await sdk.users.create({ name: 'Alice', email: 'alice@example.com' }); const users = await sdk.users.list({ include: { posts: true } }); console.log(users);
Debug
Known issues
gotchaSDK is a named export from the client file, not a default export. Using `import SDK from './api/client'` will fail.
fix
Use `import { SDK } from './api/client'`.
affects: >=0.18.0
gotchaGenerated server code depends on Hono. The package does not include Hono as a dependency — you must install it separately.
fix
Install Hono: `npm install hono` or `bun add hono`.
affects: >=0.1.0
gotchaThe `postgresdk` package is a CLI tool, not a runtime library. Attempting to import it in application code will fail.
fix
Use `npx postgresdk` or install as a devDependency and run via npm scripts.
affects: >=0.1.0
breakingThe output directory structure changed between v0.17 and v0.18. Router was moved from `./generated/server/router` to `./api/server/router`.
fix
Update import paths from `./generated/server/router` to `./api/server/router`.
affects: >=0.18.0
deprecatedThe `generate` command without `--config` flag may be deprecated in future versions. Always use explicit config file.
fix
Run `npx postgresdk generate --config postgresdk.config.ts` or ensure config file exists at project root.
affects: >=0.19.0
Errors
Common errors & fixes
Error: Cannot find module './api/server/router'
Import path mismatch after upgrading from v0.17 to v0.18; the output directory changed.
fix
Change import path from `./generated/server/router` to `./api/server/router`.
TypeError: sdk.users.create is not a function
SDK constructor was called without `new` or the SDK is imported incorrectly (default vs named).
fix
Ensure you use `import { SDK } from './api/client'` and instantiate with `new SDK({ baseUrl: '...' })`.
Error: Cannot find module 'hono'
Hono is not installed in the project, but it is required by the generated server code.
fix
Run `npm install hono` or `bun add hono`.
Error: No configuration file found. Run `postgresdk init` first.
Missing `postgresdk.config.ts` in the project root.
fix
Run `npx postgresdk init` to generate a config file, or create one manually.
Upgrade
Version history
0.19.6latest on npm
Audit
Dependencies
honorequiredServer SDK generates a Hono router — Hono must be installed in the consuming project.
pgrequiredRuntime dependency for connecting to PostgreSQL in both server and client SDK.
zodrequiredUsed for runtime validation of request/response payloads — generated code imports Zod.
Agent activity
9 hits · last 30 days
node
8
Resources
postgresdk — npm install postgresdk · libregistry