Skip to content

Variable: buildDatabaseOptions ​

const buildDatabaseOptions: (options) => object

Build the registration of a Database component, for the components of the application options: the component class with its TypeORM connection options.

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 ​

typescript
import {Application} from 'lakutata'
import {buildDatabaseOptions} from 'lakutata/com/database'
import {Column, Entity, PrimaryGeneratedColumn} from 'lakutata/decorator/orm'

@Entity()
class User {
    @PrimaryGeneratedColumn()
    public id: number

    @Column()
    public name: string
}

Application.run(() => ({
    id: 'com.example.app',
    name: 'Example',
    components: {
        //A PostgreSQL connection (the pg package installed), the component named db
        db: buildDatabaseOptions({
            type: 'postgres',
            host: 'localhost',
            port: 5432,
            username: 'postgres',
            password: 'secret',
            database: 'example',
            entities: [User]
        })
    },
    //Connected while the application launches: a connection failure stops it
    bootstrap: ['db']
}))

Released under the MIT License.