Skip to content
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

feat: support custom data source #4262

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/core/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,9 @@ export type DataSourceManagerConfigOption<OPTIONS, ENTITY_CONFIG_KEY extends str
dataSource?: {
[key: string]: PowerPartial<{
[keyName in ENTITY_CONFIG_KEY]: any[];
}> & OPTIONS;
}> & OPTIONS & {
customDataSourceClass?: any;
};
};
} & CreateDataSourceInstanceOptions;

Expand Down
11 changes: 10 additions & 1 deletion packages/typeorm/src/dataSourceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,16 @@ export class TypeORMDataSourceManager extends DataSourceManager<DataSource> {
this.loggerService.getLogger('typeormLogger')
);
}
const dataSource = new DataSource(config);

const { customDataSourceClass, ...otherConfig } = config;

let dataSource: DataSource;
if (customDataSourceClass) {
dataSource = new customDataSourceClass(otherConfig);
} else {
dataSource = new DataSource(otherConfig);
}

await dataSource.initialize();
return dataSource;
}
Expand Down
Loading