UNPKG

@nodeboot/starter-persistence

Version:

Nodeboot starter package for persistence. Supports data access layer auto-configuration providing features like database initialization, consistency check, entity mapping, repository pattern, transactions, paging, migrations, persistence listeners, persis

77 lines 2.96 kB
import { MongoEntityManager, ObjectLiteral, Repository } from "typeorm"; import { MongoQueryRunner } from "typeorm/driver/mongodb/MongoQueryRunner"; /** * Retrieves the underlying `MongoClient` instance from a TypeORM `MongoRepository`. * * @param repoInstance - An instance of a MongoRepository. * @returns The `MongoClient` instance used by the repository. * @throws Error if used on a non-Mongo repository or if the client is not available. * * @example * ```ts * import {useMongoClient} from "@nodeboot/starter-persistence"; * * const client = useMongoClient(this.mongoRepo); * const db = client.db("customDb"); * ``` * * @author Manuel Santos <https://github.com/manusant> */ export declare function useMongoClient(repoInstance: Repository<any>): import("typeorm").MongoClient; /** * Retrieves a MongoDB `Collection` from a TypeORM `MongoRepository`. * * @template C - Entity type of the collection. * @param repoInstance - An instance of a MongoRepository. * @param collectionName - Optional custom collection name; defaults to the repository’s metadata table name. * @returns The MongoDB collection instance. * @throws Error if used on a non-Mongo repository. * * @example * ```ts * import {useMongoCollection} from "@nodeboot/starter-persistence"; * * const usersCollection = useMongoCollection<User>(this.mongoRepo, "users"); * const user = await usersCollection.findOne({ email: "test@example.com" }); * ``` * * @author Manuel Santos <https://github.com/manusant> */ export declare function useMongoCollection<C extends ObjectLiteral>(repoInstance: Repository<any>, collectionName?: string): import("typeorm").Collection<C>; /** * Retrieves the `MongoEntityManager` from a TypeORM `MongoRepository`. * * @param repoInstance - An instance of a MongoRepository. * @returns The associated `MongoEntityManager`. * @throws Error if used on a non-Mongo repository. * * @example * ```ts * import {useMongoEntityManager} from "@nodeboot/starter-persistence"; * * const manager = useMongoEntityManager(this.mongoRepo); * await manager.find(User); * ``` * * @author Manuel Santos <https://github.com/manusant> */ export declare function useMongoEntityManager(repoInstance: Repository<any>): MongoEntityManager; /** * Retrieves the `MongoQueryRunner` from a TypeORM `MongoRepository`. * * @param repoInstance - An instance of a MongoRepository. * @returns The associated `MongoQueryRunner`. * @throws Error if used on a non-Mongo repository. * * @example * ```ts * import {useMongoQueryRunner} from "@nodeboot/starter-persistence"; * * const queryRunner = useMongoQueryRunner(this.mongoRepo); * await queryRunner.databaseConnection.db().collection("myCollection").insertOne({ key: "value" }); * ``` * * @author Manuel Santos <https://github.com/manusant> */ export declare function useMongoQueryRunner(repoInstance: Repository<any>): MongoQueryRunner; //# sourceMappingURL=mongo.hooks.d.ts.map