@batijs/cli 0.0.633 → 0.0.634

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.
Files changed (75) hide show
  1. package/dist/{asset-env-Jk0sS-Q2.js → asset-env-DvKtWq7P.js} +6 -3
  2. package/dist/{asset-package.json-BgXWfTnb.js → asset-package.json-CBsEdGlU.js} +1 -0
  3. package/dist/{asset-package.json-CJq8QmFk.js → asset-package.json-CXa26JLJ.js} +1 -0
  4. package/dist/{asset-package.json-DotEkyyW.js → asset-package.json-CpJdnsXW.js} +2 -1
  5. package/dist/asset-package.json-D5lEjBIT.js +41 -0
  6. package/dist/{asset-package.json-BfPjhiqX.js → asset-package.json-DcJFVtbo.js} +2 -0
  7. package/dist/{asset-package.json-CO-Tvf85.js → asset-package.json-WOGFbHRZ.js} +1 -0
  8. package/dist/{asset-package.json-D5VQND8y.js → asset-package2.json-Cqt3zXsB.js} +1 -0
  9. package/dist/boilerplates/@batijs/d1-sqlite/bati.config.mjs +1 -1
  10. package/dist/boilerplates/@batijs/docker-compose/files/$Dockerfile.js +17 -9
  11. package/dist/boilerplates/@batijs/docker-compose/files/$docker-compose.yml.js +1 -1
  12. package/dist/boilerplates/@batijs/docker-compose/files/asset-env.mjs +6 -3
  13. package/dist/boilerplates/@batijs/docker-compose/files/docker-compose.yml +25 -2
  14. package/dist/boilerplates/@batijs/drizzle/files/$package.json.js +5 -2
  15. package/dist/boilerplates/@batijs/drizzle/files/asset-package.json.mjs +2 -1
  16. package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/db.ts +11 -1
  17. package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/queries/todos.ts +6 -3
  18. package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/schema/todos.ts +11 -5
  19. package/dist/boilerplates/@batijs/drizzle/files/drizzle.config.ts +1 -1
  20. package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/db.d.mts +5 -1
  21. package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/queries/todos.d.mts +5 -48
  22. package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/schema/todos.d.mts +43 -1
  23. package/dist/boilerplates/@batijs/express/files/+server.ts +1 -1
  24. package/dist/boilerplates/@batijs/fastify/files/+server.ts +1 -1
  25. package/dist/boilerplates/@batijs/h3/files/+server.ts +1 -1
  26. package/dist/boilerplates/@batijs/hono/files/server/hono.ts +1 -1
  27. package/dist/boilerplates/@batijs/kysely/files/$package.json.js +6 -8
  28. package/dist/boilerplates/@batijs/kysely/files/asset-package.json.mjs +2 -0
  29. package/dist/boilerplates/@batijs/kysely/files/database/kysely/db.ts +13 -1
  30. package/dist/boilerplates/@batijs/kysely/files/database/kysely/migrate.ts +2 -2
  31. package/dist/boilerplates/@batijs/kysely/files/database/kysely/migrations/001_create_todos_table.ts +4 -5
  32. package/dist/boilerplates/@batijs/kysely/files/database/kysely/queries/todos.ts +3 -1
  33. package/dist/boilerplates/@batijs/kysely/types/database/kysely/db.d.mts +2 -1
  34. package/dist/boilerplates/@batijs/kysely/types/database/kysely/queries/todos.d.mts +3 -1
  35. package/dist/boilerplates/@batijs/postgres/bati.config.mjs +25 -0
  36. package/dist/boilerplates/@batijs/postgres/files/$TODO.md.js +25 -0
  37. package/dist/boilerplates/@batijs/postgres/files/$package.json.js +15 -0
  38. package/dist/boilerplates/@batijs/postgres/files/asset-package.json.mjs +39 -0
  39. package/dist/boilerplates/@batijs/postgres/files/database/postgres/db.ts +15 -0
  40. package/dist/boilerplates/@batijs/postgres/files/database/postgres/queries/todos.ts +9 -0
  41. package/dist/boilerplates/@batijs/postgres/files/database/postgres/schema/all.ts +1 -0
  42. package/dist/boilerplates/@batijs/postgres/files/database/postgres/schema/todos.ts +16 -0
  43. package/dist/boilerplates/@batijs/postgres/types/database/postgres/db.d.mts +6 -0
  44. package/dist/boilerplates/@batijs/postgres/types/database/postgres/queries/todos.d.mts +10 -0
  45. package/dist/boilerplates/@batijs/postgres/types/database/postgres/schema/all.d.mts +1 -0
  46. package/dist/boilerplates/@batijs/postgres/types/database/postgres/schema/todos.d.mts +1 -0
  47. package/dist/boilerplates/@batijs/prisma/bati.config.mjs +6 -12
  48. package/dist/boilerplates/@batijs/prisma/files/$TODO.md.js +4 -3
  49. package/dist/boilerplates/@batijs/shared-db/bati.config.mjs +26 -12
  50. package/dist/boilerplates/@batijs/shared-db/files/server/db-middleware.ts +25 -15
  51. package/dist/boilerplates/@batijs/shared-db/types/server/db-middleware.d.mts +9 -5
  52. package/dist/boilerplates/@batijs/shared-server/files/$package.json.js +1 -1
  53. package/dist/boilerplates/@batijs/shared-server/files/asset-package.json.mjs +1 -0
  54. package/dist/boilerplates/@batijs/shared-server/files/server/create-todo-handler.ts +13 -6
  55. package/dist/boilerplates/@batijs/shared-server/types/server/create-todo-handler.d.mts +15 -5
  56. package/dist/boilerplates/@batijs/shared-todo/files/global.d.ts +9 -5
  57. package/dist/boilerplates/@batijs/shared-todo/files/pages/todo/+data.ts +7 -2
  58. package/dist/boilerplates/@batijs/shared-todo/types/pages/todo/+data.d.mts +1 -3
  59. package/dist/boilerplates/@batijs/sqlite/bati.config.mjs +1 -1
  60. package/dist/boilerplates/@batijs/telefunc/files/$package.json.js +1 -1
  61. package/dist/boilerplates/@batijs/telefunc/files/asset-package.json.mjs +1 -0
  62. package/dist/boilerplates/@batijs/telefunc/files/global.d.ts +9 -6
  63. package/dist/boilerplates/@batijs/telefunc/files/pages/todo/TodoList.telefunc.ts +6 -2
  64. package/dist/boilerplates/@batijs/telefunc/files/server/telefunc-handler.ts +9 -4
  65. package/dist/boilerplates/@batijs/trpc/files/$package.json.js +1 -1
  66. package/dist/boilerplates/@batijs/trpc/files/asset-package.json.mjs +1 -0
  67. package/dist/boilerplates/@batijs/trpc/files/trpc/server.ts +13 -6
  68. package/dist/boilerplates/@batijs/trpc/types/trpc/client.d.mts +6 -0
  69. package/dist/boilerplates/@batijs/trpc/types/trpc/server.d.mts +22 -3
  70. package/dist/boilerplates/@batijs/ts-rest/files/$package.json.js +1 -1
  71. package/dist/boilerplates/@batijs/ts-rest/files/asset-package.json.mjs +1 -0
  72. package/dist/boilerplates/@batijs/ts-rest/files/server/ts-rest-handler.ts +13 -6
  73. package/dist/boilerplates/boilerplates.json +6 -0
  74. package/dist/index.js +4 -1
  75. package/package.json +5 -5
@@ -1,7 +1,8 @@
1
- import type { dbKysely, dbKyselyD1 } from "../db";
1
+ import type { dbKysely, dbKyselyD1, dbKyselyPostgres } from "../db";
2
2
 
3
3
  export async function insertTodo(
4
4
  db: BATI.If<{
5
+ 'BATI.has("postgres")': ReturnType<typeof dbKyselyPostgres>;
5
6
  "!BATI.hasD1": ReturnType<typeof dbKysely>;
6
7
  "BATI.hasD1": ReturnType<typeof dbKyselyD1>;
7
8
  }>,
@@ -12,6 +13,7 @@ export async function insertTodo(
12
13
 
13
14
  export async function getAllTodos(
14
15
  db: BATI.If<{
16
+ 'BATI.has("postgres")': ReturnType<typeof dbKyselyPostgres>;
15
17
  "!BATI.hasD1": ReturnType<typeof dbKysely>;
16
18
  "BATI.hasD1": ReturnType<typeof dbKyselyD1>;
17
19
  }>,
@@ -4,5 +4,6 @@ import { Kysely } from "kysely";
4
4
  //#region files/database/kysely/db.d.ts
5
5
  declare function dbKysely(): Kysely<Database>;
6
6
  declare function dbKyselyD1(d1: D1Database): Kysely<Database>;
7
+ declare function dbKyselyPostgres(): Kysely<Database>;
7
8
  //#endregion
8
- export { dbKysely, dbKyselyD1 };
9
+ export { dbKysely, dbKyselyD1, dbKyselyPostgres };
@@ -1,7 +1,8 @@
1
- import { dbKysely, dbKyselyD1 } from "../db.mjs";
1
+ import { dbKysely, dbKyselyD1, dbKyselyPostgres } from "../db.mjs";
2
2
 
3
3
  //#region files/database/kysely/queries/todos.d.ts
4
4
  declare function insertTodo(db: BATI.If<{
5
+ 'BATI.has("postgres")': ReturnType<typeof dbKyselyPostgres>;
5
6
  "!BATI.hasD1": ReturnType<typeof dbKysely>;
6
7
  "BATI.hasD1": ReturnType<typeof dbKyselyD1>;
7
8
  }>, text: string): Promise<{
@@ -9,6 +10,7 @@ declare function insertTodo(db: BATI.If<{
9
10
  text: string;
10
11
  }>;
11
12
  declare function getAllTodos(db: BATI.If<{
13
+ 'BATI.has("postgres")': ReturnType<typeof dbKyselyPostgres>;
12
14
  "!BATI.hasD1": ReturnType<typeof dbKysely>;
13
15
  "BATI.hasD1": ReturnType<typeof dbKyselyD1>;
14
16
  }>): Promise<{
@@ -0,0 +1,25 @@
1
+ //#region ../../packages/core/dist/config.js
2
+ function e(e, t) {
3
+ if (!e) throw Error(t);
4
+ }
5
+ function t(t) {
6
+ return `enforce` in t && e(t.enforce === `pre` || t.enforce === `post`, `'enforce' must be 'pre' or 'post', was ${t.enforce}`), `if` in t && e(typeof t.if == `function`, `'if' must be a function`), `nextSteps` in t && e(typeof t.nextSteps == `function`, `'nextSteps' must be a function`), `knip` in t && (e(typeof t.knip == `object` && t.knip !== null, `'knip' must be an object`), `entry` in t.knip && e(Array.isArray(t.knip.entry), `'knip.entry' must be an array`), `ignoreDependencies` in t.knip && e(Array.isArray(t.knip.ignoreDependencies), `'knip.ignoreDependencies' must be an array`), `ignore` in t.knip && e(Array.isArray(t.knip.ignore), `'knip.ignore' must be an array`), `vite` in t.knip && e(typeof t.knip.vite == `boolean`, `'knip.vite' must be a boolean`)), `env` in t && e(typeof t.env == `function`, `'env' must be a function of meta`), t;
7
+ }
8
+ //#endregion
9
+ //#region bati.config.ts
10
+ var bati_config_default = t({
11
+ if(meta) {
12
+ return meta.BATI.has("postgres") && !meta.BATI.hasOrm;
13
+ },
14
+ nextSteps(_meta, packageManager, { bold }) {
15
+ return [{
16
+ type: "text",
17
+ step: `Set your ${bold("DATABASE_URL")} in .env and provide a PostgreSQL server — see ${bold("TODO.md")}`
18
+ }, {
19
+ type: "command",
20
+ step: `${packageManager} postgres:migrate`
21
+ }];
22
+ }
23
+ });
24
+ //#endregion
25
+ export { bati_config_default as default };
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { loadMarkdown, packageManager } from "@batijs/core";
4
+ //#region ../../boilerplates/postgres/dist/files/$TODO.md.mjs
5
+ async function getTodo(props) {
6
+ const content = await loadMarkdown(props);
7
+ const pmCmd = packageManager().run;
8
+ const todo = `
9
+ ## PostgreSQL
10
+
11
+ ${props.meta.BATI.has("docker") ? "The Docker setup provisions a PostgreSQL server for you via `docker-compose.yml`." : "Bati only installs the `postgres` client — **bring your own PostgreSQL server** (a local install, a managed instance, or e.g. `docker run -e POSTGRES_PASSWORD=postgres -p 5432:5432 postgres`)."}
12
+
13
+ Set \`DATABASE_URL\` in \`.env\` to your connection string, then create the example table:
14
+ \`\`\`bash
15
+ ${pmCmd} postgres:migrate # creates the \`todos\` table
16
+ \`\`\`
17
+
18
+ Queries use [postgres.js](https://github.com/porsager/postgres). See \`database/postgres/\` for the
19
+ client, schema and example queries.
20
+ `;
21
+ content.addMarkdownFeature(todo, "postgres");
22
+ return content;
23
+ }
24
+ //#endregion
25
+ export { getTodo as default };
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { loadPackageJson, packageManager } from "@batijs/core";
4
+ //#region ../../boilerplates/postgres/dist/files/$package.json.mjs
5
+ async function getPackageJson(props) {
6
+ const packageJson = await loadPackageJson(props, await import("../../../../asset-package.json-D5lEjBIT.js").then((x) => x.default));
7
+ const bun = packageManager().name === "bun";
8
+ packageJson.setScript("postgres:migrate", {
9
+ value: `${bun ? "bun" : "tsx"} ./database/postgres/schema/all.ts`,
10
+ precedence: 1
11
+ }).addDependencies(["postgres", "dotenv"]).addDevDependencies(["tsx"], ["postgres:migrate"], !bun);
12
+ return packageJson;
13
+ }
14
+ //#endregion
15
+ export { getPackageJson as default };
@@ -0,0 +1,39 @@
1
+ //#region package.json
2
+ var package_default = {
3
+ name: "@batijs/postgres",
4
+ "private": true,
5
+ version: "0.0.1",
6
+ description: "",
7
+ type: "module",
8
+ scripts: {
9
+ "check-types": "tsc --noEmit",
10
+ "build": "bati-compile-boilerplate"
11
+ },
12
+ keywords: [],
13
+ author: "",
14
+ license: "MIT",
15
+ devDependencies: {
16
+ "@batijs/compile": "workspace:*",
17
+ "@batijs/core": "workspace:*",
18
+ "@types/node": "^20.19.37",
19
+ "dotenv": "^17.4.2",
20
+ "postgres": "^3.4.7",
21
+ "tsx": "^4.22.3"
22
+ },
23
+ files: ["dist/"],
24
+ exports: {
25
+ "./database/postgres/db": { "types": "./dist/types/database/postgres/db.d.mts" },
26
+ "./database/postgres/queries/todos": { "types": "./dist/types/database/postgres/queries/todos.d.mts" },
27
+ "./database/postgres/schema/all": { "types": "./dist/types/database/postgres/schema/all.d.mts" },
28
+ "./database/postgres/schema/todos": { "types": "./dist/types/database/postgres/schema/todos.d.mts" }
29
+ },
30
+ typesVersions: { "*": {
31
+ "database/postgres/db": ["./dist/types/database/postgres/db.d.mts"],
32
+ "database/postgres/queries/todos": ["./dist/types/database/postgres/queries/todos.d.mts"],
33
+ "database/postgres/schema/all": ["./dist/types/database/postgres/schema/all.d.mts"],
34
+ "database/postgres/schema/todos": ["./dist/types/database/postgres/schema/todos.d.mts"]
35
+ } },
36
+ nx: { "tags": ["type:boilerplate"] }
37
+ };
38
+ //#endregion
39
+ export { package_default as default };
@@ -0,0 +1,15 @@
1
+ /*# BATI include-if-imported #*/
2
+ import postgres from "postgres";
3
+
4
+ let singleton: postgres.Sql | undefined;
5
+
6
+ export function db(): postgres.Sql {
7
+ if (!singleton) {
8
+ if (!process.env.DATABASE_URL) {
9
+ throw new Error("Missing DATABASE_URL in .env file");
10
+ }
11
+
12
+ singleton = postgres(process.env.DATABASE_URL);
13
+ }
14
+ return singleton;
15
+ }
@@ -0,0 +1,9 @@
1
+ import type postgres from "postgres";
2
+
3
+ export function insertTodo(sql: postgres.Sql, text: string) {
4
+ return sql`INSERT INTO todos (text) VALUES (${text})`;
5
+ }
6
+
7
+ export function getAllTodos(sql: postgres.Sql) {
8
+ return sql<{ id: number; text: string }[]>`SELECT id, text FROM todos ORDER BY id`;
9
+ }
@@ -0,0 +1,16 @@
1
+ /*# BATI include-if-imported #*/
2
+ import "dotenv/config";
3
+ import { db } from "../db";
4
+
5
+ const sql = db();
6
+
7
+ /**
8
+ * PostgreSQL Schema
9
+ * `todos` example
10
+ */
11
+ await sql`CREATE TABLE IF NOT EXISTS todos (
12
+ id SERIAL PRIMARY KEY,
13
+ text TEXT NOT NULL
14
+ )`;
15
+
16
+ await sql.end();
@@ -0,0 +1,6 @@
1
+ import postgres from "postgres";
2
+
3
+ //#region files/database/postgres/db.d.ts
4
+ declare function db(): postgres.Sql;
5
+ //#endregion
6
+ export { db };
@@ -0,0 +1,10 @@
1
+ import postgres from "postgres";
2
+
3
+ //#region files/database/postgres/queries/todos.d.ts
4
+ declare function insertTodo(sql: postgres.Sql, text: string): postgres.PendingQuery<postgres.Row[]>;
5
+ declare function getAllTodos(sql: postgres.Sql): postgres.PendingQuery<{
6
+ id: number;
7
+ text: string;
8
+ }[]>;
9
+ //#endregion
10
+ export { getAllTodos, insertTodo };
@@ -11,25 +11,19 @@ var bati_config_default = t({
11
11
  if(meta) {
12
12
  return meta.BATI.has("prisma");
13
13
  },
14
- env: () => [{
14
+ env: (meta) => [{
15
15
  key: "DATABASE_URL",
16
16
  scope: "server-default",
17
- default: "postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public",
18
- comment: `Prisma
19
-
20
- Environment variables declared in this file are automatically made available to Prisma.
21
- See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
22
-
23
- Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
24
- See the documentation for all the connection string options: https://pris.ly/d/connection-strings`
17
+ default: meta.BATI.has("postgres") ? "postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public" : "file:./dev.db",
18
+ comment: `Prisma connection string — see https://pris.ly/d/connection-strings`
25
19
  }],
26
- nextSteps(_meta, packageManager) {
20
+ nextSteps(meta, packageManager) {
27
21
  return [{
28
22
  type: "command",
29
- step: `${packageManager} prisma init --db`
23
+ step: `${packageManager} prisma init --datasource-provider ${meta.BATI.has("postgres") ? "postgresql" : "sqlite"}`
30
24
  }, {
31
25
  type: "text",
32
- step: `Then follow instructions at https://www.prisma.io/docs/getting-started/prisma-orm/quickstart/prisma-postgres`
26
+ step: `Then define your models and run ${packageManager} prisma migrate dev — https://www.prisma.io/docs/getting-started`
33
27
  }];
34
28
  },
35
29
  knip: { ignoreDependencies: ["@prisma/client", "prisma"] }
@@ -4,15 +4,16 @@ import { loadMarkdown, packageManager } from "@batijs/core";
4
4
  //#region ../../boilerplates/prisma/dist/files/$TODO.md.mjs
5
5
  async function getTodo(props) {
6
6
  const content = await loadMarkdown(props);
7
+ const pmCmd = packageManager().run;
7
8
  const todo = `
8
9
  ## Prisma
9
10
 
10
- Run the following command once:
11
+ Scaffold your Prisma schema (uses the \`DATABASE_URL\` already set in \`.env\`):
11
12
  \`\`\`sh
12
- ${packageManager().run} prisma init --db
13
+ ${pmCmd} prisma init --datasource-provider ${props.meta.BATI.has("postgres") ? "postgresql" : "sqlite"}
13
14
  \`\`\`
14
15
 
15
- then follow instructions at <https://www.prisma.io/docs/getting-started/prisma-orm/quickstart/prisma-postgres#4-initialize-prisma-orm-and-create-a-prisma-postgres-database>`;
16
+ Then define your models and run \`${pmCmd} prisma migrate dev\`. See <https://www.prisma.io/docs/getting-started>`;
16
17
  content.addMarkdownFeature(todo, "prisma");
17
18
  return content;
18
19
  }
@@ -9,19 +9,33 @@ function t(t) {
9
9
  //#region bati.config.ts
10
10
  var bati_config_default = t({
11
11
  if(meta) {
12
- return meta.BATI.hasDatabase;
12
+ return meta.BATI.hasDbDemo;
13
13
  },
14
- env: (meta) => meta.BATI.hasD1 ? [] : [{
15
- key: "DATABASE_URL",
16
- scope: "server-default",
17
- comment: "Path to the database",
18
- default: "sqlite.db",
19
- perSink: {
20
- compose: "/app/data/db.sqlite",
21
- dockerfile: "/app/database/sqlite.db"
22
- },
23
- group: "non-D1 database"
24
- }]
14
+ env: (meta) => {
15
+ if (meta.BATI.hasD1) return [];
16
+ if (meta.BATI.has("postgres")) return [{
17
+ key: "DATABASE_URL",
18
+ scope: "server-default",
19
+ comment: "PostgreSQL connection string",
20
+ default: "postgresql://postgres:postgres@localhost:5432/app",
21
+ perSink: {
22
+ compose: "postgresql://postgres:postgres@postgres:5432/app",
23
+ dockerfile: "postgresql://postgres:postgres@postgres:5432/app"
24
+ },
25
+ group: "postgres database"
26
+ }];
27
+ return [{
28
+ key: "DATABASE_URL",
29
+ scope: "server-default",
30
+ comment: "Path to the database",
31
+ default: "sqlite.db",
32
+ perSink: {
33
+ compose: "/app/data/db.sqlite",
34
+ dockerfile: "/app/database/sqlite.db"
35
+ },
36
+ group: "non-D1 database"
37
+ }];
38
+ }
25
39
  });
26
40
  //#endregion
27
41
  export { bati_config_default as default };
@@ -1,8 +1,9 @@
1
1
  /*# BATI include-if-imported #*/
2
2
 
3
3
  import { getDbFromRuntime } from "@batijs/d1/database/d1/helpers";
4
- import { dbD1, dbSqlite } from "@batijs/drizzle/database/drizzle/db";
5
- import { dbKysely, dbKyselyD1 } from "@batijs/kysely/database/kysely/db";
4
+ import { dbD1, dbPostgres, dbSqlite } from "@batijs/drizzle/database/drizzle/db";
5
+ import { dbKysely, dbKyselyD1, dbKyselyPostgres } from "@batijs/kysely/database/kysely/db";
6
+ import { db as pgDb } from "@batijs/postgres/database/postgres/db";
6
7
  import { db as sqliteDb } from "@batijs/sqlite/database/sqlite/db";
7
8
  import { enhance, type UniversalMiddleware } from "@universal-middleware/core";
8
9
 
@@ -11,12 +12,15 @@ declare global {
11
12
  namespace Universal {
12
13
  interface Context {
13
14
  db: BATI.If<{
14
- 'BATI.has("sqlite") && !BATI.hasD1': ReturnType<typeof sqliteDb>;
15
+ 'BATI.has("drizzle") && BATI.has("postgres")': ReturnType<typeof dbPostgres>;
16
+ 'BATI.has("kysely") && BATI.has("postgres")': ReturnType<typeof dbKyselyPostgres>;
17
+ 'BATI.has("postgres") && !BATI.hasOrm': ReturnType<typeof pgDb>;
18
+ 'BATI.has("sqlite") && !BATI.hasD1 && !BATI.hasOrm': ReturnType<typeof sqliteDb>;
15
19
  'BATI.has("drizzle") && !BATI.hasD1': ReturnType<typeof dbSqlite>;
16
20
  'BATI.has("drizzle")': ReturnType<typeof dbD1>;
17
21
  'BATI.has("kysely") && !BATI.hasD1': ReturnType<typeof dbKysely>;
18
22
  'BATI.has("kysely")': ReturnType<typeof dbKyselyD1>;
19
- "BATI.hasD1": D1Database;
23
+ "BATI.hasD1 && !BATI.hasOrm": D1Database;
20
24
  }>;
21
25
  }
22
26
  }
@@ -30,17 +34,23 @@ export const dbMiddleware: UniversalMiddleware = enhance(
30
34
  // The context we add here is automatically merged into pageContext
31
35
  async (_request, context, _runtime) => {
32
36
  const db =
33
- BATI.has("sqlite") && !BATI.hasD1
34
- ? sqliteDb()
35
- : BATI.has("drizzle") && !BATI.hasD1
36
- ? dbSqlite()
37
- : BATI.has("kysely") && !BATI.hasD1
38
- ? dbKysely()
39
- : BATI.has("kysely")
40
- ? dbKyselyD1(await getDbFromRuntime(_runtime))
41
- : BATI.has("drizzle")
42
- ? dbD1(await getDbFromRuntime(_runtime))
43
- : await getDbFromRuntime(_runtime);
37
+ BATI.has("drizzle") && BATI.has("postgres")
38
+ ? dbPostgres()
39
+ : BATI.has("kysely") && BATI.has("postgres")
40
+ ? dbKyselyPostgres()
41
+ : BATI.has("postgres") && !BATI.hasOrm
42
+ ? pgDb()
43
+ : BATI.has("sqlite") && !BATI.hasD1 && !BATI.hasOrm
44
+ ? sqliteDb()
45
+ : BATI.has("drizzle") && !BATI.hasD1
46
+ ? dbSqlite()
47
+ : BATI.has("kysely") && !BATI.hasD1
48
+ ? dbKysely()
49
+ : BATI.has("kysely")
50
+ ? dbKyselyD1(await getDbFromRuntime(_runtime))
51
+ : BATI.has("drizzle")
52
+ ? dbD1(await getDbFromRuntime(_runtime))
53
+ : await getDbFromRuntime(_runtime);
44
54
 
45
55
  return {
46
56
  ...context,
@@ -1,6 +1,7 @@
1
- import { dbD1, dbSqlite } from "@batijs/drizzle/database/drizzle/db";
2
- import { dbKysely, dbKyselyD1 } from "@batijs/kysely/database/kysely/db";
3
- import { db } from "@batijs/sqlite/database/sqlite/db";
1
+ import { dbD1, dbPostgres, dbSqlite } from "@batijs/drizzle/database/drizzle/db";
2
+ import { dbKysely, dbKyselyD1, dbKyselyPostgres } from "@batijs/kysely/database/kysely/db";
3
+ import { db } from "@batijs/postgres/database/postgres/db";
4
+ import { db as db$1 } from "@batijs/sqlite/database/sqlite/db";
4
5
  import { UniversalMiddleware } from "@universal-middleware/core";
5
6
 
6
7
  //#region files/server/db-middleware.d.ts
@@ -8,12 +9,15 @@ declare global {
8
9
  namespace Universal {
9
10
  interface Context {
10
11
  db: BATI.If<{
11
- 'BATI.has("sqlite") && !BATI.hasD1': ReturnType<typeof db>;
12
+ 'BATI.has("drizzle") && BATI.has("postgres")': ReturnType<typeof dbPostgres>;
13
+ 'BATI.has("kysely") && BATI.has("postgres")': ReturnType<typeof dbKyselyPostgres>;
14
+ 'BATI.has("postgres") && !BATI.hasOrm': ReturnType<typeof db>;
15
+ 'BATI.has("sqlite") && !BATI.hasD1 && !BATI.hasOrm': ReturnType<typeof db$1>;
12
16
  'BATI.has("drizzle") && !BATI.hasD1': ReturnType<typeof dbSqlite>;
13
17
  'BATI.has("drizzle")': ReturnType<typeof dbD1>;
14
18
  'BATI.has("kysely") && !BATI.hasD1': ReturnType<typeof dbKysely>;
15
19
  'BATI.has("kysely")': ReturnType<typeof dbKyselyD1>;
16
- "BATI.hasD1": D1Database;
20
+ "BATI.hasD1 && !BATI.hasOrm": D1Database;
17
21
  }>;
18
22
  }
19
23
  }
@@ -3,7 +3,7 @@
3
3
  import { loadPackageJson } from "@batijs/core";
4
4
  //#region ../../boilerplates/shared-server/dist/files/$package.json.mjs
5
5
  async function getPackageJson(props) {
6
- return (await loadPackageJson(props, await import("../../../../asset-package.json-CJq8QmFk.js").then((x) => x.default))).addDependencies(["@universal-middleware/core"]);
6
+ return (await loadPackageJson(props, await import("../../../../asset-package.json-CXa26JLJ.js").then((x) => x.default))).addDependencies(["@universal-middleware/core"]);
7
7
  }
8
8
  //#endregion
9
9
  export { getPackageJson as default };
@@ -19,6 +19,7 @@ var package_default = {
19
19
  "@batijs/d1-sqlite": "workspace:*",
20
20
  "@batijs/drizzle": "workspace:*",
21
21
  "@batijs/kysely": "workspace:*",
22
+ "@batijs/postgres": "workspace:*",
22
23
  "@batijs/sqlite": "workspace:*",
23
24
  "@types/node": "^20.19.37",
24
25
  "@universal-middleware/core": "^0.4.17",
@@ -1,10 +1,12 @@
1
1
  /*# BATI include-if-imported #*/
2
2
 
3
3
  import * as d1Queries from "@batijs/d1-sqlite/database/d1/queries/todos";
4
- import type { dbD1, dbSqlite } from "@batijs/drizzle/database/drizzle/db";
4
+ import type { dbD1, dbPostgres, dbSqlite } from "@batijs/drizzle/database/drizzle/db";
5
5
  import * as drizzleQueries from "@batijs/drizzle/database/drizzle/queries/todos";
6
- import type { dbKysely, dbKyselyD1 } from "@batijs/kysely/database/kysely/db";
6
+ import type { dbKysely, dbKyselyD1, dbKyselyPostgres } from "@batijs/kysely/database/kysely/db";
7
7
  import * as kyselyQueries from "@batijs/kysely/database/kysely/queries/todos";
8
+ import type { db as pgDb } from "@batijs/postgres/database/postgres/db";
9
+ import * as pgQueries from "@batijs/postgres/database/postgres/queries/todos";
8
10
  import type { db as sqliteDb } from "@batijs/sqlite/database/sqlite/db";
9
11
  import * as sqliteQueries from "@batijs/sqlite/database/sqlite/queries/todos";
10
12
  import { enhance, type UniversalHandler } from "@universal-middleware/core";
@@ -13,12 +15,15 @@ import { enhance, type UniversalHandler } from "@universal-middleware/core";
13
15
  export const createTodoHandler: UniversalHandler<
14
16
  Universal.Context &
15
17
  BATI.If<{
16
- 'BATI.has("sqlite") && !BATI.hasD1': { db: ReturnType<typeof sqliteDb> };
18
+ 'BATI.has("drizzle") && BATI.has("postgres")': { db: ReturnType<typeof dbPostgres> };
19
+ 'BATI.has("kysely") && BATI.has("postgres")': { db: ReturnType<typeof dbKyselyPostgres> };
20
+ 'BATI.has("postgres") && !BATI.hasOrm': { db: ReturnType<typeof pgDb> };
21
+ 'BATI.has("sqlite") && !BATI.hasD1 && !BATI.hasOrm': { db: ReturnType<typeof sqliteDb> };
17
22
  'BATI.has("drizzle") && !BATI.hasD1': { db: ReturnType<typeof dbSqlite> };
18
23
  'BATI.has("drizzle")': { db: ReturnType<typeof dbD1> };
19
24
  'BATI.has("kysely") && !BATI.hasD1': { db: ReturnType<typeof dbKysely> };
20
25
  'BATI.has("kysely")': { db: ReturnType<typeof dbKyselyD1> };
21
- "BATI.hasD1": { db: D1Database };
26
+ "BATI.hasD1 && !BATI.hasOrm": { db: D1Database };
22
27
  _: object;
23
28
  }>
24
29
  > = enhance(
@@ -28,12 +33,14 @@ export const createTodoHandler: UniversalHandler<
28
33
 
29
34
  if (BATI.has("drizzle")) {
30
35
  await drizzleQueries.insertTodo(_context.db, newTodo.text);
31
- } else if (BATI.has("sqlite") && !BATI.hasD1) {
36
+ } else if (BATI.has("sqlite") && !BATI.hasD1 && !BATI.hasOrm) {
32
37
  sqliteQueries.insertTodo(_context.db, newTodo.text);
33
38
  } else if (BATI.has("kysely")) {
34
39
  await kyselyQueries.insertTodo(_context.db, newTodo.text);
35
- } else if (BATI.hasD1) {
40
+ } else if (BATI.hasD1 && !BATI.hasOrm) {
36
41
  await d1Queries.insertTodo(_context.db, newTodo.text);
42
+ } else if (BATI.has("postgres") && !BATI.hasOrm) {
43
+ await pgQueries.insertTodo(_context.db, newTodo.text);
37
44
  } else {
38
45
  // This is where you'd persist the data
39
46
  console.log("Received new todo", newTodo);
@@ -1,13 +1,23 @@
1
- import { dbD1, dbSqlite } from "@batijs/drizzle/database/drizzle/db";
2
- import { dbKysely, dbKyselyD1 } from "@batijs/kysely/database/kysely/db";
3
- import { db } from "@batijs/sqlite/database/sqlite/db";
1
+ import { dbD1, dbPostgres, dbSqlite } from "@batijs/drizzle/database/drizzle/db";
2
+ import { dbKysely, dbKyselyD1, dbKyselyPostgres } from "@batijs/kysely/database/kysely/db";
3
+ import { db } from "@batijs/postgres/database/postgres/db";
4
+ import { db as db$1 } from "@batijs/sqlite/database/sqlite/db";
4
5
  import { UniversalHandler } from "@universal-middleware/core";
5
6
 
6
7
  //#region files/server/create-todo-handler.d.ts
7
8
  declare const createTodoHandler: UniversalHandler<Universal.Context & BATI.If<{
8
- 'BATI.has("sqlite") && !BATI.hasD1': {
9
+ 'BATI.has("drizzle") && BATI.has("postgres")': {
10
+ db: ReturnType<typeof dbPostgres>;
11
+ };
12
+ 'BATI.has("kysely") && BATI.has("postgres")': {
13
+ db: ReturnType<typeof dbKyselyPostgres>;
14
+ };
15
+ 'BATI.has("postgres") && !BATI.hasOrm': {
9
16
  db: ReturnType<typeof db>;
10
17
  };
18
+ 'BATI.has("sqlite") && !BATI.hasD1 && !BATI.hasOrm': {
19
+ db: ReturnType<typeof db$1>;
20
+ };
11
21
  'BATI.has("drizzle") && !BATI.hasD1': {
12
22
  db: ReturnType<typeof dbSqlite>;
13
23
  };
@@ -20,7 +30,7 @@ declare const createTodoHandler: UniversalHandler<Universal.Context & BATI.If<{
20
30
  'BATI.has("kysely")': {
21
31
  db: ReturnType<typeof dbKyselyD1>;
22
32
  };
23
- "BATI.hasD1": {
33
+ "BATI.hasD1 && !BATI.hasOrm": {
24
34
  db: D1Database;
25
35
  };
26
36
  _: object;
@@ -1,18 +1,22 @@
1
- import type { dbD1, dbSqlite } from "@batijs/drizzle/database/drizzle/db";
2
- import type { dbKysely, dbKyselyD1 } from "@batijs/kysely/database/kysely/db";
1
+ import type { dbD1, dbPostgres, dbSqlite } from "@batijs/drizzle/database/drizzle/db";
2
+ import type { dbKysely, dbKyselyD1, dbKyselyPostgres } from "@batijs/kysely/database/kysely/db";
3
+ import type { db as pgDb } from "@batijs/postgres/database/postgres/db";
3
4
  import type { db as sqliteDb } from "@batijs/sqlite/database/sqlite/db";
4
5
 
5
- //# BATI.hasDatabase
6
+ //# BATI.hasDbDemo
6
7
  declare global {
7
8
  namespace Vike {
8
9
  interface PageContextServer {
9
10
  db: BATI.If<{
10
- 'BATI.has("sqlite") && !BATI.hasD1': ReturnType<typeof sqliteDb>;
11
+ 'BATI.has("drizzle") && BATI.has("postgres")': ReturnType<typeof dbPostgres>;
12
+ 'BATI.has("kysely") && BATI.has("postgres")': ReturnType<typeof dbKyselyPostgres>;
13
+ 'BATI.has("postgres") && !BATI.hasOrm': ReturnType<typeof pgDb>;
14
+ 'BATI.has("sqlite") && !BATI.hasD1 && !BATI.hasOrm': ReturnType<typeof sqliteDb>;
11
15
  'BATI.has("drizzle") && !BATI.hasD1': ReturnType<typeof dbSqlite>;
12
16
  'BATI.has("drizzle")': ReturnType<typeof dbD1>;
13
17
  'BATI.has("kysely") && !BATI.hasD1': ReturnType<typeof dbKysely>;
14
18
  'BATI.has("kysely")': ReturnType<typeof dbKyselyD1>;
15
- "BATI.hasD1": D1Database;
19
+ "BATI.hasD1 && !BATI.hasOrm": D1Database;
16
20
  }>;
17
21
  }
18
22
  }
@@ -3,6 +3,7 @@
3
3
  import * as d1Queries from "@batijs/d1-sqlite/database/d1/queries/todos";
4
4
  import * as drizzleQueries from "@batijs/drizzle/database/drizzle/queries/todos";
5
5
  import * as kyselyQueries from "@batijs/kysely/database/kysely/queries/todos";
6
+ import * as pgQueries from "@batijs/postgres/database/postgres/queries/todos";
6
7
  import * as sqliteQueries from "@batijs/sqlite/database/sqlite/queries/todos";
7
8
  import type { PageContextServer } from "vike/types";
8
9
 
@@ -13,7 +14,7 @@ export async function data(_pageContext: PageContextServer) {
13
14
  const todoItemsInitial = await drizzleQueries.getAllTodos(_pageContext.db);
14
15
 
15
16
  return { todoItemsInitial };
16
- } else if (BATI.has("sqlite") && !BATI.hasD1) {
17
+ } else if (BATI.has("sqlite") && !BATI.hasD1 && !BATI.hasOrm) {
17
18
  const todoItemsInitial = sqliteQueries.getAllTodos(_pageContext.db);
18
19
 
19
20
  return { todoItemsInitial };
@@ -21,9 +22,13 @@ export async function data(_pageContext: PageContextServer) {
21
22
  const todoItemsInitial = await kyselyQueries.getAllTodos(_pageContext.db);
22
23
 
23
24
  return { todoItemsInitial };
24
- } else if (BATI.hasD1) {
25
+ } else if (BATI.hasD1 && !BATI.hasOrm) {
25
26
  const todoItemsInitial = await d1Queries.getAllTodos(_pageContext.db);
26
27
 
28
+ return { todoItemsInitial };
29
+ } else if (BATI.has("postgres") && !BATI.hasOrm) {
30
+ const todoItemsInitial = await pgQueries.getAllTodos(_pageContext.db);
31
+
27
32
  return { todoItemsInitial };
28
33
  } else {
29
34
  // NOTE: This +data hook is only for demonstration — it doesn't actually retrieve data from a database.
@@ -3,9 +3,7 @@ import { PageContextServer } from "vike/types";
3
3
  //#region files/pages/todo/+data.d.ts
4
4
  type Data = Awaited<ReturnType<typeof data>>;
5
5
  declare function data(_pageContext: PageContextServer): Promise<{
6
- todoItemsInitial: {
7
- text: string;
8
- }[];
6
+ todoItemsInitial: any;
9
7
  }>;
10
8
  //#endregion
11
9
  export { Data, data };
@@ -9,7 +9,7 @@ function t(t) {
9
9
  //#region bati.config.ts
10
10
  var bati_config_default = t({
11
11
  if(meta) {
12
- return meta.BATI.has("sqlite") && !meta.BATI.has("cloudflare");
12
+ return meta.BATI.has("sqlite") && !meta.BATI.hasOrm && !meta.BATI.has("cloudflare");
13
13
  },
14
14
  nextSteps(_meta, packageManager) {
15
15
  return [{
@@ -3,7 +3,7 @@
3
3
  import { loadPackageJson } from "@batijs/core";
4
4
  //#region ../../boilerplates/telefunc/dist/files/$package.json.mjs
5
5
  async function getPackageJson(props) {
6
- return (await loadPackageJson(props, await import("../../../../asset-package.json-BgXWfTnb.js").then((x) => x.default))).addDependencies(["telefunc", "@universal-middleware/core"]);
6
+ return (await loadPackageJson(props, await import("../../../../asset-package.json-CBsEdGlU.js").then((x) => x.default))).addDependencies(["telefunc", "@universal-middleware/core"]);
7
7
  }
8
8
  //#endregion
9
9
  export { getPackageJson as default };