Closed dschlarmann closed 1 year ago
we can use the integrated possibilites of our ORM-framework typeORM or sequelizer to realize multiple database connections, multiple connection pool, timeouts and other common connection parameters. Nest databases
Mutliple databases can ne set like this:
const defaultOptions = {
type: 'postgres',
port: 5432,
username: 'user',
password: 'password',
database: 'db',
synchronize: true,
};
@Module({
imports: [
TypeOrmModule.forRoot({
...defaultOptions,
host: 'user_db_host',
entities: [User],
}),
TypeOrmModule.forRoot({
...defaultOptions,
name: 'albumsConnection',
host: 'album_db_host',
entities: [Album],
}),
],
})
and can be integrated in a service via Injectables:
@Injectable()
export class AlbumsService {
constructor(
@InjectDataSource('albumsConnection')
private dataSource: DataSource,
@InjectEntityManager('albumsConnection')
private entityManager: EntityManager,
) {}
}
Short: In order to provide an flexible approach for answering geo-related queries, the backend should be able to integrate and request different database-instances at the same time.
Details: Quering multiple database at the same time make the backend more flexible. There might be the use case, that the service-instance provider hosts the service-instance for multiple customers, where each customer organises the the data in a separate database. Those databases could have a different databasesystem, datamodels and could be hosted in another datacenter or even cloud service.
ToDo:
Some (random) reading: