Skip to content

[Backend] Evaluierung - Integration von mehreren Datenbanken #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dschlarmann opened this issue Oct 17, 2023 · 1 comment
Closed
Assignees

Comments

@dschlarmann
Copy link
Contributor

dschlarmann commented Oct 17, 2023

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:

  • Please evaluate the the integration of multiple database(systems). This includes:
    • Connection-Parametes. Is it possible to define ConnectionPools separately?
  • Please note some information how a configuration could be set up.
    • This is needed because a unique identifier between "topic" and database table is needed.
      • ❗ The databasetable name itself is not unique

Some (random) reading:

@dschlarmann dschlarmann changed the title [Backend] Allow integration of different databases at the same time [Backend] Evaluierung - Integration von mehreren Datenbanken Oct 24, 2023
@artmarks
Copy link
Collaborator

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,
  ) {}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants