import type { EntityManagerType, IDatabaseDriver } from './drivers/IDatabaseDriver.js'; import { type EntitySchema } from './metadata/EntitySchema.js'; import { MetadataStorage } from './metadata/MetadataStorage.js'; import { Configuration, type Options } from './utils/Configuration.js'; import type { EntityManager } from './EntityManager.js'; import type { AnyEntity, Constructor, EntityClass, EntityMetadata, EntityName, IEntityGenerator, IMigrator, ISeedManager, } from './typings.js'; /** @internal */ export declare function loadOptionalDependencies(options: Partial): Promise; /** * The main class used to configure and bootstrap the ORM. * * @example * ```ts * // import from driver package * import { MikroORM, defineEntity, p } from '@mikro-orm/sqlite'; * * const User = defineEntity({ * name: 'User', * properties: { * id: p.integer().primary(), * name: p.string(), * }, * }); * * const orm = new MikroORM({ * entities: [User], * dbName: 'my.db', * }); * await orm.schema.update(); * * const em = orm.em.fork(); * const u1 = em.create(User, { name: 'John' }); * const u2 = em.create(User, { name: 'Ben' }); * await em.flush(); * ``` */ export declare class MikroORM< Driver extends IDatabaseDriver = IDatabaseDriver, EM extends Driver[typeof EntityManagerType] & EntityManager = Driver[typeof EntityManagerType] & EntityManager, Entities extends (string | EntityClass | EntitySchema)[] = ( | string | EntityClass | EntitySchema )[], > { #private; /** The global EntityManager instance. If you are using `RequestContext` helper, it will automatically pick the request specific context under the hood */ em: EM & { '~entities'?: Entities; }; /** The database driver instance used by this ORM. */ readonly driver: Driver; /** The ORM configuration instance. */ readonly config: Configuration; /** * Initialize the ORM, load entity metadata, create EntityManager and connect to the database. * If you omit the `options` parameter, your CLI config will be used. */ static init< D extends IDatabaseDriver = IDatabaseDriver, EM extends D[typeof EntityManagerType] & EntityManager = D[typeof EntityManagerType] & EntityManager, Entities extends (string | EntityClass | EntitySchema)[] = ( | string | EntityClass | EntitySchema )[], >(options: Partial>): Promise>; /** * Synchronous variant of the `init` method with some limitations: * - folder-based discovery not supported * - ORM extensions are not autoloaded * - when metadata cache is enabled, `FileCacheAdapter` needs to be explicitly set in the config */ constructor(options: Partial>); /** * Connects to the database. */ connect(): Promise; /** * Reconnects, possibly to a different database. */ reconnect(options?: Partial>): Promise; /** * Checks whether the database connection is active. */ isConnected(): Promise; /** * Checks whether the database connection is active, returns the reason if not. */ checkConnection(): Promise< | { ok: true; } | { ok: false; reason: string; error?: Error; } >; /** * Closes the database connection. */ close(force?: boolean): Promise; /** * Gets the `MetadataStorage`. */ getMetadata(): MetadataStorage; /** * Gets the `EntityMetadata` instance when provided with the `entityName` parameter. */ getMetadata(entityName: EntityName): EntityMetadata; private createEntityManager; /** * Allows dynamically discovering new entity by reference, handy for testing schema diffing. */ discoverEntity(entities: T | T[], reset?: EntityName | EntityName[]): void; /** * Gets the SchemaGenerator. */ get schema(): ReturnType['getSchemaGenerator']>; /** * Gets the SeedManager */ get seeder(): ISeedManager; /** * Gets the Migrator. */ get migrator(): IMigrator; /** * Gets the EntityGenerator. */ get entityGenerator(): IEntityGenerator; }