This repository has been archived by the owner on Jul 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a992270
Showing
7 changed files
with
2,537 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist/ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
```shell | ||
docker-compose up -d | ||
yarn install | ||
yarn build | ||
yarn run:ts-node | ||
yarn run:built | ||
docker-compose stop | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version: "3.7" | ||
services: | ||
db-mongo: | ||
image: "public.ecr.aws/docker/library/mongo:3" | ||
healthcheck: | ||
test: ["CMD-SHELL", 'mongo --eval ''db.runCommand("ping").ok'' localhost:27017/test --quiet'] | ||
interval: 10s | ||
timeout: 2s | ||
retries: 10 | ||
ports: | ||
- "27017:27017" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "mikro-orm-nestjs-issue-128", | ||
"version": "1.0.0", | ||
"repository": "[email protected]:AndKiel/mikro-orm-nestjs-issue-128.git", | ||
"license": "MIT", | ||
"scripts": { | ||
"compile": "tsc", | ||
"build": "ncc build --out dist --source-map ./reproduction.ts", | ||
"run:ts-node": "yarn ts-node ./reproduction.ts", | ||
"run:built": "node ./dist/index.js" | ||
}, | ||
"resolutions": { | ||
"mongodb": "4.1.4" | ||
}, | ||
"dependencies": { | ||
"@mikro-orm/core": "5.7.13", | ||
"@mikro-orm/mongodb": "5.7.13", | ||
"@mikro-orm/nestjs": "5.2.0", | ||
"@nestjs/common": "10.1.0", | ||
"@nestjs/config": "3.0.0", | ||
"@nestjs/core": "10.1.0", | ||
"nestjs-pino": "3.3.0", | ||
"pino-http": "8.3.3", | ||
"reflect-metadata": "0.1.13", | ||
"source-map-support": "0.5.21", | ||
"tslib": "2.6.0" | ||
}, | ||
"devDependencies": { | ||
"@nestjs/cli": "10.1.4", | ||
"@nestjs/schematics": "10.0.1", | ||
"@nestjs/testing": "10.0.5", | ||
"@types/node": "18.16.19", | ||
"@vercel/ncc": "0.36.1", | ||
"ts-node": "10.9.1", | ||
"typescript": "5.1.6" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import "reflect-metadata"; | ||
|
||
import { BaseEntity, Entity, PrimaryKey, SerializedPrimaryKey } from "@mikro-orm/core"; | ||
import { EntityManager, ObjectId } from "@mikro-orm/mongodb"; | ||
import { MikroOrmModule } from "@mikro-orm/nestjs"; | ||
import { INestApplicationContext, Injectable, Module, Scope } from "@nestjs/common"; | ||
import { NestFactory } from "@nestjs/core"; | ||
import { LoggerModule, PinoLogger } from "nestjs-pino"; | ||
|
||
@Entity({ collection: "entities" }) | ||
export class MongoEntity extends BaseEntity<MongoEntity, "id"> { | ||
@PrimaryKey() | ||
public _id!: ObjectId; | ||
|
||
@SerializedPrimaryKey() | ||
public id!: string; | ||
} | ||
|
||
|
||
@Injectable({ scope: Scope.TRANSIENT }) | ||
export class MongoService { | ||
private entityManager: EntityManager; | ||
|
||
constructor(entityManager: EntityManager) { | ||
this.entityManager = entityManager.fork(); | ||
} | ||
} | ||
|
||
@Module({ providers: [MongoService] }) | ||
export class MongoModule {} | ||
|
||
@Module({ | ||
imports: [ | ||
LoggerModule.forRoot(), | ||
MikroOrmModule.forRootAsync({ | ||
inject: [PinoLogger], | ||
useFactory: (logger: PinoLogger) => { | ||
logger.setContext("MikroOrm"); | ||
|
||
return { | ||
type: "mongo", | ||
clientUrl: "mongodb://127.0.0.1:27017/dbName", // run a local dockerized MongoDB v3 instance | ||
dbName: "dbName", | ||
entities: [MongoEntity], | ||
debug: ["query"], // Log all queries | ||
logger: message => logger.info(message), | ||
}; | ||
}, | ||
}), | ||
MongoModule, | ||
], | ||
}) | ||
class AppModule {} | ||
|
||
let applicationContext: INestApplicationContext; | ||
|
||
if (require.main === module) { | ||
(async () => { | ||
applicationContext = await NestFactory.createApplicationContext(AppModule); | ||
applicationContext = await applicationContext.init(); | ||
await applicationContext.resolve(MongoService); | ||
await applicationContext.close(); | ||
process.exit(0) | ||
})().catch(async error => { | ||
await applicationContext?.close(); | ||
throw error; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2021", | ||
"lib": ["es2021"], | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true, | ||
"module": "commonjs", | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true | ||
} | ||
} |
Oops, something went wrong.