()
| 74 | } |
| 75 | |
| 76 | createClient(): void { |
| 77 | let driverOptions = this.options.driverOptions ?? this.config.get('driverOptions'); |
| 78 | |
| 79 | if (typeof driverOptions === 'function') { |
| 80 | driverOptions = driverOptions(); |
| 81 | } |
| 82 | |
| 83 | if (driverOptions instanceof MongoClient) { |
| 84 | this.logger.log('info', 'Reusing MongoClient provided via `driverOptions`'); |
| 85 | this.#client = driverOptions; |
| 86 | } else { |
| 87 | this.#client = new MongoClient( |
| 88 | this.config.get('clientUrl'), |
| 89 | this.mapOptions(driverOptions as MongoClientOptions), |
| 90 | ); |
| 91 | this.#client.appendMetadata({ |
| 92 | name: 'MikroORM', |
| 93 | version: Utils.getORMVersion(), |
| 94 | }); |
| 95 | const onCreateConnection = this.options.onCreateConnection ?? this.config.get('onCreateConnection'); |
| 96 | /* v8 ignore next */ |
| 97 | this.#client.on('connectionCreated', () => { |
| 98 | void onCreateConnection?.(this.#client); |
| 99 | }); |
| 100 | } |
| 101 | |
| 102 | this.#db = this.#client.db(this.config.get('dbName')); |
| 103 | } |
| 104 | |
| 105 | override async close(force?: boolean): Promise<void> { |
| 106 | await this.#client?.close(force); |
no test coverage detected