@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.
- package/dist/{asset-env-Jk0sS-Q2.js → asset-env-DvKtWq7P.js} +6 -3
- package/dist/{asset-package.json-BgXWfTnb.js → asset-package.json-CBsEdGlU.js} +1 -0
- package/dist/{asset-package.json-CJq8QmFk.js → asset-package.json-CXa26JLJ.js} +1 -0
- package/dist/{asset-package.json-DotEkyyW.js → asset-package.json-CpJdnsXW.js} +2 -1
- package/dist/asset-package.json-D5lEjBIT.js +41 -0
- package/dist/{asset-package.json-BfPjhiqX.js → asset-package.json-DcJFVtbo.js} +2 -0
- package/dist/{asset-package.json-CO-Tvf85.js → asset-package.json-WOGFbHRZ.js} +1 -0
- package/dist/{asset-package.json-D5VQND8y.js → asset-package2.json-Cqt3zXsB.js} +1 -0
- package/dist/boilerplates/@batijs/d1-sqlite/bati.config.mjs +1 -1
- package/dist/boilerplates/@batijs/docker-compose/files/$Dockerfile.js +17 -9
- package/dist/boilerplates/@batijs/docker-compose/files/$docker-compose.yml.js +1 -1
- package/dist/boilerplates/@batijs/docker-compose/files/asset-env.mjs +6 -3
- package/dist/boilerplates/@batijs/docker-compose/files/docker-compose.yml +25 -2
- package/dist/boilerplates/@batijs/drizzle/files/$package.json.js +5 -2
- package/dist/boilerplates/@batijs/drizzle/files/asset-package.json.mjs +2 -1
- package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/db.ts +11 -1
- package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/queries/todos.ts +6 -3
- package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/schema/todos.ts +11 -5
- package/dist/boilerplates/@batijs/drizzle/files/drizzle.config.ts +1 -1
- package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/db.d.mts +5 -1
- package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/queries/todos.d.mts +5 -48
- package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/schema/todos.d.mts +43 -1
- package/dist/boilerplates/@batijs/express/files/+server.ts +1 -1
- package/dist/boilerplates/@batijs/fastify/files/+server.ts +1 -1
- package/dist/boilerplates/@batijs/h3/files/+server.ts +1 -1
- package/dist/boilerplates/@batijs/hono/files/server/hono.ts +1 -1
- package/dist/boilerplates/@batijs/kysely/files/$package.json.js +6 -8
- package/dist/boilerplates/@batijs/kysely/files/asset-package.json.mjs +2 -0
- package/dist/boilerplates/@batijs/kysely/files/database/kysely/db.ts +13 -1
- package/dist/boilerplates/@batijs/kysely/files/database/kysely/migrate.ts +2 -2
- package/dist/boilerplates/@batijs/kysely/files/database/kysely/migrations/001_create_todos_table.ts +4 -5
- package/dist/boilerplates/@batijs/kysely/files/database/kysely/queries/todos.ts +3 -1
- package/dist/boilerplates/@batijs/kysely/types/database/kysely/db.d.mts +2 -1
- package/dist/boilerplates/@batijs/kysely/types/database/kysely/queries/todos.d.mts +3 -1
- package/dist/boilerplates/@batijs/postgres/bati.config.mjs +25 -0
- package/dist/boilerplates/@batijs/postgres/files/$TODO.md.js +25 -0
- package/dist/boilerplates/@batijs/postgres/files/$package.json.js +15 -0
- package/dist/boilerplates/@batijs/postgres/files/asset-package.json.mjs +39 -0
- package/dist/boilerplates/@batijs/postgres/files/database/postgres/db.ts +15 -0
- package/dist/boilerplates/@batijs/postgres/files/database/postgres/queries/todos.ts +9 -0
- package/dist/boilerplates/@batijs/postgres/files/database/postgres/schema/all.ts +1 -0
- package/dist/boilerplates/@batijs/postgres/files/database/postgres/schema/todos.ts +16 -0
- package/dist/boilerplates/@batijs/postgres/types/database/postgres/db.d.mts +6 -0
- package/dist/boilerplates/@batijs/postgres/types/database/postgres/queries/todos.d.mts +10 -0
- package/dist/boilerplates/@batijs/postgres/types/database/postgres/schema/all.d.mts +1 -0
- package/dist/boilerplates/@batijs/postgres/types/database/postgres/schema/todos.d.mts +1 -0
- package/dist/boilerplates/@batijs/prisma/bati.config.mjs +6 -12
- package/dist/boilerplates/@batijs/prisma/files/$TODO.md.js +4 -3
- package/dist/boilerplates/@batijs/shared-db/bati.config.mjs +26 -12
- package/dist/boilerplates/@batijs/shared-db/files/server/db-middleware.ts +25 -15
- package/dist/boilerplates/@batijs/shared-db/types/server/db-middleware.d.mts +9 -5
- package/dist/boilerplates/@batijs/shared-server/files/$package.json.js +1 -1
- package/dist/boilerplates/@batijs/shared-server/files/asset-package.json.mjs +1 -0
- package/dist/boilerplates/@batijs/shared-server/files/server/create-todo-handler.ts +13 -6
- package/dist/boilerplates/@batijs/shared-server/types/server/create-todo-handler.d.mts +15 -5
- package/dist/boilerplates/@batijs/shared-todo/files/global.d.ts +9 -5
- package/dist/boilerplates/@batijs/shared-todo/files/pages/todo/+data.ts +7 -2
- package/dist/boilerplates/@batijs/shared-todo/types/pages/todo/+data.d.mts +1 -3
- package/dist/boilerplates/@batijs/sqlite/bati.config.mjs +1 -1
- package/dist/boilerplates/@batijs/telefunc/files/$package.json.js +1 -1
- package/dist/boilerplates/@batijs/telefunc/files/asset-package.json.mjs +1 -0
- package/dist/boilerplates/@batijs/telefunc/files/global.d.ts +9 -6
- package/dist/boilerplates/@batijs/telefunc/files/pages/todo/TodoList.telefunc.ts +6 -2
- package/dist/boilerplates/@batijs/telefunc/files/server/telefunc-handler.ts +9 -4
- package/dist/boilerplates/@batijs/trpc/files/$package.json.js +1 -1
- package/dist/boilerplates/@batijs/trpc/files/asset-package.json.mjs +1 -0
- package/dist/boilerplates/@batijs/trpc/files/trpc/server.ts +13 -6
- package/dist/boilerplates/@batijs/trpc/types/trpc/client.d.mts +6 -0
- package/dist/boilerplates/@batijs/trpc/types/trpc/server.d.mts +22 -3
- package/dist/boilerplates/@batijs/ts-rest/files/$package.json.js +1 -1
- package/dist/boilerplates/@batijs/ts-rest/files/asset-package.json.mjs +1 -0
- package/dist/boilerplates/@batijs/ts-rest/files/server/ts-rest-handler.ts +13 -6
- package/dist/boilerplates/boilerplates.json +6 -0
- package/dist/index.js +4 -1
- package/package.json +5 -5
|
@@ -4,11 +4,14 @@ import { committedValue, isServerVar } from "@batijs/core";
|
|
|
4
4
|
//#region ../../boilerplates/docker-compose/dist/files/asset-env.mjs
|
|
5
5
|
/**
|
|
6
6
|
* `KEY=<expr>` lines for the docker-compose `services.<app>.environment` list:
|
|
7
|
-
* secrets are pulled from the host (`${KEY}`)
|
|
8
|
-
* (`${KEY
|
|
7
|
+
* secrets are pulled from the host (`${KEY}`); defaulted vars are pinned to their
|
|
8
|
+
* compose value. Pinning (not `${KEY:-default}`) is deliberate: compose loads the
|
|
9
|
+
* project `.env` for interpolation, and `.env` carries the local-dev value (e.g.
|
|
10
|
+
* `DATABASE_URL` on `localhost`), which would otherwise shadow the in-container
|
|
11
|
+
* value (the app reaching the `postgres` service over the compose network).
|
|
9
12
|
*/
|
|
10
13
|
function composeEnvEntries(registry) {
|
|
11
|
-
return registry.filter(isServerVar).map((def) => def.scope === "secret" ? `${def.key}=\${${def.key}}` : `${def.key}
|
|
14
|
+
return registry.filter(isServerVar).map((def) => def.scope === "secret" ? `${def.key}=\${${def.key}}` : `${def.key}=${committedValue(def, "compose")}`);
|
|
12
15
|
}
|
|
13
16
|
/**
|
|
14
17
|
* Dockerfile `ENV` defaults grouped by `group` (first-seen order), one
|
|
@@ -20,6 +20,7 @@ var package_default = {
|
|
|
20
20
|
"@batijs/d1-sqlite": "workspace:*",
|
|
21
21
|
"@batijs/drizzle": "workspace:*",
|
|
22
22
|
"@batijs/kysely": "workspace:*",
|
|
23
|
+
"@batijs/postgres": "workspace:*",
|
|
23
24
|
"@batijs/sqlite": "workspace:*",
|
|
24
25
|
"@types/node": "^20.19.37",
|
|
25
26
|
"@universal-middleware/core": "^0.4.17",
|
|
@@ -21,6 +21,7 @@ var package_default = {
|
|
|
21
21
|
"@batijs/d1-sqlite": "workspace:*",
|
|
22
22
|
"@batijs/drizzle": "workspace:*",
|
|
23
23
|
"@batijs/kysely": "workspace:*",
|
|
24
|
+
"@batijs/postgres": "workspace:*",
|
|
24
25
|
"@batijs/sqlite": "workspace:*",
|
|
25
26
|
"@types/node": "^20.19.37",
|
|
26
27
|
"@universal-middleware/core": "^0.4.17",
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
//#region ../../boilerplates/postgres/dist/files/asset-package.json.mjs
|
|
4
|
+
var package_default = {
|
|
5
|
+
name: "@batijs/postgres",
|
|
6
|
+
"private": true,
|
|
7
|
+
version: "0.0.1",
|
|
8
|
+
description: "",
|
|
9
|
+
type: "module",
|
|
10
|
+
scripts: {
|
|
11
|
+
"check-types": "tsc --noEmit",
|
|
12
|
+
"build": "bati-compile-boilerplate"
|
|
13
|
+
},
|
|
14
|
+
keywords: [],
|
|
15
|
+
author: "",
|
|
16
|
+
license: "MIT",
|
|
17
|
+
devDependencies: {
|
|
18
|
+
"@batijs/compile": "workspace:*",
|
|
19
|
+
"@batijs/core": "workspace:*",
|
|
20
|
+
"@types/node": "^20.19.37",
|
|
21
|
+
"dotenv": "^17.4.2",
|
|
22
|
+
"postgres": "^3.4.7",
|
|
23
|
+
"tsx": "^4.22.3"
|
|
24
|
+
},
|
|
25
|
+
files: ["dist/"],
|
|
26
|
+
exports: {
|
|
27
|
+
"./database/postgres/db": { "types": "./dist/types/database/postgres/db.d.mts" },
|
|
28
|
+
"./database/postgres/queries/todos": { "types": "./dist/types/database/postgres/queries/todos.d.mts" },
|
|
29
|
+
"./database/postgres/schema/all": { "types": "./dist/types/database/postgres/schema/all.d.mts" },
|
|
30
|
+
"./database/postgres/schema/todos": { "types": "./dist/types/database/postgres/schema/todos.d.mts" }
|
|
31
|
+
},
|
|
32
|
+
typesVersions: { "*": {
|
|
33
|
+
"database/postgres/db": ["./dist/types/database/postgres/db.d.mts"],
|
|
34
|
+
"database/postgres/queries/todos": ["./dist/types/database/postgres/queries/todos.d.mts"],
|
|
35
|
+
"database/postgres/schema/all": ["./dist/types/database/postgres/schema/all.d.mts"],
|
|
36
|
+
"database/postgres/schema/todos": ["./dist/types/database/postgres/schema/todos.d.mts"]
|
|
37
|
+
} },
|
|
38
|
+
nx: { "tags": ["type:boilerplate"] }
|
|
39
|
+
};
|
|
40
|
+
//#endregion
|
|
41
|
+
export { package_default as default };
|
|
@@ -20,6 +20,7 @@ var package_default = {
|
|
|
20
20
|
"@batijs/d1-sqlite": "workspace:*",
|
|
21
21
|
"@batijs/drizzle": "workspace:*",
|
|
22
22
|
"@batijs/kysely": "workspace:*",
|
|
23
|
+
"@batijs/postgres": "workspace:*",
|
|
23
24
|
"@batijs/sqlite": "workspace:*",
|
|
24
25
|
"@trpc/client": "^11.17.0",
|
|
25
26
|
"@trpc/server": "^11.17.0",
|
|
@@ -20,6 +20,7 @@ var package_default = {
|
|
|
20
20
|
"@batijs/d1-sqlite": "workspace:*",
|
|
21
21
|
"@batijs/drizzle": "workspace:*",
|
|
22
22
|
"@batijs/kysely": "workspace:*",
|
|
23
|
+
"@batijs/postgres": "workspace:*",
|
|
23
24
|
"@batijs/sqlite": "workspace:*",
|
|
24
25
|
"@ts-rest/core": "^3.52.1",
|
|
25
26
|
"@ts-rest/serverless": "^3.52.1",
|
|
@@ -8,7 +8,7 @@ function t(t) {
|
|
|
8
8
|
//#endregion
|
|
9
9
|
//#region bati.config.ts
|
|
10
10
|
var bati_config_default = t({ if(meta) {
|
|
11
|
-
return meta.BATI.hasD1 && meta.BATI.
|
|
11
|
+
return meta.BATI.hasD1 && !meta.BATI.hasOrm;
|
|
12
12
|
} });
|
|
13
13
|
//#endregion
|
|
14
14
|
export { bati_config_default as default };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { n as serverEnvDefaults } from "../../../../asset-env-
|
|
3
|
+
import { n as serverEnvDefaults } from "../../../../asset-env-DvKtWq7P.js";
|
|
4
4
|
import { dockerPackageManager, dockerfile, packageManager } from "@batijs/core";
|
|
5
5
|
//#region ../../boilerplates/docker-compose/dist/files/$Dockerfile.mjs
|
|
6
6
|
async function getDockerfile(props) {
|
|
@@ -20,14 +20,6 @@ async function getDockerfile(props) {
|
|
|
20
20
|
const config = dockerPackageManager(pm.name, { frozenLockfile: !meta.BATI_TEST });
|
|
21
21
|
const startupMigrations = [];
|
|
22
22
|
const migrationCopies = [];
|
|
23
|
-
if (meta.BATI.has("sqlite")) {
|
|
24
|
-
startupMigrations.push(`${run} sqlite:migrate`);
|
|
25
|
-
migrationCopies.push({
|
|
26
|
-
sources: ["/app/database/sqlite"],
|
|
27
|
-
dest: "./database/sqlite",
|
|
28
|
-
from: "builder"
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
23
|
if (meta.BATI.has("drizzle")) {
|
|
32
24
|
startupMigrations.push(`${run} drizzle:migrate`);
|
|
33
25
|
migrationCopies.push({
|
|
@@ -49,6 +41,22 @@ async function getDockerfile(props) {
|
|
|
49
41
|
from: "builder"
|
|
50
42
|
});
|
|
51
43
|
}
|
|
44
|
+
if (meta.BATI.has("sqlite") && !meta.BATI.hasOrm) {
|
|
45
|
+
startupMigrations.push(`${run} sqlite:migrate`);
|
|
46
|
+
migrationCopies.push({
|
|
47
|
+
sources: ["/app/database/sqlite"],
|
|
48
|
+
dest: "./database/sqlite",
|
|
49
|
+
from: "builder"
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (meta.BATI.has("postgres") && !meta.BATI.hasOrm) {
|
|
53
|
+
startupMigrations.push(`${run} postgres:migrate`);
|
|
54
|
+
migrationCopies.push({
|
|
55
|
+
sources: ["/app/database/postgres"],
|
|
56
|
+
dest: "./database/postgres",
|
|
57
|
+
from: "builder"
|
|
58
|
+
});
|
|
59
|
+
}
|
|
52
60
|
const startCmd = startupMigrations.length > 0 ? [
|
|
53
61
|
"sh",
|
|
54
62
|
"-c",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { t as composeEnvEntries } from "../../../../asset-env-
|
|
3
|
+
import { t as composeEnvEntries } from "../../../../asset-env-DvKtWq7P.js";
|
|
4
4
|
import { setComposeEnvironment } from "@batijs/core";
|
|
5
5
|
//#region ../../boilerplates/docker-compose/dist/files/$docker-compose.yml.mjs
|
|
6
6
|
async function getDockerCompose(props) {
|
|
@@ -2,11 +2,14 @@ import { committedValue, isServerVar } from "@batijs/core";
|
|
|
2
2
|
//#region env.ts
|
|
3
3
|
/**
|
|
4
4
|
* `KEY=<expr>` lines for the docker-compose `services.<app>.environment` list:
|
|
5
|
-
* secrets are pulled from the host (`${KEY}`)
|
|
6
|
-
* (`${KEY
|
|
5
|
+
* secrets are pulled from the host (`${KEY}`); defaulted vars are pinned to their
|
|
6
|
+
* compose value. Pinning (not `${KEY:-default}`) is deliberate: compose loads the
|
|
7
|
+
* project `.env` for interpolation, and `.env` carries the local-dev value (e.g.
|
|
8
|
+
* `DATABASE_URL` on `localhost`), which would otherwise shadow the in-container
|
|
9
|
+
* value (the app reaching the `postgres` service over the compose network).
|
|
7
10
|
*/
|
|
8
11
|
function composeEnvEntries(registry) {
|
|
9
|
-
return registry.filter(isServerVar).map((def) => def.scope === "secret" ? `${def.key}=\${${def.key}}` : `${def.key}
|
|
12
|
+
return registry.filter(isServerVar).map((def) => def.scope === "secret" ? `${def.key}=\${${def.key}}` : `${def.key}=${committedValue(def, "compose")}`);
|
|
10
13
|
}
|
|
11
14
|
/**
|
|
12
15
|
* Dockerfile `ENV` defaults grouped by `group` (first-seen order), one
|
|
@@ -8,11 +8,34 @@ services:
|
|
|
8
8
|
environment:
|
|
9
9
|
- NODE_ENV=production
|
|
10
10
|
- PORT=3000
|
|
11
|
-
# BATI.hasDatabase
|
|
11
|
+
# BATI.hasDatabase && !BATI.has("postgres")
|
|
12
12
|
volumes:
|
|
13
13
|
- sqlite_data:/app/data
|
|
14
|
+
# BATI.has("postgres")
|
|
15
|
+
depends_on:
|
|
16
|
+
postgres:
|
|
17
|
+
condition: service_healthy
|
|
18
|
+
restart: unless-stopped
|
|
19
|
+
|
|
20
|
+
# BATI.has("postgres")
|
|
21
|
+
postgres:
|
|
22
|
+
image: postgres:18-alpine
|
|
23
|
+
environment:
|
|
24
|
+
- POSTGRES_USER=${POSTGRES_USER:-postgres}
|
|
25
|
+
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-postgres}
|
|
26
|
+
- POSTGRES_DB=${POSTGRES_DB:-app}
|
|
27
|
+
volumes:
|
|
28
|
+
- postgres_data:/var/lib/postgresql
|
|
29
|
+
healthcheck:
|
|
30
|
+
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres} -d ${POSTGRES_DB:-app}"]
|
|
31
|
+
interval: 5s
|
|
32
|
+
timeout: 5s
|
|
33
|
+
retries: 10
|
|
14
34
|
restart: unless-stopped
|
|
15
35
|
|
|
16
36
|
# BATI.hasDatabase
|
|
17
37
|
volumes:
|
|
18
|
-
|
|
38
|
+
# BATI.hasDatabase && !BATI.has("postgres")
|
|
39
|
+
sqlite_data: {}
|
|
40
|
+
# BATI.has("postgres")
|
|
41
|
+
postgres_data: {}
|
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
import { loadPackageJson } from "@batijs/core";
|
|
4
4
|
//#region ../../boilerplates/drizzle/dist/files/$package.json.mjs
|
|
5
5
|
async function getPackageJson(props) {
|
|
6
|
-
|
|
6
|
+
const packageJson = await loadPackageJson(props, await import("../../../../asset-package.json-CpJdnsXW.js").then((x) => x.default));
|
|
7
|
+
const hasPostgres = props.meta.BATI.has("postgres");
|
|
8
|
+
const hasSqliteEngine = !props.meta.BATI.hasD1 && !hasPostgres;
|
|
9
|
+
return packageJson.setScript("drizzle:generate", {
|
|
7
10
|
value: "drizzle-kit generate",
|
|
8
11
|
precedence: 20
|
|
9
12
|
}).setScript("drizzle:migrate", {
|
|
@@ -16,7 +19,7 @@ async function getPackageJson(props) {
|
|
|
16
19
|
"drizzle-kit",
|
|
17
20
|
"drizzle-orm",
|
|
18
21
|
"dotenv"
|
|
19
|
-
]).addDevDependencies(["@types/better-sqlite3"],
|
|
22
|
+
]).addDevDependencies(["@types/better-sqlite3"], hasSqliteEngine).addDependencies(["better-sqlite3"], hasSqliteEngine).addDependencies(["postgres"], hasPostgres);
|
|
20
23
|
}
|
|
21
24
|
//#endregion
|
|
22
25
|
export { getPackageJson as default };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import Database from "better-sqlite3";
|
|
2
2
|
import { drizzle as drizzleSqlite } from "drizzle-orm/better-sqlite3";
|
|
3
3
|
import { drizzle as drizzleD1 } from "drizzle-orm/d1";
|
|
4
|
+
import { drizzle as drizzlePostgres } from "drizzle-orm/postgres-js";
|
|
5
|
+
import postgres from "postgres";
|
|
4
6
|
|
|
5
|
-
//# !BATI.hasD1
|
|
7
|
+
//# BATI.has("sqlite") && !BATI.hasD1
|
|
6
8
|
export function dbSqlite() {
|
|
7
9
|
const sqlite = new Database(process.env.DATABASE_URL);
|
|
8
10
|
return drizzleSqlite(sqlite);
|
|
@@ -12,3 +14,11 @@ export function dbSqlite() {
|
|
|
12
14
|
export function dbD1(d1: D1Database) {
|
|
13
15
|
return drizzleD1(d1);
|
|
14
16
|
}
|
|
17
|
+
|
|
18
|
+
//# BATI.has("postgres")
|
|
19
|
+
export function dbPostgres() {
|
|
20
|
+
if (!process.env.DATABASE_URL) {
|
|
21
|
+
throw new Error("Missing DATABASE_URL in .env file");
|
|
22
|
+
}
|
|
23
|
+
return drizzlePostgres(postgres(process.env.DATABASE_URL));
|
|
24
|
+
}
|
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
/*# BATI include-if-imported #*/
|
|
2
2
|
|
|
3
|
-
import type { dbD1, dbSqlite } from "../db";
|
|
3
|
+
import type { dbD1, dbPostgres, dbSqlite } from "../db";
|
|
4
4
|
import { todoTable } from "../schema/todos";
|
|
5
5
|
|
|
6
6
|
export function insertTodo(
|
|
7
7
|
db: BATI.If<{
|
|
8
|
+
'BATI.has("postgres")': ReturnType<typeof dbPostgres>;
|
|
8
9
|
"!BATI.hasD1": ReturnType<typeof dbSqlite>;
|
|
9
10
|
_: ReturnType<typeof dbD1>;
|
|
10
11
|
}>,
|
|
11
12
|
text: string,
|
|
12
13
|
) {
|
|
13
|
-
return db.insert(todoTable).values({ text });
|
|
14
|
+
return (db as BATI.Any).insert(todoTable).values({ text });
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export async function getAllTodos(
|
|
17
18
|
db: BATI.If<
|
|
18
19
|
{
|
|
20
|
+
'BATI.has("postgres")': ReturnType<typeof dbPostgres>;
|
|
19
21
|
"!BATI.hasD1": ReturnType<typeof dbSqlite>;
|
|
20
22
|
_: ReturnType<typeof dbD1>;
|
|
21
23
|
},
|
|
22
24
|
"union"
|
|
23
25
|
>,
|
|
24
26
|
) {
|
|
25
|
-
|
|
27
|
+
const query = (db as BATI.Any).select().from(todoTable);
|
|
28
|
+
return BATI.has("postgres") ? query : query.all();
|
|
26
29
|
}
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
/*# BATI include-if-imported #*/
|
|
2
|
+
import { pgTable, serial, varchar } from "drizzle-orm/pg-core";
|
|
2
3
|
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
3
4
|
|
|
4
|
-
// Example of defining a schema in Drizzle ORM
|
|
5
|
-
export const todoTable =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
})
|
|
5
|
+
// Example of defining a schema in Drizzle ORM.
|
|
6
|
+
export const todoTable = BATI.has("postgres")
|
|
7
|
+
? pgTable("todos", {
|
|
8
|
+
id: serial("id").primaryKey(),
|
|
9
|
+
text: varchar("text", { length: 50 }).notNull(),
|
|
10
|
+
})
|
|
11
|
+
: sqliteTable("todos", {
|
|
12
|
+
id: integer("id", { mode: "number" }).primaryKey({ autoIncrement: true }),
|
|
13
|
+
text: text("text", { length: 50 }).notNull(),
|
|
14
|
+
});
|
|
9
15
|
|
|
10
16
|
// You can then infer the types for selecting and inserting
|
|
11
17
|
export type TodoItem = typeof todoTable.$inferSelect;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Database from "better-sqlite3";
|
|
2
|
+
import postgres from "postgres";
|
|
2
3
|
|
|
3
4
|
//#region files/database/drizzle/db.d.ts
|
|
4
5
|
declare function dbSqlite(): import("drizzle-orm/better-sqlite3").BetterSQLite3Database<Record<string, never>> & {
|
|
@@ -7,5 +8,8 @@ declare function dbSqlite(): import("drizzle-orm/better-sqlite3").BetterSQLite3D
|
|
|
7
8
|
declare function dbD1(d1: D1Database): import("drizzle-orm/d1").DrizzleD1Database<Record<string, never>> & {
|
|
8
9
|
$client: D1Database;
|
|
9
10
|
};
|
|
11
|
+
declare function dbPostgres(): import("drizzle-orm/postgres-js").PostgresJsDatabase<Record<string, never>> & {
|
|
12
|
+
$client: postgres.Sql<{}>;
|
|
13
|
+
};
|
|
10
14
|
//#endregion
|
|
11
|
-
export { dbD1, dbSqlite };
|
|
15
|
+
export { dbD1, dbPostgres, dbSqlite };
|
|
@@ -1,58 +1,15 @@
|
|
|
1
|
-
import { dbD1, dbSqlite } from "../db.mjs";
|
|
1
|
+
import { dbD1, dbPostgres, dbSqlite } from "../db.mjs";
|
|
2
2
|
|
|
3
3
|
//#region files/database/drizzle/queries/todos.d.ts
|
|
4
4
|
declare function insertTodo(db: BATI.If<{
|
|
5
|
+
'BATI.has("postgres")': ReturnType<typeof dbPostgres>;
|
|
5
6
|
"!BATI.hasD1": ReturnType<typeof dbSqlite>;
|
|
6
7
|
_: ReturnType<typeof dbD1>;
|
|
7
|
-
}>, text: string):
|
|
8
|
-
name: "todos";
|
|
9
|
-
schema: undefined;
|
|
10
|
-
columns: {
|
|
11
|
-
id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
12
|
-
name: "id";
|
|
13
|
-
tableName: "todos";
|
|
14
|
-
dataType: "number";
|
|
15
|
-
columnType: "SQLiteInteger";
|
|
16
|
-
data: number;
|
|
17
|
-
driverParam: number;
|
|
18
|
-
notNull: true;
|
|
19
|
-
hasDefault: true;
|
|
20
|
-
isPrimaryKey: true;
|
|
21
|
-
isAutoincrement: false;
|
|
22
|
-
hasRuntimeDefault: false;
|
|
23
|
-
enumValues: undefined;
|
|
24
|
-
baseColumn: never;
|
|
25
|
-
identity: undefined;
|
|
26
|
-
generated: undefined;
|
|
27
|
-
}, {}, {}>;
|
|
28
|
-
text: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
29
|
-
name: "text";
|
|
30
|
-
tableName: "todos";
|
|
31
|
-
dataType: "string";
|
|
32
|
-
columnType: "SQLiteText";
|
|
33
|
-
data: string;
|
|
34
|
-
driverParam: string;
|
|
35
|
-
notNull: true;
|
|
36
|
-
hasDefault: false;
|
|
37
|
-
isPrimaryKey: false;
|
|
38
|
-
isAutoincrement: false;
|
|
39
|
-
hasRuntimeDefault: false;
|
|
40
|
-
enumValues: [string, ...string[]];
|
|
41
|
-
baseColumn: never;
|
|
42
|
-
identity: undefined;
|
|
43
|
-
generated: undefined;
|
|
44
|
-
}, {}, {
|
|
45
|
-
length: 50;
|
|
46
|
-
}>;
|
|
47
|
-
};
|
|
48
|
-
dialect: "sqlite";
|
|
49
|
-
}>, "sync", import("better-sqlite3").RunResult, undefined, false, never>;
|
|
8
|
+
}>, text: string): any;
|
|
50
9
|
declare function getAllTodos(db: BATI.If<{
|
|
10
|
+
'BATI.has("postgres")': ReturnType<typeof dbPostgres>;
|
|
51
11
|
"!BATI.hasD1": ReturnType<typeof dbSqlite>;
|
|
52
12
|
_: ReturnType<typeof dbD1>;
|
|
53
|
-
}, "union">): Promise<
|
|
54
|
-
id: number;
|
|
55
|
-
text: string;
|
|
56
|
-
}[]>;
|
|
13
|
+
}, "union">): Promise<any>;
|
|
57
14
|
//#endregion
|
|
58
15
|
export { getAllTodos, insertTodo };
|
|
@@ -1,5 +1,47 @@
|
|
|
1
1
|
//#region files/database/drizzle/schema/todos.d.ts
|
|
2
|
-
declare const todoTable: import("drizzle-orm/
|
|
2
|
+
declare const todoTable: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
3
|
+
name: "todos";
|
|
4
|
+
schema: undefined;
|
|
5
|
+
columns: {
|
|
6
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
7
|
+
name: "id";
|
|
8
|
+
tableName: "todos";
|
|
9
|
+
dataType: "number";
|
|
10
|
+
columnType: "PgSerial";
|
|
11
|
+
data: number;
|
|
12
|
+
driverParam: number;
|
|
13
|
+
notNull: true;
|
|
14
|
+
hasDefault: true;
|
|
15
|
+
isPrimaryKey: true;
|
|
16
|
+
isAutoincrement: false;
|
|
17
|
+
hasRuntimeDefault: false;
|
|
18
|
+
enumValues: undefined;
|
|
19
|
+
baseColumn: never;
|
|
20
|
+
identity: undefined;
|
|
21
|
+
generated: undefined;
|
|
22
|
+
}, {}, {}>;
|
|
23
|
+
text: import("drizzle-orm/pg-core").PgColumn<{
|
|
24
|
+
name: "text";
|
|
25
|
+
tableName: "todos";
|
|
26
|
+
dataType: "string";
|
|
27
|
+
columnType: "PgVarchar";
|
|
28
|
+
data: string;
|
|
29
|
+
driverParam: string;
|
|
30
|
+
notNull: true;
|
|
31
|
+
hasDefault: false;
|
|
32
|
+
isPrimaryKey: false;
|
|
33
|
+
isAutoincrement: false;
|
|
34
|
+
hasRuntimeDefault: false;
|
|
35
|
+
enumValues: [string, ...string[]];
|
|
36
|
+
baseColumn: never;
|
|
37
|
+
identity: undefined;
|
|
38
|
+
generated: undefined;
|
|
39
|
+
}, {}, {
|
|
40
|
+
length: 50;
|
|
41
|
+
}>;
|
|
42
|
+
};
|
|
43
|
+
dialect: "pg";
|
|
44
|
+
}> | import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
3
45
|
name: "todos";
|
|
4
46
|
schema: undefined;
|
|
5
47
|
columns: {
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { loadPackageJson } from "@batijs/core";
|
|
3
|
+
import { loadPackageJson, packageManager } from "@batijs/core";
|
|
4
4
|
//#region ../../boilerplates/kysely/dist/files/$package.json.mjs
|
|
5
5
|
async function getPackageJson(props) {
|
|
6
|
-
const packageJson = await loadPackageJson(props, await import("../../../../asset-package.json-
|
|
6
|
+
const packageJson = await loadPackageJson(props, await import("../../../../asset-package.json-DcJFVtbo.js").then((x) => x.default));
|
|
7
7
|
if (props.meta.BATI.hasD1) return packageJson.addDependencies(["kysely", "kysely-d1"]);
|
|
8
|
+
const hasPostgres = props.meta.BATI.has("postgres");
|
|
9
|
+
const bunDirect = packageManager().name === "bun" && hasPostgres;
|
|
8
10
|
return packageJson.setScript("kysely:migrate", {
|
|
9
|
-
value: "tsx ./database/kysely/migrate.ts
|
|
11
|
+
value: `${bunDirect ? "bun" : "tsx"} ./database/kysely/migrate.ts`,
|
|
10
12
|
precedence: 20
|
|
11
|
-
}).addDevDependencies(["@types/better-sqlite3"]).addDevDependencies(["tsx"], ["kysely:migrate"]).addDependencies([
|
|
12
|
-
"better-sqlite3",
|
|
13
|
-
"dotenv",
|
|
14
|
-
"kysely"
|
|
15
|
-
]);
|
|
13
|
+
}).addDevDependencies(["@types/better-sqlite3"], !hasPostgres).addDevDependencies(["tsx"], ["kysely:migrate"], !bunDirect).addDependencies(["dotenv", "kysely"]).addDependencies(["better-sqlite3"], !hasPostgres).addDependencies(["postgres", "kysely-postgres-js"], hasPostgres);
|
|
16
14
|
}
|
|
17
15
|
//#endregion
|
|
18
16
|
export { getPackageJson as default };
|
|
@@ -5,9 +5,11 @@ import "dotenv/config";
|
|
|
5
5
|
import SQLite from "better-sqlite3";
|
|
6
6
|
import { Kysely, SqliteDialect } from "kysely";
|
|
7
7
|
import { D1Dialect } from "kysely-d1";
|
|
8
|
+
import { PostgresJSDialect } from "kysely-postgres-js";
|
|
9
|
+
import postgres from "postgres";
|
|
8
10
|
import type { Database } from "./types";
|
|
9
11
|
|
|
10
|
-
//# !BATI.hasD1
|
|
12
|
+
//# BATI.has("sqlite") && !BATI.hasD1
|
|
11
13
|
export function dbKysely() {
|
|
12
14
|
const dialect = new SqliteDialect({
|
|
13
15
|
database: new SQLite(process.env.DATABASE_URL),
|
|
@@ -23,3 +25,13 @@ export function dbKyselyD1(d1: D1Database) {
|
|
|
23
25
|
dialect: new D1Dialect({ database: d1 }),
|
|
24
26
|
});
|
|
25
27
|
}
|
|
28
|
+
|
|
29
|
+
//# BATI.has("postgres")
|
|
30
|
+
export function dbKyselyPostgres() {
|
|
31
|
+
if (!process.env.DATABASE_URL) {
|
|
32
|
+
throw new Error("Missing DATABASE_URL in .env file");
|
|
33
|
+
}
|
|
34
|
+
return new Kysely<Database>({
|
|
35
|
+
dialect: new PostgresJSDialect({ postgres: postgres(process.env.DATABASE_URL) }),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
@@ -5,13 +5,13 @@ import * as path from "node:path";
|
|
|
5
5
|
import { dirname } from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { FileMigrationProvider, Migrator } from "kysely/migration";
|
|
8
|
-
import { dbKysely } from "./db";
|
|
8
|
+
import { dbKysely, dbKyselyPostgres } from "./db";
|
|
9
9
|
|
|
10
10
|
const __filename = fileURLToPath(import.meta.url);
|
|
11
11
|
const __dirname = dirname(__filename);
|
|
12
12
|
|
|
13
13
|
async function migrateToLatest() {
|
|
14
|
-
const db = dbKysely();
|
|
14
|
+
const db = BATI.has("postgres") ? dbKyselyPostgres() : dbKysely();
|
|
15
15
|
const migrator = new Migrator({
|
|
16
16
|
db,
|
|
17
17
|
provider: new FileMigrationProvider({
|
package/dist/boilerplates/@batijs/kysely/files/database/kysely/migrations/001_create_todos_table.ts
CHANGED
|
@@ -3,11 +3,10 @@ import type { Kysely } from "kysely";
|
|
|
3
3
|
import type { Database } from "../types";
|
|
4
4
|
|
|
5
5
|
export async function up(db: Kysely<Database>): Promise<void> {
|
|
6
|
-
|
|
7
|
-
.createTable("todos")
|
|
8
|
-
.addColumn("id", "integer", (col) => col.primaryKey().autoIncrement())
|
|
9
|
-
|
|
10
|
-
.execute();
|
|
6
|
+
const withId = BATI.has("postgres")
|
|
7
|
+
? db.schema.createTable("todos").addColumn("id", "serial", (col) => col.primaryKey())
|
|
8
|
+
: db.schema.createTable("todos").addColumn("id", "integer", (col) => col.primaryKey().autoIncrement());
|
|
9
|
+
await withId.addColumn("text", "text", (col) => col.notNull()).execute();
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
export async function down(db: Kysely<Database>): Promise<void> {
|