postgresdk 0.3.0 → 0.5.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -139,7 +139,7 @@ All from your existing database schema. No manual coding required.
139
139
  - 🔗 **Smart Relationships** - Automatic handling of 1:N and M:N relationships with eager loading
140
140
  - 🔐 **Built-in Auth** - API key and JWT authentication with zero configuration
141
141
  - 🎯 **Zero Config** - Works out of the box with sensible defaults
142
- - 🏗️ **Framework Ready** - Server routes built for Hono, client SDK works anywhere
142
+ - 🏗️ **Framework Ready** - Server routes for Hono (Express & Fastify coming soon), client SDK works anywhere
143
143
  - 📦 **Lightweight** - Minimal dependencies, optimized bundle size with shared BaseClient
144
144
  - 🔄 **SDK Distribution** - Built-in SDK bundling and pull mechanism for easy client distribution
145
145
 
@@ -218,6 +218,8 @@ export default {
218
218
  softDeleteColumn: null, // Column name for soft deletes (e.g., "deleted_at")
219
219
  includeDepthLimit: 3, // Max depth for nested includes
220
220
  dateType: "date", // "date" | "string" - How to handle timestamps
221
+ serverFramework: "hono", // "hono" | "express" | "fastify" (currently only hono)
222
+ useJsExtensions: false, // Add .js to imports (for Vercel Edge, Deno)
221
223
 
222
224
  // Authentication (optional) - simplified syntax
223
225
  auth: {
@@ -493,6 +495,126 @@ const sdk = new SDK({
493
495
  });
494
496
  ```
495
497
 
498
+ ## Database Drivers
499
+
500
+ The generated code works with any PostgreSQL client that implements a simple `query` interface. You can use the standard `pg` driver, Neon's serverless driver, or any other compatible client.
501
+
502
+ ### Node.js `pg` Driver
503
+
504
+ The standard PostgreSQL driver for Node.js environments. Works everywhere Node.js runs.
505
+
506
+ Server setup:
507
+ ```typescript
508
+ import { Hono } from "hono";
509
+ import { Client } from "pg";
510
+ import { createRouter } from "./generated/server/router";
511
+
512
+ const app = new Hono();
513
+
514
+ // Standard pg client
515
+ const pg = new Client({ connectionString: process.env.DATABASE_URL });
516
+ await pg.connect();
517
+
518
+ // Wire up the generated routes
519
+ const apiRouter = createRouter({ pg });
520
+ app.route("/", apiRouter);
521
+ ```
522
+
523
+ ### Neon Serverless Driver (Edge-Compatible)
524
+
525
+ For edge environments like Vercel Edge Functions or Cloudflare Workers. Uses HTTP/WebSocket instead of TCP connections.
526
+
527
+ Configuration for Vercel Edge:
528
+ ```typescript
529
+ // postgresdk.config.ts
530
+ export default {
531
+ connectionString: process.env.DATABASE_URL,
532
+ serverFramework: "hono", // Hono is edge-compatible
533
+ useJsExtensions: true, // Required for Vercel Edge
534
+ dateType: "string", // Better for JSON serialization
535
+ auth: { apiKey: process.env.API_KEY }
536
+ };
537
+ ```
538
+
539
+ Server setup:
540
+ ```typescript
541
+ import { Hono } from "hono";
542
+ import { Pool } from "@neondatabase/serverless";
543
+ import { createRouter } from "./generated/server/router";
544
+
545
+ const app = new Hono();
546
+
547
+ // Neon's Pool is compatible with node-postgres
548
+ const pool = new Pool({ connectionString: process.env.DATABASE_URL! });
549
+
550
+ // Wire up the generated routes (Pool has the same query interface)
551
+ const apiRouter = createRouter({ pg: pool });
552
+ app.route("/", apiRouter);
553
+
554
+ // Deploy to Vercel Edge
555
+ export const config = { runtime: 'edge' };
556
+ export default app;
557
+ ```
558
+
559
+ ### Which Driver Should I Use?
560
+
561
+ - **Use `pg` (default) when:**
562
+ - Running on traditional Node.js servers
563
+ - Using Docker, VPS, or dedicated hosting
564
+ - Need connection pooling or advanced PostgreSQL features
565
+ - Running on AWS Lambda, Google Cloud Functions (with Node.js runtime)
566
+
567
+ - **Use `neon` when:**
568
+ - Deploying to Vercel Edge Functions
569
+ - Deploying to Cloudflare Workers
570
+ - Need globally distributed edge computing
571
+ - Want to avoid TCP connection overhead
572
+ - Using Neon as your PostgreSQL provider
573
+
574
+ ### Connection Pooling with `pg`
575
+
576
+ For production Node.js deployments, use connection pooling:
577
+
578
+ ```typescript
579
+ import { Pool } from "pg";
580
+ import { createRouter } from "./generated/server/router";
581
+
582
+ const pool = new Pool({
583
+ connectionString: process.env.DATABASE_URL,
584
+ max: 20,
585
+ idleTimeoutMillis: 30000,
586
+ connectionTimeoutMillis: 2000,
587
+ });
588
+
589
+ // The generated routes work with both Client and Pool
590
+ const apiRouter = createRouter({ pg: pool });
591
+ ```
592
+
593
+ ### Custom Database Adapters
594
+
595
+ You can use any database client as long as it matches the expected interface:
596
+
597
+ ```typescript
598
+ // Any client that implements this interface works
599
+ interface DatabaseAdapter {
600
+ query(text: string, params?: any[]): Promise<{ rows: any[] }>;
601
+ }
602
+
603
+ // Both pg and @neondatabase/serverless Pool/Client implement this interface natively
604
+ // For other ORMs, you may need to create an adapter:
605
+
606
+ // Example with a hypothetical ORM that doesn't match the interface
607
+ const customClient = new SomeORM();
608
+ const pg = {
609
+ async query(text: string, params?: any[]) {
610
+ const result = await customClient.raw(text, params);
611
+ return { rows: result };
612
+ }
613
+ };
614
+
615
+ const apiRouter = createRouter({ pg });
616
+ ```
617
+
496
618
  ## Server Integration with Hono
497
619
 
498
620
  The generated code integrates seamlessly with [Hono](https://hono.dev/), a lightweight web framework for the Edge.