Variable: buildDatabaseOptions
constbuildDatabaseOptions: (options) =>object
Build the registration of a Database provider, for the providers of the application options: the provider class with its TypeORM connection options. Its entities option, added to the entities of the connection options, is set by spreading the registration: {...buildDatabaseOptions(options), entities: [User]}.
Parameters
options
DataSourceOptions
The TypeORM connection options (DataSourceOptions): the driver type, the connection settings, the entities, the migrations, synchronize, migrationsRun, logging… Passed to TypeORM, with the null and undefined values of the where conditions ignored unless they set invalidWhereValuesBehavior (see Database).
Returns
object
The registration {class: Database, options}.
class
class: typeof
Database
options
options:
DataSourceOptions
Example
import {Application} from 'lakutata'
import {buildDatabaseOptions} from 'lakutata/provider/database'
import {Column, Entity, PrimaryGeneratedColumn} from 'lakutata/decorator/orm'
@Entity()
class Report {
@PrimaryGeneratedColumn()
public id: number
@Column('text')
public content: string
}
Application.run(() => ({
id: 'com.example.reports',
name: 'Reports',
providers: {
//A new PostgreSQL connection each time reports is resolved, closed with its owner
reports: {
...buildDatabaseOptions({type: 'postgres', url: 'postgres://postgres:secret@localhost:5432/reports'}),
entities: [Report]
}
}
}))