@nest-arch/tui 0.1.38 → 0.1.45

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 (52) hide show
  1. package/dist/cli.js +1 -1
  2. package/dist/index-BUgQzcBt.js +4 -0
  3. package/dist/index-E3XHqeRi.js +117 -0
  4. package/dist/index.js +1 -1
  5. package/dist/templates/base/.env.hbs +17 -0
  6. package/dist/templates/base/.gitignore.hbs +3 -0
  7. package/dist/templates/base/README.md.hbs +37 -0
  8. package/dist/templates/base/pnpm-workspace.yaml.hbs +4 -0
  9. package/dist/templates/base/prisma.config.ts.hbs +11 -0
  10. package/dist/templates/base/src/app.controller.spec.ts.hbs +21 -2
  11. package/dist/templates/base/src/app.controller.ts.hbs +6 -1
  12. package/dist/templates/base/src/app.module.ts.hbs +20 -1
  13. package/dist/templates/base/src/app.service.ts.hbs +7 -0
  14. package/dist/templates/base/src/database/adapters/interfaces/db-adapter.interface.ts.hbs +14 -0
  15. package/dist/templates/base/src/database/adapters/mongo/prisma-mongo.adapter.ts.hbs +25 -0
  16. package/dist/templates/base/src/database/adapters/mongo/raw-mongo.adapter.ts.hbs +17 -0
  17. package/dist/templates/base/src/database/adapters/sql/drizzle-sql.adapter.ts.hbs +24 -0
  18. package/dist/templates/base/src/database/adapters/sql/prisma-sql.adapter.ts.hbs +29 -0
  19. package/dist/templates/base/src/database/adapters/sql/raw-sql.adapter.ts.hbs +49 -0
  20. package/dist/templates/base/src/database/adapters/sql/typeorm-sql.adapter.ts.hbs +23 -0
  21. package/dist/templates/base/src/database/db.module.ts.hbs +244 -0
  22. package/dist/templates/base/src/database/db.service.ts.hbs +88 -0
  23. package/dist/templates/base/src/database/entities/todo.entity.ts.hbs +32 -0
  24. package/dist/templates/base/src/database/index.ts.hbs +10 -0
  25. package/dist/templates/base/src/database/orm/drizzle/schema.ts.hbs +30 -0
  26. package/dist/templates/base/src/database/orm/typeorm/data-source.ts.hbs +24 -0
  27. package/dist/templates/base/src/database/schema/index.ts.hbs +32 -0
  28. package/dist/templates/base/src/main.ts.hbs +4 -1
  29. package/dist/templates/base/tsconfig.json.hbs +1 -1
  30. package/dist/templates/extras/docker/Dockerfile.hbs +22 -2
  31. package/dist/templates/extras/docker/docker-compose.yml.hbs +11 -3
  32. package/dist/templates/monorepo/apps/api-gateway/src/app.controller.spec.ts.hbs +21 -2
  33. package/dist/templates/monorepo/apps/api-gateway/src/app.module.ts.hbs +20 -1
  34. package/dist/templates/monorepo/apps/api-gateway/src/app.service.ts.hbs +7 -0
  35. package/dist/templates/monorepo/apps/api-gateway/src/main.ts.hbs +4 -1
  36. package/dist/templates/monorepo/packages/db/package.json.hbs +21 -0
  37. package/dist/templates/monorepo/packages/db/tsconfig.json.hbs +4 -0
  38. package/dist/templates/monorepo/packages/env/src/api-gateway.ts.hbs +12 -0
  39. package/dist/templates/monorepo/root/.gitignore.hbs +3 -0
  40. package/dist/templates/monorepo/root/README.md.hbs +37 -0
  41. package/dist/templates/single-project/architecture/nest-api/src/main.ts.hbs +4 -1
  42. package/dist/templates/single-project/architecture/nest-gateway/src/app.controller.ts.hbs +4 -0
  43. package/dist/templates/single-project/architecture/nest-gateway/src/app.module.ts.hbs +20 -1
  44. package/dist/templates/single-project/architecture/nest-gateway/src/app.service.ts.hbs +11 -1
  45. package/dist/templates/single-project/architecture/nest-gateway/src/main.ts.hbs +4 -1
  46. package/dist/templates/single-project/architecture/nest-microservice/src/app.module.ts.hbs +20 -1
  47. package/dist/templates/single-project/architecture/nest-microservice/src/app.service.ts.hbs +7 -0
  48. package/dist/templates/single-project/architecture/nest-microservice/src/main.ts.hbs +4 -1
  49. package/dist/templates/single-project/shared/config/env.ts.hbs +16 -0
  50. package/package.json +2 -2
  51. package/dist/index-CtVIAGtc.js +0 -4
  52. package/dist/index-D8EatQzo.js +0 -50
@@ -1,9 +1,22 @@
1
+ // oxlint-disable vitest/require-mock-type-parameters
1
2
  import type { TestingModule } from "@nestjs/testing";
2
3
  import { Test } from "@nestjs/testing";
3
- import { beforeEach, describe, expect, it } from "vitest";
4
+ import { beforeEach, describe, expect, it, vi } from "vitest";
4
5
 
5
6
  import { AppController } from "./app.controller.js";
6
7
  import { AppService } from "./app.service.js";
8
+ {{#if (or hasDatabase hasOrm)}}
9
+ import type { ISqlAdapter } from "./database/adapters/interfaces/db-adapter.interface.js";
10
+ import { DbService } from "./database/db.service.js";
11
+ {{/if}}
12
+
13
+ {{#if (or hasDatabase hasOrm)}}
14
+ const mockSqlAdapter: ISqlAdapter = {
15
+ execute: vi.fn().mockResolvedValue(null),
16
+ getClient: vi.fn().mockReturnValue({}),
17
+ query: vi.fn().mockResolvedValue([]),
18
+ };
19
+ {{/if}}
7
20
 
8
21
  describe(AppController, () => {
9
22
  let appController: AppController;
@@ -11,7 +24,13 @@ describe(AppController, () => {
11
24
  beforeEach(async () => {
12
25
  const app: TestingModule = await Test.createTestingModule({
13
26
  controllers: [AppController],
14
- providers: [AppService],
27
+ providers: [
28
+ AppService,
29
+ {{#if (or hasDatabase hasOrm)}}
30
+ DbService,
31
+ { provide: "SQL_ADAPTER", useValue: mockSqlAdapter },
32
+ {{/if}}
33
+ ],
15
34
  }).compile();
16
35
 
17
36
  appController = app.get<AppController>(AppController);
@@ -1,11 +1,16 @@
1
1
  import { Controller, Get } from "@nestjs/common";
2
-
2
+ {{#if (or (eq auth "better-auth") (eq auth "better-auth:stateless"))}}
3
+ import { AllowAnonymous } from "@thallesp/nestjs-better-auth";
4
+ {{/if}}
3
5
  import { AppService } from "./app.service.js";
4
6
 
5
7
  @Controller()
6
8
  export class AppController {
7
9
  constructor(private readonly appService: AppService) {}
8
10
 
11
+ {{#if (or (eq auth "better-auth") (eq auth "better-auth:stateless"))}}
12
+ @AllowAnonymous()
13
+ {{/if}}
9
14
  @Get()
10
15
  getHello(): string {
11
16
  return this.appService.getHello();
@@ -1,11 +1,30 @@
1
1
  import { Module } from "@nestjs/common";
2
+ {{#if (or hasDatabase hasOrm)}}
3
+ import { env } from "./config/env.js";
4
+ {{/if}}
5
+ import { DbModule } from "./database/db.module.js";
6
+ {{#if (or (eq auth "better-auth") (eq auth "better-auth:stateless"))}}
7
+ import { AuthModule } from "./auth/auth.module.js";
8
+ {{/if}}
2
9
 
3
10
  import { AppController } from "./app.controller.js";
4
11
  import { AppService } from "./app.service.js";
5
12
 
6
13
  @Module({
7
14
  controllers: [AppController],
8
- imports: [],
15
+ imports: [
16
+ {{#if (or hasDatabase hasOrm)}}
17
+ DbModule.forRoot({
18
+ {{#if hasPostgres}}postgresUrl: env.POSTGRES_URL,{{/if}}
19
+ {{#if hasMysql}}mysqlUrl: env.MYSQL_URL,{{/if}}
20
+ {{#if hasSqlite}}sqlitePath: env.SQLITE_PATH,{{/if}}
21
+ {{#if hasMongodb}}mongodbUrl: env.MONGODB_URL,{{/if}}
22
+ }),
23
+ {{/if}}
24
+ {{#if (or (eq auth "better-auth") (eq auth "better-auth:stateless"))}}
25
+ AuthModule,
26
+ {{/if}}
27
+ ],
9
28
  providers: [AppService],
10
29
  })
11
30
  export class AppModule {}
@@ -1,7 +1,14 @@
1
1
  import { Injectable } from "@nestjs/common";
2
+ {{#if (or hasDatabase hasOrm)}}
3
+ import { DbService } from "./database/db.service.js";
4
+ {{/if}}
2
5
 
3
6
  @Injectable()
4
7
  export class AppService {
8
+ {{#if (or hasDatabase hasOrm)}}
9
+ constructor(private readonly db: DbService) {}
10
+
11
+ {{/if}}
5
12
  getHello(): string {
6
13
  return "Hello World!";
7
14
  }
@@ -0,0 +1,14 @@
1
+ {{#if (or hasPostgres hasMysql hasSqlite)}}
2
+ export interface ISqlAdapter<TClient = unknown> {
3
+ query<T = unknown>(sql: string, params?: unknown[]): Promise<T[]>;
4
+ execute(sql: string, params?: unknown[]): Promise<unknown>;
5
+ getClient(): TClient;
6
+ }
7
+ {{/if}}
8
+
9
+ {{#if hasMongodb}}
10
+ export interface IMongoAdapter<TClient = unknown> {
11
+ collection<T = unknown>(name: string): T;
12
+ getClient(): TClient;
13
+ }
14
+ {{/if}}
@@ -0,0 +1,25 @@
1
+ import { Injectable, Inject } from '@nestjs/common';
2
+ import { IMongoAdapter } from '../interfaces/db-adapter.interface.js';
3
+ {{#if isMonorepo}}
4
+ import type { PrismaClient } from '../../../database/orm/prisma/generated/client.js';
5
+ {{else}}
6
+ import type { PrismaClient } from '../../orm/prisma/generated/client.js';
7
+ {{/if}}
8
+
9
+ @Injectable()
10
+ export class PrismaMongoAdapter implements IMongoAdapter<PrismaClient> {
11
+ constructor(
12
+ @Inject('PRISMA_MONGO_CLIENT') private readonly prisma: PrismaClient
13
+ ) {}
14
+ collection<T = unknown>(name: string): T {
15
+ return this.prisma[name as keyof PrismaClient] as T;
16
+ }
17
+
18
+ async runCommand(command: unknown): Promise<unknown> {
19
+ return this.prisma.$runCommandRaw(command);
20
+ }
21
+
22
+ getClient(): PrismaClient {
23
+ return this.prisma;
24
+ }
25
+ }
@@ -0,0 +1,17 @@
1
+ import { Injectable, Inject } from '@nestjs/common';
2
+ import { IMongoAdapter } from '../interfaces/db-adapter.interface.js';
3
+
4
+ @Injectable()
5
+ export class RawMongoAdapter implements IMongoAdapter {
6
+ constructor(
7
+ @Inject('MONGODB_CLIENT') private readonly db: any
8
+ ) {}
9
+
10
+ collection(name: string): any {
11
+ return this.db.collection(name);
12
+ }
13
+
14
+ getClient(): any {
15
+ return this.db;
16
+ }
17
+ }
@@ -0,0 +1,24 @@
1
+ // oxlint-disable typescript/no-explicit-any require-await
2
+ import { Injectable, Inject } from '@nestjs/common';
3
+ import { sql } from 'drizzle-orm';
4
+ import { ISqlAdapter } from '../interfaces/db-adapter.interface.js';
5
+
6
+ @Injectable()
7
+ export class DrizzleSqlAdapter<TClient = unknown> implements ISqlAdapter<TClient> {
8
+ constructor(
9
+ @Inject('DRIZZLE_CLIENT') private readonly db: TClient
10
+ ) {}
11
+
12
+ async query<T = unknown>(queryString: string, _params: unknown[] = []): Promise<T[]> {
13
+ const result = await (this.db as any).execute(sql.raw(queryString));
14
+ return (result.rows || result) as T[];
15
+ }
16
+
17
+ async execute(queryString: string, _params: unknown[] = []): Promise<unknown> {
18
+ return (this.db as any).execute(sql.raw(queryString));
19
+ }
20
+
21
+ getClient(): TClient {
22
+ return this.db;
23
+ }
24
+ }
@@ -0,0 +1,29 @@
1
+ // oxlint-disable typescript/no-explicit-any require-await
2
+ import { Injectable, Inject } from '@nestjs/common';
3
+ import { ISqlAdapter } from '../interfaces/db-adapter.interface.js';
4
+ {{#if isMonorepo}}
5
+ import type { PrismaClient } from '../../../database/orm/prisma/generated/client.js';
6
+ {{else}}
7
+ import type { PrismaClient } from '../../orm/prisma/generated/client.js';
8
+ {{/if}}
9
+
10
+
11
+
12
+ @Injectable()
13
+ export class PrismaSqlAdapter implements ISqlAdapter<PrismaClient> {
14
+ constructor(
15
+ @Inject('PRISMA_SQL_CLIENT') private readonly prisma: PrismaClient
16
+ ) {}
17
+
18
+ async query<T = any>(sql: string, params: any[] = []): Promise<T[]> {
19
+ return this.prisma.$queryRawUnsafe(sql, ...params);
20
+ }
21
+
22
+ async execute(sql: string, params: any[] = []): Promise<any> {
23
+ return this.prisma.$executeRawUnsafe(sql, ...params);
24
+ }
25
+
26
+ getClient(): PrismaClient {
27
+ return this.prisma;
28
+ }
29
+ }
@@ -0,0 +1,49 @@
1
+ import { Injectable, Inject } from '@nestjs/common';
2
+ import { ISqlAdapter } from '../interfaces/db-adapter.interface.js';
3
+
4
+ @Injectable()
5
+ export class RawSqlAdapter implements ISqlAdapter {
6
+ constructor(
7
+ @Inject('SQL_CLIENT') private readonly db: any
8
+ ) {}
9
+
10
+ async query<T = any>(queryString: string, params: any[] = []): Promise<T[]> {
11
+ if (typeof this.db.query === 'function') {
12
+ const result = await this.db.query(queryString, params);
13
+ return result.rows ?? result[0] ?? [];
14
+ }
15
+
16
+ if (typeof this.db.execute === 'function') {
17
+ const result = await this.db.execute(queryString, params);
18
+ return result[0] ?? result.rows ?? [];
19
+ }
20
+
21
+ if (typeof this.db.prepare === 'function') {
22
+ const stmt = this.db.prepare(queryString);
23
+ return stmt.all(...params) as T[];
24
+ }
25
+
26
+ throw new Error('Unsupported SQL client for raw SQL adapter');
27
+ }
28
+
29
+ async execute(queryString: string, params: any[] = []): Promise<any> {
30
+ if (typeof this.db.query === 'function') {
31
+ return this.db.query(queryString, params);
32
+ }
33
+
34
+ if (typeof this.db.execute === 'function') {
35
+ return this.db.execute(queryString, params);
36
+ }
37
+
38
+ if (typeof this.db.prepare === 'function') {
39
+ const stmt = this.db.prepare(queryString);
40
+ return stmt.run(...params);
41
+ }
42
+
43
+ throw new Error('Unsupported SQL client for raw SQL adapter');
44
+ }
45
+
46
+ getClient(): any {
47
+ return this.db;
48
+ }
49
+ }
@@ -0,0 +1,23 @@
1
+ // oxlint-disable typescript/no-explicit-any require-await
2
+ import { Injectable, Inject } from '@nestjs/common';
3
+ import type { DataSource } from 'typeorm';
4
+ import type { ISqlAdapter } from '../interfaces/db-adapter.interface.js';
5
+
6
+ @Injectable()
7
+ export class TypeormSqlAdapter implements ISqlAdapter<DataSource> {
8
+ constructor(
9
+ @Inject('TYPEORM_DATA_SOURCE') private readonly dataSource: DataSource
10
+ ) {}
11
+
12
+ async query<T = any>(sql: string, params: any[] = []): Promise<T[]> {
13
+ return this.dataSource.query(sql, params);
14
+ }
15
+
16
+ async execute(sql: string, params: any[] = []): Promise<any> {
17
+ return this.dataSource.query(sql, params);
18
+ }
19
+
20
+ getClient(): DataSource {
21
+ return this.dataSource;
22
+ }
23
+ }
@@ -0,0 +1,244 @@
1
+ import { DynamicModule, Module, Global, Provider } from '@nestjs/common';
2
+ import { DbService } from './db.service.js';
3
+
4
+ {{#if usePrisma}}
5
+ {{#if isMonorepo}}
6
+ import { PrismaClient } from '../database/orm/prisma/generated/client.js';
7
+ {{else}}
8
+ import { PrismaClient } from '../database/orm/prisma/generated/client.js';
9
+ {{/if}}
10
+ {{#if (or hasPostgres hasMysql hasSqlite)}}
11
+ import { PrismaSqlAdapter } from './adapters/sql/prisma-sql.adapter.js';
12
+ {{/if}}
13
+ {{#if hasPostgres}}
14
+ import { PrismaPg } from '@prisma/adapter-pg';
15
+ {{/if}}
16
+ {{#if hasMysql}}
17
+ import { PrismaMySql } from '@prisma/adapter-mysql2';
18
+ {{/if}}
19
+ {{#if hasSqlite}}
20
+ import { PrismaBetterSqlite3 } from '@prisma/adapter-better-sqlite3';
21
+ {{/if}}
22
+ {{#if hasMongodb}}
23
+ import { PrismaMongoAdapter } from './adapters/mongo/prisma-mongo.adapter.js';
24
+ {{/if}}
25
+ {{/if}}
26
+
27
+ {{#if useDrizzle}}
28
+ import { DrizzleSqlAdapter } from './adapters/sql/drizzle-sql.adapter.js';
29
+ import * as schema from './orm/drizzle/schema.js';
30
+ {{#if hasPostgres}}
31
+ import { drizzle } from 'drizzle-orm/node-postgres';
32
+ import { Pool } from "pg"
33
+ {{/if}}
34
+ {{#if hasMysql}}
35
+ import { drizzle } from 'drizzle-orm/mysql2';
36
+ import mysql from 'mysql2/promise';
37
+ {{/if}}
38
+ {{#if hasSqlite}}
39
+ import { drizzle } from 'drizzle-orm/better-sqlite3';
40
+ import Database from 'better-sqlite3';
41
+ {{/if}}
42
+ {{/if}}
43
+
44
+ {{#if useTypeorm}}
45
+ import { TypeormSqlAdapter } from './adapters/sql/typeorm-sql.adapter.js';
46
+ import { AppDataSource } from "./orm/typeorm/data-source.js";
47
+ {{/if}}
48
+
49
+ {{#if useRawSql}}
50
+ {{#if (or hasPostgres hasMysql hasSqlite)}}
51
+ import { RawSqlAdapter } from './adapters/sql/raw-sql.adapter.js';
52
+ {{#if hasPostgres}}
53
+ import { Pool } from "pg"
54
+ {{/if}}
55
+ {{#if hasMysql}}
56
+ import mysql from 'mysql2';
57
+ {{/if}}
58
+ {{#if hasSqlite}}
59
+ import Database from 'better-sqlite3';
60
+ {{/if}}
61
+ {{/if}}
62
+ {{#if hasMongodb}}
63
+ import { RawMongoAdapter } from './adapters/mongo/raw-mongo.adapter.js';
64
+ import { MongoClient } from 'mongodb';
65
+ {{/if}}
66
+ {{/if}}
67
+
68
+ export interface DbModuleOptions {
69
+ {{#if hasPostgres}}
70
+ postgresUrl?: string;
71
+ {{/if}}
72
+ {{#if hasMysql}}
73
+ mysqlUrl?: string;
74
+ {{/if}}
75
+ {{#if hasSqlite}}
76
+ sqlitePath?: string;
77
+ {{/if}}
78
+ {{#if hasMongodb}}
79
+ mongodbUrl?: string;
80
+ {{/if}}
81
+ {{#if useTypeorm}}
82
+ entities?: string[];
83
+ {{/if}}
84
+ }
85
+
86
+ @Global()
87
+ @Module({})
88
+ export class DbModule {
89
+ static forRoot(options: DbModuleOptions): DynamicModule {
90
+ const providers: Provider[] = [DbService];
91
+
92
+ {{#if usePrisma}}
93
+ {{#if (or hasPostgres hasMysql hasSqlite)}}
94
+ {{#if hasPostgres}}
95
+ const sqlAdapter = new PrismaPg({
96
+ connectionString: options.postgresUrl,
97
+ });
98
+ const prismaSql = new PrismaClient({ adapter: sqlAdapter });
99
+ {{/if}}
100
+ {{#if hasMysql}}
101
+ const sqlAdapter = new PrismaMySql({
102
+ uri: options.mysqlUrl,
103
+ });
104
+ const prismaSql = new PrismaClient({ adapter: sqlAdapter });
105
+ {{/if}}
106
+ {{#if hasSqlite}}
107
+ const sqlAdapter = new PrismaBetterSqlite3({
108
+ url: options.sqlitePath || ':memory:',
109
+ });
110
+ const prismaSql = new PrismaClient({ adapter: sqlAdapter });
111
+ {{/if}}
112
+ providers.push({
113
+ provide: 'PRISMA_SQL_CLIENT',
114
+ useValue: prismaSql,
115
+ });
116
+ providers.push({
117
+ provide: 'SQL_ADAPTER',
118
+ useClass: PrismaSqlAdapter,
119
+ });
120
+ {{/if}}
121
+
122
+ {{#if hasMongodb}}
123
+ const prismaMongo = new PrismaClient({
124
+ datasources: {
125
+ db: {
126
+ url: options.mongodbUrl,
127
+ },
128
+ },
129
+ });
130
+ providers.push({
131
+ provide: 'PRISMA_MONGO_CLIENT',
132
+ useValue: prismaMongo,
133
+ });
134
+ providers.push({
135
+ provide: 'MONGO_ADAPTER',
136
+ useClass: PrismaMongoAdapter,
137
+ });
138
+ {{/if}}
139
+ {{/if}}
140
+
141
+ {{#if useDrizzle}}
142
+ {{#if hasPostgres}}
143
+ const pool = new Pool({
144
+ connectionString: options.postgresUrl,
145
+ });
146
+ const drizzleClient = drizzle({ client: pool, schema });
147
+ providers.push({
148
+ provide: 'DRIZZLE_CLIENT',
149
+ useValue: drizzleClient,
150
+ });
151
+ {{/if}}
152
+ {{#if hasMysql}}
153
+ const pool = mysql.createPool({
154
+ uri: options.mysqlUrl,
155
+ });
156
+ const drizzleClient = drizzle({ client: pool, schema });
157
+ providers.push({
158
+ provide: 'DRIZZLE_CLIENT',
159
+ useValue: drizzleClient,
160
+ });
161
+ {{/if}}
162
+ {{#if hasSqlite}}
163
+ const sqliteDb = new Database(options.sqlitePath || ':memory:');
164
+ const drizzleClient = drizzle({ client: sqliteDb, schema });
165
+ providers.push({
166
+ provide: 'DRIZZLE_CLIENT',
167
+ useValue: drizzleClient,
168
+ });
169
+ {{/if}}
170
+
171
+ providers.push({
172
+ provide: 'SQL_ADAPTER',
173
+ useClass: DrizzleSqlAdapter,
174
+ });
175
+ {{/if}}
176
+
177
+ {{#if useTypeorm}}
178
+ providers.push({
179
+ provide: 'TYPEORM_DATA_SOURCE',
180
+ useFactory: async () => {
181
+ return AppDataSource.initialize();
182
+ },
183
+ });
184
+ providers.push({
185
+ provide: 'SQL_ADAPTER',
186
+ useClass: TypeormSqlAdapter,
187
+ });
188
+ {{/if}}
189
+
190
+ {{#if useRawSql}}
191
+ {{#if (or hasPostgres hasMysql hasSqlite)}}
192
+ {{#if hasPostgres}}
193
+ const pool = new Pool({
194
+ connectionString: options.postgresUrl,
195
+ });
196
+ providers.push({
197
+ provide: 'SQL_CLIENT',
198
+ useValue: pool,
199
+ });
200
+ {{/if}}
201
+ {{#if hasMysql}}
202
+ const pool = mysql.createPool({
203
+ uri: options.mysqlUrl,
204
+ });
205
+ providers.push({
206
+ provide: 'SQL_CLIENT',
207
+ useValue: pool,
208
+ });
209
+ {{/if}}
210
+ {{#if hasSqlite}}
211
+ const sqliteDb = new Database(options.sqlitePath || ':memory:');
212
+ providers.push({
213
+ provide: 'SQL_CLIENT',
214
+ useValue: sqliteDb,
215
+ });
216
+ {{/if}}
217
+
218
+ providers.push({
219
+ provide: 'SQL_ADAPTER',
220
+ useClass: RawSqlAdapter,
221
+ });
222
+ {{/if}}
223
+
224
+ {{#if hasMongodb}}
225
+ const mongoClient = new MongoClient(options.mongodbUrl || '');
226
+ const mongoDb = mongoClient.db();
227
+ providers.push({
228
+ provide: 'MONGODB_CLIENT',
229
+ useValue: mongoDb,
230
+ });
231
+ providers.push({
232
+ provide: 'MONGO_ADAPTER',
233
+ useClass: RawMongoAdapter,
234
+ });
235
+ {{/if}}
236
+ {{/if}}
237
+
238
+ return {
239
+ exports: [DbService],
240
+ module: DbModule,
241
+ providers,
242
+ };
243
+ }
244
+ }
@@ -0,0 +1,88 @@
1
+ import { Injectable, Inject } from '@nestjs/common';
2
+ {{#if (or hasPostgres hasMysql hasSqlite)}}
3
+ import type { ISqlAdapter } from './adapters/interfaces/db-adapter.interface.js';
4
+ {{/if}}
5
+ {{#if hasMongodb}}
6
+ import type { IMongoAdapter } from './adapters/interfaces/db-adapter.interface.js';
7
+ {{/if}}
8
+ {{#if usePrisma}}
9
+ import type { PrismaClient } from './orm/prisma/generated/client.js';
10
+ {{/if}}
11
+ {{#if useDrizzle}}
12
+ {{#if hasPostgres}}
13
+ import type { NodePgDatabase } from 'drizzle-orm/node-postgres';
14
+ {{/if}}
15
+ {{#if hasMysql}}
16
+ import type { MySql2Database } from 'drizzle-orm/mysql2';
17
+ {{/if}}
18
+ {{#if hasSqlite}}
19
+ import type { BetterSqlite3Database } from 'drizzle-orm/better-sqlite3';
20
+ {{/if}}
21
+ import type * as schema from './orm/drizzle/schema.js';
22
+ {{/if}}
23
+ {{#if useTypeorm}}
24
+ import type { DataSource } from 'typeorm';
25
+ {{/if}}
26
+ {{#if (or hasPostgres hasMysql hasSqlite)}}
27
+ {{#if usePrisma}}
28
+ type SqlClient = PrismaClient;
29
+ {{else if useTypeorm}}
30
+ type SqlClient = DataSource;
31
+ {{else if useDrizzle}}
32
+ type DrizzleClient = {{#if hasPostgres}}NodePgDatabase{{/if}}{{#if hasMysql}}MySql2Database{{/if}}{{#if hasSqlite}}BetterSqlite3Database{{/if}}<typeof schema>;
33
+ type SqlClient = DrizzleClient;
34
+ {{else}}
35
+ type SqlClient = unknown;
36
+ {{/if}}
37
+ {{/if}}
38
+ {{#if hasMongodb}}
39
+ {{#if usePrisma}}
40
+ type MongoClient = PrismaClient;
41
+ {{else}}
42
+ type MongoClient = unknown;
43
+ {{/if}}
44
+ {{/if}}
45
+
46
+ @Injectable()
47
+ export class DbService {
48
+ constructor(
49
+ {{#if (or hasPostgres hasMysql hasSqlite)}}
50
+ @Inject('SQL_ADAPTER') public readonly sql: ISqlAdapter<SqlClient>{{#if hasMongodb}},{{/if}}
51
+ {{/if}}
52
+ {{#if hasMongodb}}
53
+ @Inject('MONGO_ADAPTER') public readonly mongo: IMongoAdapter<MongoClient>
54
+ {{/if}}
55
+ ) {}
56
+
57
+ get raw() {
58
+ return {
59
+ {{#if (or hasPostgres hasMysql hasSqlite)}}
60
+ sql: this.sql.getClient(),
61
+ {{/if}}
62
+ {{#if hasMongodb}}
63
+ mongo: this.mongo.getClient(),
64
+ {{/if}}
65
+ };
66
+ }
67
+ {{#if usePrisma}}
68
+ {{#if (or hasPostgres hasMysql hasSqlite)}}
69
+ get prisma(): PrismaClient {
70
+ return this.sql.getClient();
71
+ }
72
+ {{/if}}
73
+ {{/if}}
74
+ {{#if useDrizzle}}
75
+ {{#if (or hasPostgres hasMysql hasSqlite)}}
76
+ get drizzle(): DrizzleClient {
77
+ return this.sql.getClient();
78
+ }
79
+ {{/if}}
80
+ {{/if}}
81
+ {{#if useTypeorm}}
82
+ {{#if (or hasPostgres hasMysql hasSqlite)}}
83
+ get typeorm(): DataSource {
84
+ return this.sql.getClient();
85
+ }
86
+ {{/if}}
87
+ {{/if}}
88
+ }
@@ -0,0 +1,32 @@
1
+ // ═════════════════════════════════════════════════════════════════════
2
+ // Example TypeORM entity — Todo
3
+ // ═════════════════════════════════════════════════════════════════════
4
+
5
+ import {
6
+ Column,
7
+ CreateDateColumn,
8
+ Entity,
9
+ PrimaryGeneratedColumn,
10
+ UpdateDateColumn,
11
+ } from "typeorm";
12
+
13
+ @Entity("todos")
14
+ export class Todo {
15
+ @PrimaryGeneratedColumn("uuid")
16
+ id: string;
17
+
18
+ @Column({ length: 255 })
19
+ description: string;
20
+
21
+ @Column({ length: 100, nullable: true })
22
+ name: string;
23
+
24
+ @Column({ default: false, name: "is_completed", type: "boolean" })
25
+ isCompleted: boolean;
26
+
27
+ @CreateDateColumn({ name: "created_at", type: "timestamptz" })
28
+ createdAt: Date;
29
+
30
+ @UpdateDateColumn({ name: "updated_at", type: "timestamptz" })
31
+ updatedAt: Date;
32
+ }
@@ -0,0 +1,10 @@
1
+ // oxlint-disable oxc/no-barrel-file
2
+ export * from './db.module.js';
3
+ export * from './db.service.js';
4
+ export * from './adapters/interfaces/db-adapter.interface.js';
5
+ {{#if useDrizzle}}
6
+ export * from './orm/drizzle/schema.js';
7
+ {{/if}}
8
+ {{#if useTypeorm}}
9
+ export * from './orm/typeorm/data-source.js';
10
+ {{/if}}