typeorm / typeorm

ORM for TypeScript and JavaScript. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.
http://typeorm.io
MIT License
33.99k stars 6.26k forks source link

Request: DataSource.getOptions(): DataSourceOptions method #10381

Open AaronNGray opened 11 months ago

AaronNGray commented 11 months ago

Feature Description

I require a DataSource.getOptions(): DataSourceOptions to access :-

https://github.com/typeorm/typeorm/blob/master/src/data-source/DataSource.ts#L69

And complement DataSource.setOptions(options: Partial<DataSourceOptions>): this

https://github.com/typeorm/typeorm/blob/master/src/data-source/DataSource.ts#L206

Something simular to :-

getOptions(): DataSourceOptions {
    return this.options;
}

The Solution

this allows access to the DataSource's options as in the following :-

    dataSource = new DataSource({
      type: 'sqlite',
      database: ':memory:',
      entities: ['sample/entities/**/*{.ts,.js}'],
      factories: ['sample/factories/**/*{.ts,.js}'],
    })

and later in usage

    const options = dataSource.getOptions();
    const factoryFiles = loadFiles(option.factories)

as passed through here :-

https://github.com/typeorm/typeorm/blob/master/src/data-source/DataSource.ts#L140C31-L140C31

Considered Alternatives

Individual options could be passed through but this is limiting and also is just slower and requires knowing what option attributes will be passed through in the future.

Additional Context

No response

Relevant Database Driver(s)

Are you willing to resolve this issue by submitting a Pull Request?

Yes, I have the time, and I know how to start.

AaronNGray commented 11 months ago

In order to add new fields for typeorm-seeding DataSourceOptions needs either to be made extensible with new random fields which would remove the name safety or to have the necessary extra fields for seeding added, or perhaps a cleverer mechanism ?