///
import { DeepPartial } from "../common/DeepPartial";
import { ObjectType } from "../common/ObjectType";
import { Connection } from "../connection/Connection";
import { ObjectID } from "../driver/mongodb/typings";
import { FindExtraOptions, FindOptions, FindOptionsWhere } from "../index";
import { DeleteResult } from "../query-builder/result/DeleteResult";
import { InsertResult } from "../query-builder/result/InsertResult";
import { UpdateResult } from "../query-builder/result/UpdateResult";
import { SelectQueryBuilder } from "../query-builder/SelectQueryBuilder";
import { RemoveOptions } from "./RemoveOptions";
import { Repository } from "./Repository";
import { SaveOptions } from "./SaveOptions";
import Observable = require("zen-observable");
/**
* Base abstract entity for all entities, used in ActiveRecord patterns.
*/
export declare class BaseEntity {
/**
* Connection used in all static methods of the BaseEntity.
*/
private static usedConnection?;
/**
* Checks if entity has an id.
* If entity composite compose ids, it will check them all.
*/
hasId(): boolean;
/**
* Saves current entity in the database.
* If entity does not exist in the database then inserts, otherwise updates.
*/
save(): Promise;
/**
* Removes current entity from the database.
*/
remove(): Promise;
/**
* Reloads entity data from the database.
*/
reload(): Promise;
/**
* Sets connection to be used by entity.
*/
static useConnection(connection: Connection): void;
/**
* Gets current entity's Repository.
*/
static getRepository(this: ObjectType): Repository;
/**
* Returns object that is managed by this repository.
* If this repository manages entity from schema,
* then it returns a name of that schema instead.
*/
static readonly target: Function | string;
/**
* Checks entity has an id.
* If entity composite compose ids, it will check them all.
*/
static hasId(entity: BaseEntity): boolean;
/**
* Gets entity mixed id.
*/
static getId(this: ObjectType, entity: T): any;
/**
* Creates a new query builder that can be used to build a sql query.
*/
static createQueryBuilder(this: ObjectType, alias?: string): SelectQueryBuilder;
/**
* Creates a new entity instance.
*/
static create(this: ObjectType): T;
/**
* Creates a new entities and copies all entity properties from given objects into their new entities.
* Note that it copies only properties that present in entity schema.
*/
static create(this: ObjectType, entityLikeArray: DeepPartial[]): T;
/**
* Creates a new entity instance and copies all entity properties from this object into a new entity.
* Note that it copies only properties that present in entity schema.
*/
static create(this: ObjectType, entityLike: DeepPartial): T;
/**
* Merges multiple entities (or entity-like objects) into a given entity.
*/
static merge(this: ObjectType, mergeIntoEntity: T, ...entityLikes: DeepPartial[]): T;
/**
* Creates a new entity from the given plan javascript object. If entity already exist in the database, then
* it loads it (and everything related to it), replaces all values with the new ones from the given object
* and returns this new entity. This new entity is actually a loaded from the db entity with all properties
* replaced from the new object.
*
* Note that given entity-like object must have an entity id / primary key to find entity by.
* Returns undefined if entity with given id was not found.
*/
static preload(this: ObjectType, entityLike: DeepPartial): Promise;
/**
* Saves all given entities in the database.
* If entities do not exist in the database then inserts, otherwise updates.
*/
static save(this: ObjectType, entities: T[], options?: SaveOptions): Promise;
/**
* Saves a given entity in the database.
* If entity does not exist in the database then inserts, otherwise updates.
*/
static save(this: ObjectType, entity: T, options?: SaveOptions): Promise;
/**
* Removes a given entities from the database.
*/
static remove(this: ObjectType, entities: T[], options?: RemoveOptions): Promise;
/**
* Removes a given entity from the database.
*/
static remove(this: ObjectType, entity: T, options?: RemoveOptions): Promise;
/**
* Inserts a given entity into the database.
* Unlike save method executes a primitive operation without cascades, relations and other operations included.
* Executes fast and efficient INSERT query.
* Does not check if entity exist in the database, so query will fail if duplicate entity is being inserted.
*/
static insert(this: ObjectType, entity: DeepPartial | DeepPartial[], options?: SaveOptions): Promise;
/**
* Updates entity partially. Entity can be found by a given conditions.
* Unlike save method executes a primitive operation without cascades, relations and other operations included.
* Executes fast and efficient UPDATE query.
* Does not check if entity exist in the database.
*/
static update(this: ObjectType, criteria: string | string[] | number | number[] | Date | Date[] | ObjectID | ObjectID[] | FindOptionsWhere, partialEntity: DeepPartial, options?: SaveOptions): Promise;
/**
* Deletes entities by a given criteria.
* Unlike save method executes a primitive operation without cascades, relations and other operations included.
* Executes fast and efficient DELETE query.
* Does not check if entity exist in the database.
*/
static delete(this: ObjectType, criteria: string | string[] | number | number[] | Date | Date[] | ObjectID | ObjectID[] | FindOptionsWhere, options?: RemoveOptions): Promise;
/**
* Counts entities that match given conditions.
*/
static count(this: ObjectType, conditions?: FindOptionsWhere, options?: FindExtraOptions): Promise;
/**
* Finds entities that match given options.
*/
static find(this: ObjectType, options?: FindOptions): Promise;
/**
* Finds entities that match given conditions.
*/
static find(this: ObjectType, conditions?: FindOptionsWhere): Promise;
/**
* Finds entities that match given find options.
* Also counts all entities that match given conditions,
* but ignores pagination settings (from and take options).
*/
static findAndCount(this: ObjectType, options?: FindOptions): Promise<[T[], number]>;
/**
* Finds entities that match given conditions.
* Also counts all entities that match given conditions,
* but ignores pagination settings (from and take options).
*/
static findAndCount(this: ObjectType, conditions?: FindOptionsWhere): Promise<[T[], number]>;
/**
* Finds entities by ids.
* Optionally find options can be applied.
*/
static findByIds(this: ObjectType, ids: any[], options?: FindOptions): Promise;
/**
* Finds entities by ids.
* Optionally conditions can be applied.
*/
static findByIds(this: ObjectType, ids: any[], conditions?: FindOptionsWhere): Promise;
/**
* Finds first entity that matches given options.
*/
static findOne(this: ObjectType, id?: string | number | Date | ObjectID, options?: FindOptions): Promise;
/**
* Finds first entity that matches given options.
*/
static findOne(this: ObjectType, options?: FindOptions): Promise;
/**
* Finds first entity that matches given conditions.
*/
static findOne(this: ObjectType, conditions?: FindOptionsWhere, options?: FindOptions): Promise;
/**
* Finds first entity that matches given options.
*/
static findOneOrFail(this: ObjectType, id?: string | number | Date | ObjectID, options?: FindOptions): Promise;
/**
* Finds first entity that matches given options.
*/
static findOneOrFail(this: ObjectType, options?: FindOptions): Promise;
/**
* Finds first entity that matches given conditions.
*/
static findOneOrFail(this: ObjectType, conditions?: DeepPartial, options?: FindOptions): Promise;
/**
* Finds entities that match given options and returns observable.
* Whenever new data appears that matches given query observable emits new value.
*/
static observe(options?: FindOptions): Observable;
/**
* Finds entities that match given conditions and returns observable.
* Whenever new data appears that matches given query observable emits new value.
*/
static observe(conditions?: FindOptionsWhere): Observable;
/**
* Finds entities and count that match given options and returns observable.
* Whenever new data appears that matches given query observable emits new value.
*/
static observeManyAndCount(options?: FindOptions): Observable<[Entity[], number]>;
/**
* Finds entities and count that match given conditions and returns observable.
* Whenever new data appears that matches given query observable emits new value.
*/
static observeManyAndCount(conditions?: FindOptionsWhere): Observable<[Entity[], number]>;
/**
* Finds entity that match given options and returns observable.
* Whenever new data appears that matches given query observable emits new value.
*/
static observeOne(options?: FindOptions): Observable;
/**
* Finds entity that match given conditions and returns observable.
* Whenever new data appears that matches given query observable emits new value.
*/
static observeOne(conditions?: FindOptionsWhere): Observable;
/**
* Gets the entities count match given options and returns observable.
* Whenever new data appears that matches given query observable emits new value.
*/
static observeCount(options?: FindOptions): Observable;
/**
* Gets the entities count match given options and returns observable.
* Whenever new data appears that matches given query observable emits new value.
*/
static observeCount(conditions?: FindOptionsWhere): Observable;
/**
* Executes a raw SQL query and returns a raw database results.
* Raw query execution is supported only by relational databases (MongoDB is not supported).
*/
static query(this: ObjectType, query: string, parameters?: any[]): Promise;
/**
* Clears all the data from the given table/collection (truncates/drops it).
*/
static clear(this: ObjectType): Promise;
}