UNPKG

@techmmunity/symbiosis

Version:

Symbiosis - The Ultimate OM For All Databases

65 lines (64 loc) 2.09 kB
import { EntityManager } from "../entity-manager"; import { Logger } from "../logger"; import type { BaseRepository } from "../repository"; import type { CustomClass } from "../entity-manager/types/metadata-type"; import type { BaseExtraMetadata } from "../types/extra-metadata"; import type { BaseConnectionOptions } from "./types/connection-options"; export declare abstract class BaseConnection<DatabaseConfig = any, ExtraMetadata extends BaseExtraMetadata = any> { /** * Properties */ options: Omit<BaseConnectionOptions<DatabaseConfig>, "entities" | "entitiesDir">; private readonly internalOptions; name: string; entities: Array<any>; entityManager: EntityManager<ExtraMetadata>; logger: Logger; /** * The connection needs to load the entities before do anything, * so this prop exists to plugins creators verify if the user * has not called the `.load()` and throw an error. */ protected isLoaded: boolean; /** * Constructor */ constructor(pluginName: string, options?: BaseConnectionOptions<DatabaseConfig>); /** * Load the entities and connection config */ load(): Promise<this>; /** * Makes some basic validation in the connection data */ protected basicValidate(): void; /** * Abstract Methods */ /** * Validate the connection data. Throw an error * if something is wrong. * * Very useful to check if your schemas match with * the database requirements. * * We recommend that you only call this method in * development, so your system starts faster in * production */ abstract validate(): Promise<void>; /** * Connect with the database */ abstract connect(): Promise<this>; /** * Close the connection with the database */ abstract close(): Promise<void>; /** * Makes a repository * * @param entity Entity of the repository */ abstract getRepository<Entity>(entity: CustomClass): BaseRepository<Entity, ExtraMetadata>; }