@backstage/backend-defaults
Version:
Backend defaults used by Backstage backend apps
61 lines (57 loc) • 2.22 kB
TypeScript
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
import { RootConfigService, DatabaseService, RootLoggerService, RootLifecycleService, LoggerService, LifecycleService } from '@backstage/backend-plugin-api';
/**
* Database access and management via `knex`.
*
* See {@link @backstage/code-plugin-api#DatabaseService}
* and {@link https://backstage.io/docs/backend-system/core-services/database | the service docs}
* for more information.
*
* @public
*/
declare const databaseServiceFactory: _backstage_backend_plugin_api.ServiceFactory<_backstage_backend_plugin_api.DatabaseService, "plugin", "singleton">;
/**
* Creation options for {@link DatabaseManager}.
*
* @public
*/
type DatabaseManagerOptions = {
migrations?: DatabaseService['migrations'];
rootLogger?: RootLoggerService;
rootLifecycle?: RootLifecycleService;
};
/**
* Manages database connections for Backstage backend plugins.
*
* @public
* @remarks
*
* The database manager allows the user to set connection and client settings on
* a per pluginId basis by defining a database config block under
* `plugin.<pluginId>` in addition to top level defaults. Optionally, a user may
* set `prefix` which is used to prefix generated database names if config is
* not provided.
*/
declare class DatabaseManager {
private readonly impl;
/**
* Creates a {@link DatabaseManager} from `backend.database` config.
*
* @param config - The loaded application configuration.
* @param options - An optional configuration object.
*/
static fromConfig(config: RootConfigService, options?: DatabaseManagerOptions): DatabaseManager;
private constructor();
/**
* Generates a DatabaseService for consumption by plugins.
*
* @param pluginId - The plugin that the database manager should be created for. Plugin names
* should be unique as they are used to look up database config overrides under
* `backend.database.plugin`.
*/
forPlugin(pluginId: string, deps: {
logger: LoggerService;
lifecycle: LifecycleService;
}): DatabaseService;
}
export { DatabaseManager, type DatabaseManagerOptions, databaseServiceFactory };