Skip to content

Commit cf7e53f

Browse files
committed
feat(database): support MongoDB
1 parent 065231e commit cf7e53f

File tree

125 files changed

+2583
-662
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+2583
-662
lines changed

.github/workflows/docker-e2e.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ jobs:
1212

1313
steps:
1414
- uses: actions/checkout@v4
15-
- name: Run e2e tests
16-
run: docker compose -f docker-compose.ci.yaml --env-file env-example -p ci up --build --exit-code-from api
15+
- name: Run e2e tests for NestJS with TypeORM
16+
run: docker compose -f docker-compose.relational.ci.yaml --env-file env-example-relational -p ci-relational up --build --exit-code-from api
17+
- name: Run e2e tests for NestJS with Mongoose
18+
run: docker compose -f docker-compose.document.ci.yaml --env-file env-example-document -p ci-document up --build --exit-code-from api
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
to: src/database/seeds/document/<%= h.inflection.transform(name, ['underscore', 'dasherize']) %>/<%= h.inflection.transform(name, ['underscore', 'dasherize']) %>-seed.module.ts
3+
---
4+
import { Module } from '@nestjs/common';
5+
import { MongooseModule } from '@nestjs/mongoose';
6+
import { <%= name %>Schema, <%= name %>SchemaClass } from 'src/<%= h.inflection.transform(name, ['pluralize', 'underscore', 'dasherize']) %>/infrastructure/persistence/document/entities/<%= h.inflection.transform(name, ['underscore', 'dasherize']) %>.schema';
7+
import { <%= name %>SeedService } from './<%= h.inflection.transform(name, ['underscore', 'dasherize']) %>-seed.service';
8+
9+
@Module({
10+
imports: [
11+
MongooseModule.forFeature([
12+
{
13+
name: <%= name %>SchemaClass.name,
14+
schema: <%= name %>Schema,
15+
},
16+
]),
17+
],
18+
providers: [<%= name %>SeedService],
19+
exports: [<%= name %>SeedService],
20+
})
21+
export class <%= name %>SeedModule {}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
inject: true
3-
to: src/database/seeds/run-seed.ts
3+
to: src/database/seeds/document/run-seed.ts
44
after: \@nestjs\/core
55
---
66
import { <%= name %>SeedService } from './<%= h.inflection.transform(name, ['underscore', 'dasherize']) %>/<%= h.inflection.transform(name, ['underscore', 'dasherize']) %>-seed.service';
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
inject: true
3-
to: src/database/seeds/run-seed.ts
3+
to: src/database/seeds/document/run-seed.ts
44
before: close
55
---
66
await app.get(<%= name %>SeedService).run();
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
inject: true
3-
to: src/database/seeds/seed.module.ts
3+
to: src/database/seeds/document/seed.module.ts
44
before: \@Module
55
---
66
import { <%= name %>SeedModule } from './<%= h.inflection.transform(name, ['underscore', 'dasherize']) %>/<%= h.inflection.transform(name, ['underscore', 'dasherize']) %>-seed.module';
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
inject: true
3-
to: src/database/seeds/seed.module.ts
3+
to: src/database/seeds/document/seed.module.ts
44
after: imports
55
---
66
<%= name %>SeedModule,
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
to: src/database/seeds/document/<%= h.inflection.transform(name, ['underscore', 'dasherize']) %>/<%= h.inflection.transform(name, ['underscore', 'dasherize']) %>-seed.service.ts
3+
---
4+
import { Injectable } from '@nestjs/common';
5+
import { InjectModel } from '@nestjs/mongoose';
6+
import { Model } from 'mongoose';
7+
import { <%= name %>SchemaClass } from 'src/<%= h.inflection.transform(name, ['pluralize', 'underscore', 'dasherize']) %>/infrastructure/persistence/document/entities/<%= h.inflection.transform(name, ['underscore', 'dasherize']) %>.schema';
8+
9+
@Injectable()
10+
export class <%= name %>SeedService {
11+
constructor(
12+
@InjectModel(<%= name %>SchemaClass.name)
13+
private readonly model: Model<<%= name %>SchemaClass>,
14+
) {}
15+
16+
async run() {
17+
const count = await this.model.countDocuments();
18+
19+
if (count === 0) {
20+
const data = new this.model({});
21+
await data.save();
22+
}
23+
}
24+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
to: src/database/seeds/relational/<%= h.inflection.transform(name, ['underscore', 'dasherize']) %>/<%= h.inflection.transform(name, ['underscore', 'dasherize']) %>-seed.module.ts
3+
---
4+
import { Module } from '@nestjs/common';
5+
import { TypeOrmModule } from '@nestjs/typeorm';
6+
import { <%= name %>Entity } from 'src/<%= h.inflection.transform(name, ['pluralize', 'underscore', 'dasherize']) %>/infrastructure/persistence/relational/entities/<%= h.inflection.transform(name, ['underscore', 'dasherize']) %>.entity';
7+
import { <%= name %>SeedService } from './<%= h.inflection.transform(name, ['underscore', 'dasherize']) %>-seed.service';
8+
9+
@Module({
10+
imports: [TypeOrmModule.forFeature([<%= name %>Entity])],
11+
providers: [<%= name %>SeedService],
12+
exports: [<%= name %>SeedService],
13+
})
14+
export class <%= name %>SeedModule {}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
inject: true
3+
to: src/database/seeds/relational/run-seed.ts
4+
after: \@nestjs\/core
5+
---
6+
import { <%= name %>SeedService } from './<%= h.inflection.transform(name, ['underscore', 'dasherize']) %>/<%= h.inflection.transform(name, ['underscore', 'dasherize']) %>-seed.service';
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
inject: true
3+
to: src/database/seeds/relational/run-seed.ts
4+
before: close
5+
---
6+
await app.get(<%= name %>SeedService).run();

0 commit comments

Comments
 (0)