From 458380eaea90e22f75dfdb5d1a24cc85533c1ecb Mon Sep 17 00:00:00 2001 From: davyli Date: Sun, 22 Dec 2024 12:46:45 -0800 Subject: [PATCH] Add option to retrieve typeorm database datasource --- typeorm/typeorm-store/src/database.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/typeorm/typeorm-store/src/database.ts b/typeorm/typeorm-store/src/database.ts index 9cfe5ff82..a426d77df 100644 --- a/typeorm/typeorm-store/src/database.ts +++ b/typeorm/typeorm-store/src/database.ts @@ -15,6 +15,7 @@ export interface TypeormDatabaseOptions { isolationLevel?: IsolationLevel stateSchema?: string projectDir?: string + accessibleDatasource?: boolean } @@ -23,6 +24,7 @@ export class TypeormDatabase { private isolationLevel: IsolationLevel private con?: DataSource private projectDir: string + private accessibleDatasource: boolean public readonly supportsHotBlocks: boolean @@ -31,6 +33,14 @@ export class TypeormDatabase { this.isolationLevel = options?.isolationLevel || 'SERIALIZABLE' this.supportsHotBlocks = options?.supportHotBlocks !== false this.projectDir = options?.projectDir || process.cwd() + this.accessibleDatasource = options?.accessibleDatasource || false + } + + getDataSource(): DataSource | undefined { + if (!this.accessibleDatasource) { + throw new Error('Datasource is inaccessible') + } + return this.con } async connect(): Promise {