interface IKyselyRootModuleConfig {
    attachCommands?: string | boolean;
    database?: string;
    dialect?: string;
    host?: string;
    kyselyDialectFactory?: ((module, options, ctx) => Dialect | Promise<Dialect>);
    kyselyFactory?: ((module, options, ctx) => Kysely<any> | Promise<Kysely<any>>);
    kyselyLoggerFactory?: ((module, options, ctx) => LogConfig | Promise<LogConfig>);
    kyselyMigratorFactory?: ((module, options, ctx) => Migrator | Promise<Migrator>);
    logger?: kysely.Logger | ("query" | "error")[] | "silvertree" | "console";
    migrations?: {
        enabled?: boolean;
        params?: Omit<MigratorProps, "db" | "provider">;
        provider: ((container, module, kysely) => Record<string, Migration> | Promise<Record<string, Migration>>);
    };
    onConnect?: ((connection) => Promise<void>);
    password?: string;
    plugins?: KyselyPlugin[];
    port?: number;
    rejectUnauthorized?: boolean;
    scope?: string;
    url?: string;
    user?: string;
}

Properties

attachCommands?: string | boolean

Try to add the commands to @silvertree/cli to manage database. If false it will not attach any commands. If true it will try to attach the commands to the default cli scope. If a string it will try to attach the commands to the specified cli scope.

database?: string

The database name. Environment variable: DB_DATABASE or DB_${scope}_DATABASE

dialect?: string

The dialect of the database. Environment variable: DB_DIALECT or DB_${scope}_DIALECT

Default

'postgres'
host?: string

The host of the database. Environment variable: DB_HOST or DB_${scope}_HOST

kyselyDialectFactory?: ((module, options, ctx) => Dialect | Promise<Dialect>)

The factory function to create a Kysely dialect.

Type declaration

kyselyFactory?: ((module, options, ctx) => Kysely<any> | Promise<Kysely<any>>)

The factory function to create a Kysely instance. It will completely override the default Kysely creation mechanism.

Type declaration

kyselyLoggerFactory?: ((module, options, ctx) => LogConfig | Promise<LogConfig>)

The factory function to create a Kysely logger.

Type declaration

kyselyMigratorFactory?: ((module, options, ctx) => Migrator | Promise<Migrator>)

The factory function to create a Kysely migrator.

Type declaration

logger?: kysely.Logger | ("query" | "error")[] | "silvertree" | "console"

The logger to use for the database connection.

migrations?: {
    enabled?: boolean;
    params?: Omit<MigratorProps, "db" | "provider">;
    provider: ((container, module, kysely) => Record<string, Migration> | Promise<Record<string, Migration>>);
}

The migration configuration.

Type declaration

  • Optional enabled?: boolean

    Enable or disable the migration feature.

    Default

    true
    
  • Optional params?: Omit<MigratorProps, "db" | "provider">

    Parameters for the migrator.

  • provider: ((container, module, kysely) => Record<string, Migration> | Promise<Record<string, Migration>>)

    The migration provider.

onConnect?: ((connection) => Promise<void>)

Executed once for each created connection in pool.

Type declaration

password?: string

The password of the database. Environment variable: DB_PASSWORD or DB_${scope}_PASSWORD

plugins?: KyselyPlugin[]

The plugins to use for the Kysely instance.

port?: number

The port of the database. Environment variable: DB_PORT or DB_${scope}_PORT

rejectUnauthorized?: boolean

If false it will allow self-signed database certificates.

Default

true
scope?: string

The scope of the Kysely instance. You may have multiple instances of Kysely with different scopes.

url?: string

The connection URL to the database. Use this or host, port, user, password, database to connect to the database. Environment variable: DB_CONNECTION_URL or DB_${scope}_CONNECTION_URL

user?: string

The user of the database. Environment variable: DB_USER or DB_${scope}_USER