UNPKG

nestjs-typeorm-transactions

Version:

A NestJS module to make transaction management easier across different services

73 lines (72 loc) 4.39 kB
import { DataSource, DeepPartial, EntityManager, EntitySchema, FindManyOptions, FindOneOptions, FindOptionsWhere, ObjectId, ObjectLiteral, QueryRunner, Repository, SaveOptions } from 'typeorm'; import { IPagination } from './types/pagination'; import { PickKeysByType } from 'typeorm/common/PickKeysByType'; import { UpsertOptions } from 'typeorm/repository/UpsertOptions'; type IdType = number | string | ObjectId | Date | number[] | string[] | ObjectId[] | Date[]; export declare class TransactionalRepository<T extends ObjectLiteral> { private dataSource; private EntityClass; private connection; constructor(dataSource: DataSource, EntityClass: Function | EntitySchema<any>, connection?: string); /** Execute a raw query */ static executeRawQuery<Raw = any>(options: { /** Query to execute */ query: string; /** Parameters of the query */ parameters?: any[]; /** Name of the connection */ connection?: string; }): Promise<Raw>; /** Retrieve the transactional entity manager optionally specifying a connection name. If no connection name is specified, the default connection's entity manager is returned */ static getEntityManager(connection?: string): EntityManager; /** Get native typeorm repository */ getTypeOrmRepository(): Repository<T>; /** Create query builder */ createQueryBuilder(alias?: string, queryRunner?: QueryRunner): import("typeorm").SelectQueryBuilder<T>; /** Return multiple records */ find(options?: FindManyOptions<T>): Promise<T[]>; /** Return multiple records */ findBy(where: FindOptionsWhere<T> | FindOptionsWhere<T>[]): Promise<T[]>; /** Return multiple records with pagination */ findWithPagination(limit: number, page: number, options?: FindManyOptions<T>): Promise<IPagination<T>>; /** Find one record */ findOne(options: FindOneOptions<T>): Promise<T>; /** Find one record */ findOneBy(where: FindOptionsWhere<T> | FindOptionsWhere<T>[]): Promise<T>; /** Preload an entity using typeorm preload method */ preload(entity: DeepPartial<T>): Promise<T>; /** Insert record(s). Unlike save, it attempts to insert without checking if entity exists and ingores cascades */ insert(entity: DeepPartial<T>): Promise<T>; insert(entity: DeepPartial<T>[]): Promise<T[]>; /** Creates entity/entities without saving them in DB */ create(entity: DeepPartial<T>): T; create(entity: DeepPartial<T>[]): T[]; /** Calls TypeOrm save() method */ save(entity: DeepPartial<T>[], saveOptions?: SaveOptions): Promise<T[]>; save(entity: DeepPartial<T>, saveOptions?: SaveOptions): Promise<T>; /** Updates given entity/entities */ update(id: IdType | FindOptionsWhere<T>, entity: DeepPartial<T>): Promise<void>; /** Upserts record(s) */ upsert(entity: DeepPartial<T> | DeepPartial<T>[], conflictPaths: string[] | UpsertOptions<T>): Promise<void>; /** Deletes record(s) */ delete(id: IdType | FindOptionsWhere<T>): Promise<void>; /** Disassociate all child entities in many to many relationships */ disassociateAll(entityId: IdType, relation: keyof T): Promise<void>; /** Disassociate child entities by ids in many to many relationships */ disassociate(entityId: IdType, relatedEntityId: IdType, relation: keyof T): Promise<void>; /** Associate child entities by ids in many to many relationships */ associate(entityId: IdType, relatedEntityId: IdType, relation: keyof T): Promise<void>; /** Count entities */ count(options?: FindManyOptions<T>): Promise<number>; /** Get the average of a culumn */ average(columnName: PickKeysByType<T, number>, where?: FindOptionsWhere<T> | FindOptionsWhere<T>[]): Promise<number>; /** Get the sum of a column */ sum(columnName: PickKeysByType<T, number>, where?: FindOptionsWhere<T> | FindOptionsWhere<T>[]): Promise<number>; /** Get the max value of a column */ max(columnName: PickKeysByType<T, number>, where?: FindOptionsWhere<T> | FindOptionsWhere<T>[]): Promise<number>; /** Get the min value of a column */ min(columnName: PickKeysByType<T, number>, where?: FindOptionsWhere<T> | FindOptionsWhere<T>[]): Promise<number>; /** Merge multiple entity like objects into a single entity */ merge(mergeIntoEntity: T, ...entityLikes: DeepPartial<T>[]): T; } export {};