nest-typeorm-sharding-repository
Version:
This module extends TypeORM capabilities to support distributed database environments with List and Range-based sharding strategies in a NestJS application.
102 lines (101 loc) • 5.73 kB
TypeScript
import { DataSource, DeepPartial, DeleteResult, EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere, ObjectID, RemoveOptions, Repository, SaveOptions, UpdateResult } from 'typeorm';
import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';
export declare class ShardingBaseEntity {
private base;
save(options?: SaveOptions): Promise<this>;
remove(options?: RemoveOptions): Promise<this>;
softRemove(options?: SaveOptions): Promise<this>;
recover(options?: SaveOptions): Promise<this>;
reload(): Promise<void>;
private static wrapArray;
static save<T extends ShardingBaseEntity>(this: {
new (): T;
} & typeof ShardingBaseEntity, entities: DeepPartial<T>[], options?: SaveOptions): Promise<T[]>;
static save<T extends ShardingBaseEntity>(this: {
new (): T;
} & typeof ShardingBaseEntity, entity: DeepPartial<T>, options?: SaveOptions): Promise<T>;
static create<T extends ShardingBaseEntity>(this: {
new (): T;
} & typeof ShardingBaseEntity, entityLikeArray: DeepPartial<T>[]): T[];
static create<T extends ShardingBaseEntity>(this: {
new (): T;
} & typeof ShardingBaseEntity, entityLike?: DeepPartial<T>): T;
static remove<T extends ShardingBaseEntity>(this: {
new (): T;
} & typeof ShardingBaseEntity, entities: T[], options?: RemoveOptions): Promise<T[]>;
static remove<T extends ShardingBaseEntity>(this: {
new (): T;
} & typeof ShardingBaseEntity, entity: T, options?: RemoveOptions): Promise<T>;
static softRemove<T extends ShardingBaseEntity>(this: {
new (): T;
} & typeof ShardingBaseEntity, entities: T[], options?: SaveOptions): Promise<T[]>;
static softRemove<T extends ShardingBaseEntity>(this: {
new (): T;
} & typeof ShardingBaseEntity, entity: T, options?: SaveOptions): Promise<T>;
static update<T extends ShardingBaseEntity>(this: {
new (): T;
} & typeof ShardingBaseEntity, criteria: string | string[] | number | number[] | Date | Date[] | ObjectID | ObjectID[] | FindOptionsWhere<T>, partialEntity: QueryDeepPartialEntity<T>, shardKey?: string): Promise<UpdateResult>;
static delete<T extends ShardingBaseEntity>(this: {
new (): T;
} & typeof ShardingBaseEntity, criteria: string | string[] | number | number[] | Date | Date[] | ObjectID | ObjectID[] | FindOptionsWhere<T>, shardKey?: string): Promise<DeleteResult>;
static count<T extends ShardingBaseEntity>(this: {
new (): T;
} & typeof ShardingBaseEntity, options?: FindManyOptions<T>, shardKey?: string): Promise<number>;
static countBy<T extends ShardingBaseEntity>(this: {
new (): T;
} & typeof ShardingBaseEntity, where: FindOptionsWhere<T>, shardKey?: string): Promise<number>;
static find<T extends ShardingBaseEntity>(this: {
new (): T;
} & typeof ShardingBaseEntity, options?: FindManyOptions<T>, shardKey?: string): Promise<T[]>;
static findBy<T extends ShardingBaseEntity>(this: {
new (): T;
} & typeof ShardingBaseEntity, where: FindOptionsWhere<T>, shardKey?: string): Promise<T[]>;
static findAndCount<T extends ShardingBaseEntity>(this: {
new (): T;
} & typeof ShardingBaseEntity, options?: FindManyOptions<T>, shardKey?: string): Promise<[T[], number]>;
static findAndCountBy<T extends ShardingBaseEntity>(this: {
new (): T;
} & typeof ShardingBaseEntity, where: FindOptionsWhere<T>, shardKey?: string): Promise<[T[], number]>;
/**
*
* @param this
* @param ids Entity Ids list
* @param shardingKey Optional parameter, its required when sharding type is LIST
* @returns
*/
static findByIds<T extends ShardingBaseEntity>(this: {
new (): T;
} & typeof ShardingBaseEntity, ids: any[], shardingKey?: string): Promise<T[]>;
static findOne<T extends ShardingBaseEntity>(this: {
new (): T;
} & typeof ShardingBaseEntity, options: FindOneOptions<T>, shardingKey?: string): Promise<T | null | undefined>;
static findOneBy<T extends ShardingBaseEntity>(this: {
new (): T;
} & typeof ShardingBaseEntity, where: FindOptionsWhere<T>, shardingKey?: string): Promise<T | null | undefined>;
/**
*
* @param this
* @param id entity id
* @param shardingKey Optional parameter, its required when sharding type is LIST
* @returns
*/
static findOneById<T extends ShardingBaseEntity>(this: {
new (): T;
} & typeof ShardingBaseEntity, id: string | number | Date | ObjectID, shardingKey?: string): Promise<T | null>;
/************************************************/
private static _shardingManager;
private static shardingManager;
private static _shardingFunc;
private static shardingFunc;
private static _shardingFuncById;
private static shardingFuncById;
private static _shardingType;
private static getShardingType;
static getAllRepository<T extends ShardingBaseEntity = ShardingBaseEntity>(): Repository<T>[];
static getRepository<T extends ShardingBaseEntity = ShardingBaseEntity>(entity: DeepPartial<T>): Repository<T>;
static getManager<T extends ShardingBaseEntity = ShardingBaseEntity>(entity: DeepPartial<T>): EntityManager;
static getAllDataSource<T extends ShardingBaseEntity = ShardingBaseEntity>(): DataSource[];
static getDataSource<T extends ShardingBaseEntity = ShardingBaseEntity>(entity: DeepPartial<T>): DataSource;
static getDataSourceById<T extends ShardingBaseEntity = ShardingBaseEntity>(id: unknown): DataSource;
static getDataSourceShardingKey<T extends ShardingBaseEntity = ShardingBaseEntity>(key: string): DataSource;
}