-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: use common db for askar and exchanges api
- replace better-sqlite3 with sqlite - rename in-memory-db.ts to db-config.ts - TypeOrmSQLiteModule to accept inMemory boolean param; helps in db initialization for app and unit tests Signed-off-by: ShikharBhatt <[email protected]>
- Loading branch information
1 parent
ecf0990
commit 6cf5a3c
Showing
10 changed files
with
421 additions
and
46 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
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
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
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
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,25 @@ | ||
/* | ||
* Copyright 2021 - 2023 Energy Web Foundation | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { ConfigModule, ConfigService } from '@nestjs/config'; | ||
|
||
/** | ||
* Inspired by https://dev.to/webeleon/unit-testing-nestjs-with-typeorm-in-memory-l6m | ||
* @param inMemory // default set to false; set to true for unit testing | ||
*/ | ||
export const TypeOrmSQLiteModule = (inMemory = false) => | ||
TypeOrmModule.forRootAsync({ | ||
imports: [ConfigModule], | ||
useFactory: async (configService: ConfigService) => ({ | ||
type: 'sqlite', | ||
database: !inMemory ? `${configService.get<string>('DB_BASE_PATH')}/exchanges.db` : ':memory:', | ||
// dropSchema: true, // disabling this option to avoid dropping askar tables | ||
autoLoadEntities: true, // https://docs.nestjs.com/techniques/database#auto-load-entities | ||
synchronize: true, | ||
keepConnectionAlive: true // https://github.com/nestjs/typeorm/issues/61 | ||
}), | ||
inject: [ConfigService] | ||
}); |
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
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
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.