postgresdk 0.2.1-alpha.1 → 0.3.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/dist/cli.js +52 -15
- package/dist/emit-router.d.ts +1 -1
- package/dist/index.js +44 -15
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
@@ -569,6 +569,14 @@ export default {
|
|
569
569
|
*/
|
570
570
|
// dateType: "date",
|
571
571
|
|
572
|
+
/**
|
573
|
+
* Database driver to use for connection
|
574
|
+
* - "pg": Node.js pg driver (default, works anywhere Node.js runs)
|
575
|
+
* - "neon": Neon serverless driver (edge-compatible, works on Vercel Edge/Cloudflare Workers)
|
576
|
+
* @default "pg"
|
577
|
+
*/
|
578
|
+
// driver: "pg",
|
579
|
+
|
572
580
|
// ========== AUTHENTICATION ==========
|
573
581
|
|
574
582
|
/**
|
@@ -1975,7 +1983,7 @@ export async function authMiddleware(c: Context, next: Next) {
|
|
1975
1983
|
}
|
1976
1984
|
|
1977
1985
|
// src/emit-router.ts
|
1978
|
-
function emitRouter(tables, hasAuth) {
|
1986
|
+
function emitRouter(tables, hasAuth, driver = "pg") {
|
1979
1987
|
const tableNames = tables.map((t) => t.name).sort();
|
1980
1988
|
const imports = tableNames.map((name) => {
|
1981
1989
|
const Type = pascal(name);
|
@@ -1992,6 +2000,34 @@ function emitRouter(tables, hasAuth) {
|
|
1992
2000
|
return `export { register${Type}Routes } from "./routes/${name}";`;
|
1993
2001
|
}).join(`
|
1994
2002
|
`);
|
2003
|
+
const pgExample = driver === "pg" ? `
|
2004
|
+
* import { Client } from "pg";
|
2005
|
+
* import { createRouter } from "./generated/server/router";
|
2006
|
+
*
|
2007
|
+
* const app = new Hono();
|
2008
|
+
* const pg = new Client({ connectionString: process.env.DATABASE_URL });
|
2009
|
+
* await pg.connect();
|
2010
|
+
*
|
2011
|
+
* // Mount all generated routes under /api
|
2012
|
+
* const apiRouter = createRouter({ pg });
|
2013
|
+
* app.route("/api", apiRouter);` : `
|
2014
|
+
* import { neon } from "@neondatabase/serverless";
|
2015
|
+
* import { createRouter } from "./generated/server/router";
|
2016
|
+
*
|
2017
|
+
* const app = new Hono();
|
2018
|
+
* const sql = neon(process.env.DATABASE_URL!);
|
2019
|
+
*
|
2020
|
+
* // Create pg-compatible adapter for Neon
|
2021
|
+
* const pg = {
|
2022
|
+
* async query(text: string, params?: any[]) {
|
2023
|
+
* const rows = await sql(text, params);
|
2024
|
+
* return { rows };
|
2025
|
+
* }
|
2026
|
+
* };
|
2027
|
+
*
|
2028
|
+
* // Mount all generated routes under /api
|
2029
|
+
* const apiRouter = createRouter({ pg });
|
2030
|
+
* app.route("/api", apiRouter);`;
|
1995
2031
|
return `/* Generated. Do not edit. */
|
1996
2032
|
import { Hono } from "hono";
|
1997
2033
|
import { SDK_MANIFEST } from "./sdk-bundle";
|
@@ -2002,17 +2038,7 @@ ${hasAuth ? `export { authMiddleware } from "./auth";` : ""}
|
|
2002
2038
|
* Creates a Hono router with all generated routes that can be mounted into your existing app.
|
2003
2039
|
*
|
2004
2040
|
* @example
|
2005
|
-
* import { Hono } from "hono"
|
2006
|
-
* import { Client } from "pg";
|
2007
|
-
* import { createRouter } from "./generated/server/router";
|
2008
|
-
*
|
2009
|
-
* const app = new Hono();
|
2010
|
-
* const pg = new Client({ connectionString: process.env.DATABASE_URL });
|
2011
|
-
* await pg.connect();
|
2012
|
-
*
|
2013
|
-
* // Mount all generated routes under /api
|
2014
|
-
* const apiRouter = createRouter({ pg });
|
2015
|
-
* app.route("/api", apiRouter);
|
2041
|
+
* import { Hono } from "hono";${pgExample}
|
2016
2042
|
*
|
2017
2043
|
* // Or mount directly at root
|
2018
2044
|
* const router = createRouter({ pg });
|
@@ -2057,13 +2083,24 @@ ${registrations}
|
|
2057
2083
|
* Register all generated routes directly on an existing Hono app.
|
2058
2084
|
*
|
2059
2085
|
* @example
|
2060
|
-
* import { Hono } from "hono"
|
2086
|
+
* import { Hono } from "hono";${driver === "pg" ? `
|
2061
2087
|
* import { Client } from "pg";
|
2062
2088
|
* import { registerAllRoutes } from "./generated/server/router";
|
2063
2089
|
*
|
2064
2090
|
* const app = new Hono();
|
2065
2091
|
* const pg = new Client({ connectionString: process.env.DATABASE_URL });
|
2066
|
-
* await pg.connect()
|
2092
|
+
* await pg.connect();` : `
|
2093
|
+
* import { neon } from "@neondatabase/serverless";
|
2094
|
+
* import { registerAllRoutes } from "./generated/server/router";
|
2095
|
+
*
|
2096
|
+
* const app = new Hono();
|
2097
|
+
* const sql = neon(process.env.DATABASE_URL!);
|
2098
|
+
* const pg = {
|
2099
|
+
* async query(text: string, params?: any[]) {
|
2100
|
+
* const rows = await sql(text, params);
|
2101
|
+
* return { rows };
|
2102
|
+
* }
|
2103
|
+
* };`}
|
2067
2104
|
*
|
2068
2105
|
* // Register all routes at once
|
2069
2106
|
* registerAllRoutes(app, { pg });
|
@@ -2215,7 +2252,7 @@ async function generate(configPath) {
|
|
2215
2252
|
});
|
2216
2253
|
files.push({
|
2217
2254
|
path: join(serverDir, "router.ts"),
|
2218
|
-
content: emitRouter(Object.values(model.tables), !!normalizedAuth?.strategy && normalizedAuth.strategy !== "none")
|
2255
|
+
content: emitRouter(Object.values(model.tables), !!normalizedAuth?.strategy && normalizedAuth.strategy !== "none", cfg.driver || "pg")
|
2219
2256
|
});
|
2220
2257
|
const clientFiles = files.filter((f) => {
|
2221
2258
|
return f.path.includes(clientDir);
|
package/dist/emit-router.d.ts
CHANGED
@@ -2,4 +2,4 @@ import type { Table } from "./introspect";
|
|
2
2
|
/**
|
3
3
|
* Emits the server router file that exports helper functions for route registration
|
4
4
|
*/
|
5
|
-
export declare function emitRouter(tables: Table[], hasAuth: boolean): string;
|
5
|
+
export declare function emitRouter(tables: Table[], hasAuth: boolean, driver?: "pg" | "neon"): string;
|
package/dist/index.js
CHANGED
@@ -1738,7 +1738,7 @@ export async function authMiddleware(c: Context, next: Next) {
|
|
1738
1738
|
}
|
1739
1739
|
|
1740
1740
|
// src/emit-router.ts
|
1741
|
-
function emitRouter(tables, hasAuth) {
|
1741
|
+
function emitRouter(tables, hasAuth, driver = "pg") {
|
1742
1742
|
const tableNames = tables.map((t) => t.name).sort();
|
1743
1743
|
const imports = tableNames.map((name) => {
|
1744
1744
|
const Type = pascal(name);
|
@@ -1755,6 +1755,34 @@ function emitRouter(tables, hasAuth) {
|
|
1755
1755
|
return `export { register${Type}Routes } from "./routes/${name}";`;
|
1756
1756
|
}).join(`
|
1757
1757
|
`);
|
1758
|
+
const pgExample = driver === "pg" ? `
|
1759
|
+
* import { Client } from "pg";
|
1760
|
+
* import { createRouter } from "./generated/server/router";
|
1761
|
+
*
|
1762
|
+
* const app = new Hono();
|
1763
|
+
* const pg = new Client({ connectionString: process.env.DATABASE_URL });
|
1764
|
+
* await pg.connect();
|
1765
|
+
*
|
1766
|
+
* // Mount all generated routes under /api
|
1767
|
+
* const apiRouter = createRouter({ pg });
|
1768
|
+
* app.route("/api", apiRouter);` : `
|
1769
|
+
* import { neon } from "@neondatabase/serverless";
|
1770
|
+
* import { createRouter } from "./generated/server/router";
|
1771
|
+
*
|
1772
|
+
* const app = new Hono();
|
1773
|
+
* const sql = neon(process.env.DATABASE_URL!);
|
1774
|
+
*
|
1775
|
+
* // Create pg-compatible adapter for Neon
|
1776
|
+
* const pg = {
|
1777
|
+
* async query(text: string, params?: any[]) {
|
1778
|
+
* const rows = await sql(text, params);
|
1779
|
+
* return { rows };
|
1780
|
+
* }
|
1781
|
+
* };
|
1782
|
+
*
|
1783
|
+
* // Mount all generated routes under /api
|
1784
|
+
* const apiRouter = createRouter({ pg });
|
1785
|
+
* app.route("/api", apiRouter);`;
|
1758
1786
|
return `/* Generated. Do not edit. */
|
1759
1787
|
import { Hono } from "hono";
|
1760
1788
|
import { SDK_MANIFEST } from "./sdk-bundle";
|
@@ -1765,17 +1793,7 @@ ${hasAuth ? `export { authMiddleware } from "./auth";` : ""}
|
|
1765
1793
|
* Creates a Hono router with all generated routes that can be mounted into your existing app.
|
1766
1794
|
*
|
1767
1795
|
* @example
|
1768
|
-
* import { Hono } from "hono"
|
1769
|
-
* import { Client } from "pg";
|
1770
|
-
* import { createRouter } from "./generated/server/router";
|
1771
|
-
*
|
1772
|
-
* const app = new Hono();
|
1773
|
-
* const pg = new Client({ connectionString: process.env.DATABASE_URL });
|
1774
|
-
* await pg.connect();
|
1775
|
-
*
|
1776
|
-
* // Mount all generated routes under /api
|
1777
|
-
* const apiRouter = createRouter({ pg });
|
1778
|
-
* app.route("/api", apiRouter);
|
1796
|
+
* import { Hono } from "hono";${pgExample}
|
1779
1797
|
*
|
1780
1798
|
* // Or mount directly at root
|
1781
1799
|
* const router = createRouter({ pg });
|
@@ -1820,13 +1838,24 @@ ${registrations}
|
|
1820
1838
|
* Register all generated routes directly on an existing Hono app.
|
1821
1839
|
*
|
1822
1840
|
* @example
|
1823
|
-
* import { Hono } from "hono"
|
1841
|
+
* import { Hono } from "hono";${driver === "pg" ? `
|
1824
1842
|
* import { Client } from "pg";
|
1825
1843
|
* import { registerAllRoutes } from "./generated/server/router";
|
1826
1844
|
*
|
1827
1845
|
* const app = new Hono();
|
1828
1846
|
* const pg = new Client({ connectionString: process.env.DATABASE_URL });
|
1829
|
-
* await pg.connect()
|
1847
|
+
* await pg.connect();` : `
|
1848
|
+
* import { neon } from "@neondatabase/serverless";
|
1849
|
+
* import { registerAllRoutes } from "./generated/server/router";
|
1850
|
+
*
|
1851
|
+
* const app = new Hono();
|
1852
|
+
* const sql = neon(process.env.DATABASE_URL!);
|
1853
|
+
* const pg = {
|
1854
|
+
* async query(text: string, params?: any[]) {
|
1855
|
+
* const rows = await sql(text, params);
|
1856
|
+
* return { rows };
|
1857
|
+
* }
|
1858
|
+
* };`}
|
1830
1859
|
*
|
1831
1860
|
* // Register all routes at once
|
1832
1861
|
* registerAllRoutes(app, { pg });
|
@@ -1978,7 +2007,7 @@ async function generate(configPath) {
|
|
1978
2007
|
});
|
1979
2008
|
files.push({
|
1980
2009
|
path: join(serverDir, "router.ts"),
|
1981
|
-
content: emitRouter(Object.values(model.tables), !!normalizedAuth?.strategy && normalizedAuth.strategy !== "none")
|
2010
|
+
content: emitRouter(Object.values(model.tables), !!normalizedAuth?.strategy && normalizedAuth.strategy !== "none", cfg.driver || "pg")
|
1982
2011
|
});
|
1983
2012
|
const clientFiles = files.filter((f) => {
|
1984
2013
|
return f.path.includes(clientDir);
|
package/dist/types.d.ts
CHANGED