typeorm 0.2.40-dev.ae858ad → 0.2.41-dev.1f558b1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/decorator/columns/PrimaryGeneratedColumn.d.ts +1 -0
- package/browser/decorator/columns/PrimaryGeneratedColumn.js +1 -1
- package/browser/decorator/columns/PrimaryGeneratedColumn.js.map +1 -1
- package/browser/decorator/options/ColumnCommonOptions.d.ts +1 -1
- package/browser/decorator/options/ColumnCommonOptions.js.map +1 -1
- package/browser/driver/Driver.d.ts +5 -0
- package/browser/driver/Driver.js.map +1 -1
- package/browser/driver/aurora-data-api/AuroraDataApiDriver.d.ts +4 -0
- package/browser/driver/aurora-data-api/AuroraDataApiDriver.js +4 -0
- package/browser/driver/aurora-data-api/AuroraDataApiDriver.js.map +1 -1
- package/browser/driver/cockroachdb/CockroachDriver.d.ts +4 -0
- package/browser/driver/cockroachdb/CockroachDriver.js +4 -0
- package/browser/driver/cockroachdb/CockroachDriver.js.map +1 -1
- package/browser/driver/mysql/MysqlDriver.d.ts +4 -0
- package/browser/driver/mysql/MysqlDriver.js +10 -3
- package/browser/driver/mysql/MysqlDriver.js.map +1 -1
- package/browser/driver/postgres/PostgresDriver.d.ts +4 -0
- package/browser/driver/postgres/PostgresDriver.js +4 -0
- package/browser/driver/postgres/PostgresDriver.js.map +1 -1
- package/browser/driver/postgres/PostgresQueryRunner.js +19 -8
- package/browser/driver/postgres/PostgresQueryRunner.js.map +1 -1
- package/browser/driver/sqlite-abstract/AbstractSqliteDriver.d.ts +4 -0
- package/browser/driver/sqlite-abstract/AbstractSqliteDriver.js +4 -0
- package/browser/driver/sqlite-abstract/AbstractSqliteDriver.js.map +1 -1
- package/browser/driver/types/UpsertType.d.ts +1 -0
- package/browser/driver/types/UpsertType.js +3 -0
- package/browser/driver/types/UpsertType.js.map +1 -0
- package/browser/entity-manager/EntityManager.d.ts +2 -0
- package/browser/entity-manager/EntityManager.js +42 -1
- package/browser/entity-manager/EntityManager.js.map +1 -1
- package/browser/find-options/FindConditions.d.ts +6 -2
- package/browser/find-options/FindConditions.js.map +1 -1
- package/browser/find-options/FindTreeOptions.d.ts +5 -1
- package/browser/find-options/FindTreeOptions.js.map +1 -1
- package/browser/metadata/EntityMetadata.d.ts +4 -0
- package/browser/metadata/EntityMetadata.js +14 -0
- package/browser/metadata/EntityMetadata.js.map +1 -1
- package/browser/query-builder/InsertQueryBuilder.js +8 -2
- package/browser/query-builder/InsertQueryBuilder.js.map +1 -1
- package/browser/query-builder/SelectQueryBuilder.d.ts +1 -1
- package/browser/query-builder/SelectQueryBuilder.js +4 -20
- package/browser/query-builder/SelectQueryBuilder.js.map +1 -1
- package/browser/repository/BaseEntity.d.ts +7 -0
- package/browser/repository/BaseEntity.js +8 -0
- package/browser/repository/BaseEntity.js.map +1 -1
- package/browser/repository/FindTreesOptions.d.ts +9 -0
- package/browser/repository/FindTreesOptions.js +3 -0
- package/browser/repository/FindTreesOptions.js.map +1 -0
- package/browser/repository/Repository.d.ts +7 -0
- package/browser/repository/Repository.js +8 -0
- package/browser/repository/Repository.js.map +1 -1
- package/browser/repository/TreeRepository.d.ts +4 -1
- package/browser/repository/TreeRepository.js +8 -4
- package/browser/repository/TreeRepository.js.map +1 -1
- package/browser/repository/UpsertOptions.d.ts +6 -0
- package/browser/repository/UpsertOptions.js +3 -0
- package/browser/repository/UpsertOptions.js.map +1 -0
- package/browser/schema-builder/options/TableColumnOptions.d.ts +1 -1
- package/browser/schema-builder/options/TableColumnOptions.js.map +1 -1
- package/browser/schema-builder/table/TableColumn.d.ts +1 -1
- package/browser/schema-builder/table/TableColumn.js.map +1 -1
- package/browser/util/OrmUtils.d.ts +1 -0
- package/browser/util/OrmUtils.js +11 -0
- package/browser/util/OrmUtils.js.map +1 -1
- package/decorator/columns/PrimaryGeneratedColumn.d.ts +1 -0
- package/decorator/columns/PrimaryGeneratedColumn.js +1 -1
- package/decorator/columns/PrimaryGeneratedColumn.js.map +1 -1
- package/decorator/options/ColumnCommonOptions.d.ts +1 -1
- package/decorator/options/ColumnCommonOptions.js.map +1 -1
- package/driver/Driver.d.ts +5 -0
- package/driver/Driver.js.map +1 -1
- package/driver/aurora-data-api/AuroraDataApiDriver.d.ts +4 -0
- package/driver/aurora-data-api/AuroraDataApiDriver.js +4 -0
- package/driver/aurora-data-api/AuroraDataApiDriver.js.map +1 -1
- package/driver/cockroachdb/CockroachDriver.d.ts +4 -0
- package/driver/cockroachdb/CockroachDriver.js +4 -0
- package/driver/cockroachdb/CockroachDriver.js.map +1 -1
- package/driver/mysql/MysqlDriver.d.ts +4 -0
- package/driver/mysql/MysqlDriver.js +10 -3
- package/driver/mysql/MysqlDriver.js.map +1 -1
- package/driver/postgres/PostgresDriver.d.ts +4 -0
- package/driver/postgres/PostgresDriver.js +4 -0
- package/driver/postgres/PostgresDriver.js.map +1 -1
- package/driver/postgres/PostgresQueryRunner.js +19 -8
- package/driver/postgres/PostgresQueryRunner.js.map +1 -1
- package/driver/sqlite-abstract/AbstractSqliteDriver.d.ts +4 -0
- package/driver/sqlite-abstract/AbstractSqliteDriver.js +4 -0
- package/driver/sqlite-abstract/AbstractSqliteDriver.js.map +1 -1
- package/driver/types/UpsertType.d.ts +1 -0
- package/driver/types/UpsertType.js +4 -0
- package/driver/types/UpsertType.js.map +1 -0
- package/entity-manager/EntityManager.d.ts +2 -0
- package/entity-manager/EntityManager.js +41 -0
- package/entity-manager/EntityManager.js.map +1 -1
- package/find-options/FindConditions.d.ts +6 -2
- package/find-options/FindConditions.js.map +1 -1
- package/find-options/FindTreeOptions.d.ts +5 -1
- package/find-options/FindTreeOptions.js.map +1 -1
- package/metadata/EntityMetadata.d.ts +4 -0
- package/metadata/EntityMetadata.js +14 -0
- package/metadata/EntityMetadata.js.map +1 -1
- package/package.json +1 -1
- package/query-builder/InsertQueryBuilder.js +11 -5
- package/query-builder/InsertQueryBuilder.js.map +1 -1
- package/query-builder/SelectQueryBuilder.d.ts +1 -1
- package/query-builder/SelectQueryBuilder.js +4 -20
- package/query-builder/SelectQueryBuilder.js.map +1 -1
- package/repository/BaseEntity.d.ts +7 -0
- package/repository/BaseEntity.js +8 -0
- package/repository/BaseEntity.js.map +1 -1
- package/repository/FindTreesOptions.d.ts +9 -0
- package/repository/FindTreesOptions.js +4 -0
- package/repository/FindTreesOptions.js.map +1 -0
- package/repository/Repository.d.ts +7 -0
- package/repository/Repository.js +8 -0
- package/repository/Repository.js.map +1 -1
- package/repository/TreeRepository.d.ts +4 -1
- package/repository/TreeRepository.js +7 -3
- package/repository/TreeRepository.js.map +1 -1
- package/repository/UpsertOptions.d.ts +6 -0
- package/repository/UpsertOptions.js +4 -0
- package/repository/UpsertOptions.js.map +1 -0
- package/schema-builder/options/TableColumnOptions.d.ts +1 -1
- package/schema-builder/options/TableColumnOptions.js.map +1 -1
- package/schema-builder/table/TableColumn.d.ts +1 -1
- package/schema-builder/table/TableColumn.js.map +1 -1
- package/util/OrmUtils.d.ts +1 -0
- package/util/OrmUtils.js +11 -0
- package/util/OrmUtils.js.map +1 -1
|
@@ -13,6 +13,7 @@ import { UpdateResult } from "../query-builder/result/UpdateResult";
|
|
|
13
13
|
import { DeleteResult } from "../query-builder/result/DeleteResult";
|
|
14
14
|
import { ObjectID } from "../driver/mongodb/typings";
|
|
15
15
|
import { QueryDeepPartialEntity } from "../query-builder/QueryPartialEntity";
|
|
16
|
+
import { UpsertOptions } from "./UpsertOptions";
|
|
16
17
|
/**
|
|
17
18
|
* Base abstract entity for all entities, used in ActiveRecord patterns.
|
|
18
19
|
*/
|
|
@@ -142,6 +143,12 @@ export declare class BaseEntity {
|
|
|
142
143
|
* Does not check if entity exist in the database.
|
|
143
144
|
*/
|
|
144
145
|
static update<T extends BaseEntity>(this: ObjectType<T>, criteria: string | string[] | number | number[] | Date | Date[] | ObjectID | ObjectID[] | FindConditions<T>, partialEntity: QueryDeepPartialEntity<T>, options?: SaveOptions): Promise<UpdateResult>;
|
|
146
|
+
/**
|
|
147
|
+
* Inserts a given entity into the database, unless a unique constraint conflicts then updates the entity
|
|
148
|
+
* Unlike save method executes a primitive operation without cascades, relations and other operations included.
|
|
149
|
+
* Executes fast and efficient INSERT ... ON CONFLICT DO UPDATE/ON DUPLICATE KEY UPDATE query.
|
|
150
|
+
*/
|
|
151
|
+
static upsert<T extends BaseEntity>(this: ObjectType<T> & typeof BaseEntity, entityOrEntities: QueryDeepPartialEntity<T> | (QueryDeepPartialEntity<T>[]), conflictPathsOrOptions: string[] | UpsertOptions<T>): Promise<InsertResult>;
|
|
145
152
|
/**
|
|
146
153
|
* Deletes entities by a given criteria.
|
|
147
154
|
* Unlike remove method executes a primitive operation without cascades, relations and other operations included.
|
|
@@ -174,6 +174,14 @@ var BaseEntity = /** @class */ (function () {
|
|
|
174
174
|
BaseEntity.update = function (criteria, partialEntity, options) {
|
|
175
175
|
return this.getRepository().update(criteria, partialEntity, options);
|
|
176
176
|
};
|
|
177
|
+
/**
|
|
178
|
+
* Inserts a given entity into the database, unless a unique constraint conflicts then updates the entity
|
|
179
|
+
* Unlike save method executes a primitive operation without cascades, relations and other operations included.
|
|
180
|
+
* Executes fast and efficient INSERT ... ON CONFLICT DO UPDATE/ON DUPLICATE KEY UPDATE query.
|
|
181
|
+
*/
|
|
182
|
+
BaseEntity.upsert = function (entityOrEntities, conflictPathsOrOptions) {
|
|
183
|
+
return this.getRepository().upsert(entityOrEntities, conflictPathsOrOptions);
|
|
184
|
+
};
|
|
177
185
|
/**
|
|
178
186
|
* Deletes entities by a given criteria.
|
|
179
187
|
* Unlike remove method executes a primitive operation without cascades, relations and other operations included.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/repository/BaseEntity.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AAczC,OAAO,EAAC,WAAW,EAAC,MAAM,qBAAqB,CAAC;AAGhD;;GAEG;AACH;IAAA;IAwXA,CAAC;IA5WG,4EAA4E;IAC5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A+D,mBAA0D;QACrH,OAAQ,IAAY,CAAC,aAAa,EAAE,CAAC,YAAY,CAAC,mBAA0B,CAAC,CAAC;IAClF,CAAC;IAcD;;;OAGG;IACI,oBAAS,GAAhB,UAA4D,GAAU,EAAE,mBAA0D;QAC9H,OAAQ,IAAY,CAAC,aAAa,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,mBAA0B,CAAC,CAAC;IACpF,CAAC;IAiBD;;OAEG;IACI,kBAAO,GAAd,UAA0D,mBAAqF,EAAE,YAAgC;QAC7K,OAAQ,IAAY,CAAC,aAAa,EAAE,CAAC,OAAO,CAAC,mBAA0B,EAAE,YAAY,CAAC,CAAC;IAC3F,CAAC;IAiBD;;OAEG;IACI,wBAAa,GAApB,UAAgE,mBAAqF,EAAE,YAAgC;QACnL,OAAQ,IAAY,CAAC,aAAa,EAAE,CAAC,aAAa,CAAC,mBAA0B,EAAE,YAAY,CAAC,CAAC;IACjG,CAAC;IAED;;;OAGG;IACI,gBAAK,GAAZ,UAAwD,KAAa,EAAE,UAAkB;QACrF,OAAQ,IAAY,CAAC,aAAa,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IAClE,CAAC;IAED;;OAEG;IACI,gBAAK,GAAZ;QACI,OAAQ,IAAY,CAAC,aAAa,EAAE,CAAC,KAAK,EAAE,CAAC;IACjD,CAAC;IAEL,iBAAC;AAAD,CAxXA,AAwXC,IAAA","file":"BaseEntity.js","sourcesContent":["import {Repository} from \"./Repository\";\nimport {getConnection} from \"../globals\";\nimport {FindConditions} from \"../find-options/FindConditions\";\nimport {DeepPartial} from \"../common/DeepPartial\";\nimport {SaveOptions} from \"./SaveOptions\";\nimport {FindOneOptions} from \"../find-options/FindOneOptions\";\nimport {RemoveOptions} from \"./RemoveOptions\";\nimport {FindManyOptions} from \"../find-options/FindManyOptions\";\nimport {Connection} from \"../connection/Connection\";\nimport {ObjectType} from \"../common/ObjectType\";\nimport {SelectQueryBuilder} from \"../query-builder/SelectQueryBuilder\";\nimport {InsertResult} from \"../query-builder/result/InsertResult\";\nimport {UpdateResult} from \"../query-builder/result/UpdateResult\";\nimport {DeleteResult} from \"../query-builder/result/DeleteResult\";\nimport {ObjectID} from \"../driver/mongodb/typings\";\nimport {ObjectUtils} from \"../util/ObjectUtils\";\nimport {QueryDeepPartialEntity} from \"../query-builder/QueryPartialEntity\";\n\n/**\n * Base abstract entity for all entities, used in ActiveRecord patterns.\n */\nexport class BaseEntity {\n\n // -------------------------------------------------------------------------\n // Private Static Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection used in all static methods of the BaseEntity.\n */\n // @ts-ignore: Unused variable which is actually used\n private static usedConnection?: Connection;\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Checks if entity has an id.\n * If entity composite compose ids, it will check them all.\n */\n hasId(): boolean {\n return (this.constructor as any).getRepository().hasId(this);\n }\n\n /**\n * Saves current entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n save(options?: SaveOptions): Promise<this> {\n return (this.constructor as any).getRepository().save(this, options);\n }\n\n /**\n * Removes current entity from the database.\n */\n remove(options?: RemoveOptions): Promise<this> {\n return (this.constructor as any).getRepository().remove(this, options);\n }\n\n /**\n * Records the delete date of current entity.\n */\n softRemove(options?: SaveOptions): Promise<this> {\n return (this.constructor as any).getRepository().softRemove(this, options);\n }\n\n /**\n * Recovers a given entity in the database.\n */\n recover(options?: SaveOptions): Promise<this> {\n return (this.constructor as any).getRepository().recover(this, options);\n }\n\n /**\n * Reloads entity data from the database.\n */\n async reload(): Promise<void> {\n const base: any = this.constructor;\n const newestEntity: BaseEntity = await base.getRepository().findOneOrFail(base.getId(this));\n\n ObjectUtils.assign(this, newestEntity);\n }\n\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Sets connection to be used by entity.\n */\n static useConnection(connection: Connection) {\n this.usedConnection = connection;\n }\n\n /**\n * Gets current entity's Repository.\n */\n static getRepository<T extends BaseEntity>(this: ObjectType<T>): Repository<T> {\n const connection: Connection = (this as any).usedConnection || getConnection();\n return connection.getRepository<T>(this);\n }\n\n /**\n * Returns object that is managed by this repository.\n * If this repository manages entity from schema,\n * then it returns a name of that schema instead.\n */\n static get target(): Function|string {\n return this.getRepository().target;\n }\n\n /**\n * Checks entity has an id.\n * If entity composite compose ids, it will check them all.\n */\n static hasId(entity: BaseEntity): boolean {\n return this.getRepository().hasId(entity);\n }\n\n /**\n * Gets entity mixed id.\n */\n static getId<T extends BaseEntity>(this: ObjectType<T>, entity: T): any {\n return (this as any).getRepository().getId(entity);\n }\n\n /**\n * Creates a new query builder that can be used to build a sql query.\n */\n static createQueryBuilder<T extends BaseEntity>(this: ObjectType<T>, alias?: string): SelectQueryBuilder<T> {\n return (this as any).getRepository().createQueryBuilder(alias);\n }\n\n /**\n * Creates a new entity instance.\n */\n static create<T extends BaseEntity>(this: ObjectType<T>): T;\n\n /**\n * Creates a new entities and copies all entity properties from given objects into their new entities.\n * Note that it copies only properties that present in entity schema.\n */\n static create<T extends BaseEntity>(this: ObjectType<T>, entityLikeArray: DeepPartial<T>[]): T[];\n\n /**\n * Creates a new entity instance and copies all entity properties from this object into a new entity.\n * Note that it copies only properties that present in entity schema.\n */\n static create<T extends BaseEntity>(this: ObjectType<T>, entityLike: DeepPartial<T>): T;\n /**\n * Creates a new entity instance and copies all entity properties from this object into a new entity.\n * Note that it copies only properties that present in entity schema.\n */\n static create<T extends BaseEntity>(this: ObjectType<T>, entityOrEntities?: any): T {\n return (this as any).getRepository().create(entityOrEntities);\n }\n\n /**\n * Merges multiple entities (or entity-like objects) into a given entity.\n */\n static merge<T extends BaseEntity>(this: ObjectType<T>, mergeIntoEntity: T, ...entityLikes: DeepPartial<T>[]): T {\n return (this as any).getRepository().merge(mergeIntoEntity, ...entityLikes);\n }\n\n /**\n * Creates a new entity from the given plain javascript object. If entity already exist in the database, then\n * it loads it (and everything related to it), replaces all values with the new ones from the given object\n * and returns this new entity. This new entity is actually a loaded from the db entity with all properties\n * replaced from the new object.\n *\n * Note that given entity-like object must have an entity id / primary key to find entity by.\n * Returns undefined if entity with given id was not found.\n */\n static preload<T extends BaseEntity>(this: ObjectType<T>, entityLike: DeepPartial<T>): Promise<T|undefined> {\n return (this as any).getRepository().preload(entityLike);\n }\n\n /**\n * Saves all given entities in the database.\n * If entities do not exist in the database then inserts, otherwise updates.\n */\n static save<T extends BaseEntity>(this: ObjectType<T>, entities: T[], options?: SaveOptions): Promise<T[]>;\n\n /**\n * Saves a given entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n static save<T extends BaseEntity>(this: ObjectType<T>, entity: T, options?: SaveOptions): Promise<T>;\n\n /**\n * Saves one or many given entities.\n */\n static save<T extends BaseEntity>(this: ObjectType<T>, entityOrEntities: T|T[], options?: SaveOptions): Promise<T|T[]> {\n return (this as any).getRepository().save(entityOrEntities as any, options);\n }\n\n /**\n * Removes a given entities from the database.\n */\n static remove<T extends BaseEntity>(this: ObjectType<T>, entities: T[], options?: RemoveOptions): Promise<T[]>;\n\n /**\n * Removes a given entity from the database.\n */\n static remove<T extends BaseEntity>(this: ObjectType<T>, entity: T, options?: RemoveOptions): Promise<T>;\n\n /**\n * Removes one or many given entities.\n */\n static remove<T extends BaseEntity>(this: ObjectType<T>, entityOrEntities: T|T[], options?: RemoveOptions): Promise<T|T[]> {\n return (this as any).getRepository().remove(entityOrEntities as any, options);\n }\n\n /**\n * Records the delete date of all given entities.\n */\n static softRemove<T extends BaseEntity>(this: ObjectType<T>, entities: T[], options?: SaveOptions): Promise<T[]>;\n\n /**\n * Records the delete date of a given entity.\n */\n static softRemove<T extends BaseEntity>(this: ObjectType<T>, entity: T, options?: SaveOptions): Promise<T>;\n\n /**\n * Records the delete date of one or many given entities.\n */\n static softRemove<T extends BaseEntity>(this: ObjectType<T>, entityOrEntities: T|T[], options?: SaveOptions): Promise<T|T[]> {\n return (this as any).getRepository().softRemove(entityOrEntities as any, options);\n }\n\n /**\n * Inserts a given entity into the database.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient INSERT query.\n * Does not check if entity exist in the database, so query will fail if duplicate entity is being inserted.\n */\n static insert<T extends BaseEntity>(this: ObjectType<T>, entity: QueryDeepPartialEntity<T>|QueryDeepPartialEntity<T>[], options?: SaveOptions): Promise<InsertResult> {\n return (this as any).getRepository().insert(entity, options);\n }\n\n /**\n * Updates entity partially. Entity can be found by a given conditions.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient UPDATE query.\n * Does not check if entity exist in the database.\n */\n static update<T extends BaseEntity>(this: ObjectType<T>, criteria: string|string[]|number|number[]|Date|Date[]|ObjectID|ObjectID[]|FindConditions<T>, partialEntity: QueryDeepPartialEntity<T>, options?: SaveOptions): Promise<UpdateResult> {\n return (this as any).getRepository().update(criteria, partialEntity, options);\n }\n\n /**\n * Deletes entities by a given criteria.\n * Unlike remove method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient DELETE query.\n * Does not check if entity exist in the database.\n */\n static delete<T extends BaseEntity>(this: ObjectType<T>, criteria: string|string[]|number|number[]|Date|Date[]|ObjectID|ObjectID[]|FindConditions<T>, options?: RemoveOptions): Promise<DeleteResult> {\n return (this as any).getRepository().delete(criteria, options);\n }\n\n /**\n * Counts entities that match given options.\n */\n static count<T extends BaseEntity>(this: ObjectType<T>, options?: FindManyOptions<T>): Promise<number>;\n\n /**\n * Counts entities that match given conditions.\n */\n static count<T extends BaseEntity>(this: ObjectType<T>, conditions?: FindConditions<T>): Promise<number>;\n\n /**\n * Counts entities that match given find options or conditions.\n */\n static count<T extends BaseEntity>(this: ObjectType<T>, optionsOrConditions?: FindManyOptions<T>|FindConditions<T>): Promise<number> {\n return (this as any).getRepository().count(optionsOrConditions as any);\n }\n\n /**\n * Finds entities that match given options.\n */\n static find<T extends BaseEntity>(this: ObjectType<T>, options?: FindManyOptions<T>): Promise<T[]>;\n\n /**\n * Finds entities that match given conditions.\n */\n static find<T extends BaseEntity>(this: ObjectType<T>, conditions?: FindConditions<T>): Promise<T[]>;\n\n /**\n * Finds entities that match given find options or conditions.\n */\n static find<T extends BaseEntity>(this: ObjectType<T>, optionsOrConditions?: FindManyOptions<T>|FindConditions<T>): Promise<T[]> {\n return (this as any).getRepository().find(optionsOrConditions as any);\n }\n\n /**\n * Finds entities that match given find options.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n static findAndCount<T extends BaseEntity>(this: ObjectType<T>, options?: FindManyOptions<T>): Promise<[ T[], number ]>;\n\n /**\n * Finds entities that match given conditions.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n static findAndCount<T extends BaseEntity>(this: ObjectType<T>, conditions?: FindConditions<T>): Promise<[ T[], number ]>;\n\n /**\n * Finds entities that match given find options or conditions.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n static findAndCount<T extends BaseEntity>(this: ObjectType<T>, optionsOrConditions?: FindManyOptions<T>|FindConditions<T>): Promise<[ T[], number ]> {\n return (this as any).getRepository().findAndCount(optionsOrConditions as any);\n }\n\n /**\n * Finds entities by ids.\n * Optionally find options can be applied.\n */\n static findByIds<T extends BaseEntity>(this: ObjectType<T>, ids: any[], options?: FindManyOptions<T>): Promise<T[]>;\n\n /**\n * Finds entities by ids.\n * Optionally conditions can be applied.\n */\n static findByIds<T extends BaseEntity>(this: ObjectType<T>, ids: any[], conditions?: FindConditions<T>): Promise<T[]>;\n\n /**\n * Finds entities by ids.\n * Optionally find options can be applied.\n */\n static findByIds<T extends BaseEntity>(this: ObjectType<T>, ids: any[], optionsOrConditions?: FindManyOptions<T>|FindConditions<T>): Promise<T[]> {\n return (this as any).getRepository().findByIds(ids, optionsOrConditions as any);\n }\n\n /**\n * Finds first entity that matches given options.\n */\n static findOne<T extends BaseEntity>(this: ObjectType<T>, id?: string|number|Date|ObjectID, options?: FindOneOptions<T>): Promise<T|undefined>;\n\n /**\n * Finds first entity that matches given options.\n */\n static findOne<T extends BaseEntity>(this: ObjectType<T>, options?: FindOneOptions<T>): Promise<T|undefined>;\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOne<T extends BaseEntity>(this: ObjectType<T>, conditions?: FindConditions<T>, options?: FindOneOptions<T>): Promise<T|undefined>;\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOne<T extends BaseEntity>(this: ObjectType<T>, optionsOrConditions?: string|number|Date|ObjectID|FindOneOptions<T>|FindConditions<T>, maybeOptions?: FindOneOptions<T>): Promise<T|undefined> {\n return (this as any).getRepository().findOne(optionsOrConditions as any, maybeOptions);\n }\n\n /**\n * Finds first entity that matches given options.\n */\n static findOneOrFail<T extends BaseEntity>(this: ObjectType<T>, id?: string|number|Date|ObjectID, options?: FindOneOptions<T>): Promise<T>;\n\n /**\n * Finds first entity that matches given options.\n */\n static findOneOrFail<T extends BaseEntity>(this: ObjectType<T>, options?: FindOneOptions<T>): Promise<T>;\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneOrFail<T extends BaseEntity>(this: ObjectType<T>, conditions?: FindConditions<T>, options?: FindOneOptions<T>): Promise<T>;\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneOrFail<T extends BaseEntity>(this: ObjectType<T>, optionsOrConditions?: string|number|Date|ObjectID|FindOneOptions<T>|FindConditions<T>, maybeOptions?: FindOneOptions<T>): Promise<T> {\n return (this as any).getRepository().findOneOrFail(optionsOrConditions as any, maybeOptions);\n }\n\n /**\n * Executes a raw SQL query and returns a raw database results.\n * Raw query execution is supported only by relational databases (MongoDB is not supported).\n */\n static query<T extends BaseEntity>(this: ObjectType<T>, query: string, parameters?: any[]): Promise<any> {\n return (this as any).getRepository().query(query, parameters);\n }\n\n /**\n * Clears all the data from the given table/collection (truncates/drops it).\n */\n static clear<T extends BaseEntity>(this: ObjectType<T>, ): Promise<void> {\n return (this as any).getRepository().clear();\n }\n\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,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nYA,AAmYC,IAAA","file":"BaseEntity.js","sourcesContent":["import {Repository} from \"./Repository\";\nimport {getConnection} from \"../globals\";\nimport {FindConditions} from \"../find-options/FindConditions\";\nimport {DeepPartial} from \"../common/DeepPartial\";\nimport {SaveOptions} from \"./SaveOptions\";\nimport {FindOneOptions} from \"../find-options/FindOneOptions\";\nimport {RemoveOptions} from \"./RemoveOptions\";\nimport {FindManyOptions} from \"../find-options/FindManyOptions\";\nimport {Connection} from \"../connection/Connection\";\nimport {ObjectType} from \"../common/ObjectType\";\nimport {SelectQueryBuilder} from \"../query-builder/SelectQueryBuilder\";\nimport {InsertResult} from \"../query-builder/result/InsertResult\";\nimport {UpdateResult} from \"../query-builder/result/UpdateResult\";\nimport {DeleteResult} from \"../query-builder/result/DeleteResult\";\nimport {ObjectID} from \"../driver/mongodb/typings\";\nimport {ObjectUtils} from \"../util/ObjectUtils\";\nimport {QueryDeepPartialEntity} from \"../query-builder/QueryPartialEntity\";\nimport {UpsertOptions} from \"./UpsertOptions\";\n\n/**\n * Base abstract entity for all entities, used in ActiveRecord patterns.\n */\nexport class BaseEntity {\n\n // -------------------------------------------------------------------------\n // Private Static Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection used in all static methods of the BaseEntity.\n */\n // @ts-ignore: Unused variable which is actually used\n private static usedConnection?: Connection;\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Checks if entity has an id.\n * If entity composite compose ids, it will check them all.\n */\n hasId(): boolean {\n return (this.constructor as any).getRepository().hasId(this);\n }\n\n /**\n * Saves current entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n save(options?: SaveOptions): Promise<this> {\n return (this.constructor as any).getRepository().save(this, options);\n }\n\n /**\n * Removes current entity from the database.\n */\n remove(options?: RemoveOptions): Promise<this> {\n return (this.constructor as any).getRepository().remove(this, options);\n }\n\n /**\n * Records the delete date of current entity.\n */\n softRemove(options?: SaveOptions): Promise<this> {\n return (this.constructor as any).getRepository().softRemove(this, options);\n }\n\n /**\n * Recovers a given entity in the database.\n */\n recover(options?: SaveOptions): Promise<this> {\n return (this.constructor as any).getRepository().recover(this, options);\n }\n\n /**\n * Reloads entity data from the database.\n */\n async reload(): Promise<void> {\n const base: any = this.constructor;\n const newestEntity: BaseEntity = await base.getRepository().findOneOrFail(base.getId(this));\n\n ObjectUtils.assign(this, newestEntity);\n }\n\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Sets connection to be used by entity.\n */\n static useConnection(connection: Connection) {\n this.usedConnection = connection;\n }\n\n /**\n * Gets current entity's Repository.\n */\n static getRepository<T extends BaseEntity>(this: ObjectType<T>): Repository<T> {\n const connection: Connection = (this as any).usedConnection || getConnection();\n return connection.getRepository<T>(this);\n }\n\n /**\n * Returns object that is managed by this repository.\n * If this repository manages entity from schema,\n * then it returns a name of that schema instead.\n */\n static get target(): Function|string {\n return this.getRepository().target;\n }\n\n /**\n * Checks entity has an id.\n * If entity composite compose ids, it will check them all.\n */\n static hasId(entity: BaseEntity): boolean {\n return this.getRepository().hasId(entity);\n }\n\n /**\n * Gets entity mixed id.\n */\n static getId<T extends BaseEntity>(this: ObjectType<T>, entity: T): any {\n return (this as any).getRepository().getId(entity);\n }\n\n /**\n * Creates a new query builder that can be used to build a sql query.\n */\n static createQueryBuilder<T extends BaseEntity>(this: ObjectType<T>, alias?: string): SelectQueryBuilder<T> {\n return (this as any).getRepository().createQueryBuilder(alias);\n }\n\n /**\n * Creates a new entity instance.\n */\n static create<T extends BaseEntity>(this: ObjectType<T>): T;\n\n /**\n * Creates a new entities and copies all entity properties from given objects into their new entities.\n * Note that it copies only properties that present in entity schema.\n */\n static create<T extends BaseEntity>(this: ObjectType<T>, entityLikeArray: DeepPartial<T>[]): T[];\n\n /**\n * Creates a new entity instance and copies all entity properties from this object into a new entity.\n * Note that it copies only properties that present in entity schema.\n */\n static create<T extends BaseEntity>(this: ObjectType<T>, entityLike: DeepPartial<T>): T;\n /**\n * Creates a new entity instance and copies all entity properties from this object into a new entity.\n * Note that it copies only properties that present in entity schema.\n */\n static create<T extends BaseEntity>(this: ObjectType<T>, entityOrEntities?: any): T {\n return (this as any).getRepository().create(entityOrEntities);\n }\n\n /**\n * Merges multiple entities (or entity-like objects) into a given entity.\n */\n static merge<T extends BaseEntity>(this: ObjectType<T>, mergeIntoEntity: T, ...entityLikes: DeepPartial<T>[]): T {\n return (this as any).getRepository().merge(mergeIntoEntity, ...entityLikes);\n }\n\n /**\n * Creates a new entity from the given plain javascript object. If entity already exist in the database, then\n * it loads it (and everything related to it), replaces all values with the new ones from the given object\n * and returns this new entity. This new entity is actually a loaded from the db entity with all properties\n * replaced from the new object.\n *\n * Note that given entity-like object must have an entity id / primary key to find entity by.\n * Returns undefined if entity with given id was not found.\n */\n static preload<T extends BaseEntity>(this: ObjectType<T>, entityLike: DeepPartial<T>): Promise<T|undefined> {\n return (this as any).getRepository().preload(entityLike);\n }\n\n /**\n * Saves all given entities in the database.\n * If entities do not exist in the database then inserts, otherwise updates.\n */\n static save<T extends BaseEntity>(this: ObjectType<T>, entities: T[], options?: SaveOptions): Promise<T[]>;\n\n /**\n * Saves a given entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n static save<T extends BaseEntity>(this: ObjectType<T>, entity: T, options?: SaveOptions): Promise<T>;\n\n /**\n * Saves one or many given entities.\n */\n static save<T extends BaseEntity>(this: ObjectType<T>, entityOrEntities: T|T[], options?: SaveOptions): Promise<T|T[]> {\n return (this as any).getRepository().save(entityOrEntities as any, options);\n }\n\n /**\n * Removes a given entities from the database.\n */\n static remove<T extends BaseEntity>(this: ObjectType<T>, entities: T[], options?: RemoveOptions): Promise<T[]>;\n\n /**\n * Removes a given entity from the database.\n */\n static remove<T extends BaseEntity>(this: ObjectType<T>, entity: T, options?: RemoveOptions): Promise<T>;\n\n /**\n * Removes one or many given entities.\n */\n static remove<T extends BaseEntity>(this: ObjectType<T>, entityOrEntities: T|T[], options?: RemoveOptions): Promise<T|T[]> {\n return (this as any).getRepository().remove(entityOrEntities as any, options);\n }\n\n /**\n * Records the delete date of all given entities.\n */\n static softRemove<T extends BaseEntity>(this: ObjectType<T>, entities: T[], options?: SaveOptions): Promise<T[]>;\n\n /**\n * Records the delete date of a given entity.\n */\n static softRemove<T extends BaseEntity>(this: ObjectType<T>, entity: T, options?: SaveOptions): Promise<T>;\n\n /**\n * Records the delete date of one or many given entities.\n */\n static softRemove<T extends BaseEntity>(this: ObjectType<T>, entityOrEntities: T|T[], options?: SaveOptions): Promise<T|T[]> {\n return (this as any).getRepository().softRemove(entityOrEntities as any, options);\n }\n\n /**\n * Inserts a given entity into the database.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient INSERT query.\n * Does not check if entity exist in the database, so query will fail if duplicate entity is being inserted.\n */\n static insert<T extends BaseEntity>(this: ObjectType<T>, entity: QueryDeepPartialEntity<T>|QueryDeepPartialEntity<T>[], options?: SaveOptions): Promise<InsertResult> {\n return (this as any).getRepository().insert(entity, options);\n }\n\n /**\n * Updates entity partially. Entity can be found by a given conditions.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient UPDATE query.\n * Does not check if entity exist in the database.\n */\n static update<T extends BaseEntity>(this: ObjectType<T>, criteria: string|string[]|number|number[]|Date|Date[]|ObjectID|ObjectID[]|FindConditions<T>, partialEntity: QueryDeepPartialEntity<T>, options?: SaveOptions): Promise<UpdateResult> {\n return (this as any).getRepository().update(criteria, partialEntity, options);\n }\n\n /**\n * Inserts a given entity into the database, unless a unique constraint conflicts then updates the entity\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient INSERT ... ON CONFLICT DO UPDATE/ON DUPLICATE KEY UPDATE query.\n */\n static upsert<T extends BaseEntity>(this: ObjectType<T> & typeof BaseEntity, \n entityOrEntities: QueryDeepPartialEntity<T> | (QueryDeepPartialEntity<T>[]),\n conflictPathsOrOptions: string[] | UpsertOptions<T>): Promise<InsertResult> {\n return this.getRepository<T>().upsert(entityOrEntities, conflictPathsOrOptions);\n }\n\n /**\n * Deletes entities by a given criteria.\n * Unlike remove method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient DELETE query.\n * Does not check if entity exist in the database.\n */\n static delete<T extends BaseEntity>(this: ObjectType<T>, criteria: string|string[]|number|number[]|Date|Date[]|ObjectID|ObjectID[]|FindConditions<T>, options?: RemoveOptions): Promise<DeleteResult> {\n return (this as any).getRepository().delete(criteria, options);\n }\n\n /**\n * Counts entities that match given options.\n */\n static count<T extends BaseEntity>(this: ObjectType<T>, options?: FindManyOptions<T>): Promise<number>;\n\n /**\n * Counts entities that match given conditions.\n */\n static count<T extends BaseEntity>(this: ObjectType<T>, conditions?: FindConditions<T>): Promise<number>;\n\n /**\n * Counts entities that match given find options or conditions.\n */\n static count<T extends BaseEntity>(this: ObjectType<T>, optionsOrConditions?: FindManyOptions<T>|FindConditions<T>): Promise<number> {\n return (this as any).getRepository().count(optionsOrConditions as any);\n }\n\n /**\n * Finds entities that match given options.\n */\n static find<T extends BaseEntity>(this: ObjectType<T>, options?: FindManyOptions<T>): Promise<T[]>;\n\n /**\n * Finds entities that match given conditions.\n */\n static find<T extends BaseEntity>(this: ObjectType<T>, conditions?: FindConditions<T>): Promise<T[]>;\n\n /**\n * Finds entities that match given find options or conditions.\n */\n static find<T extends BaseEntity>(this: ObjectType<T>, optionsOrConditions?: FindManyOptions<T>|FindConditions<T>): Promise<T[]> {\n return (this as any).getRepository().find(optionsOrConditions as any);\n }\n\n /**\n * Finds entities that match given find options.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n static findAndCount<T extends BaseEntity>(this: ObjectType<T>, options?: FindManyOptions<T>): Promise<[ T[], number ]>;\n\n /**\n * Finds entities that match given conditions.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n static findAndCount<T extends BaseEntity>(this: ObjectType<T>, conditions?: FindConditions<T>): Promise<[ T[], number ]>;\n\n /**\n * Finds entities that match given find options or conditions.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n static findAndCount<T extends BaseEntity>(this: ObjectType<T>, optionsOrConditions?: FindManyOptions<T>|FindConditions<T>): Promise<[ T[], number ]> {\n return (this as any).getRepository().findAndCount(optionsOrConditions as any);\n }\n\n /**\n * Finds entities by ids.\n * Optionally find options can be applied.\n */\n static findByIds<T extends BaseEntity>(this: ObjectType<T>, ids: any[], options?: FindManyOptions<T>): Promise<T[]>;\n\n /**\n * Finds entities by ids.\n * Optionally conditions can be applied.\n */\n static findByIds<T extends BaseEntity>(this: ObjectType<T>, ids: any[], conditions?: FindConditions<T>): Promise<T[]>;\n\n /**\n * Finds entities by ids.\n * Optionally find options can be applied.\n */\n static findByIds<T extends BaseEntity>(this: ObjectType<T>, ids: any[], optionsOrConditions?: FindManyOptions<T>|FindConditions<T>): Promise<T[]> {\n return (this as any).getRepository().findByIds(ids, optionsOrConditions as any);\n }\n\n /**\n * Finds first entity that matches given options.\n */\n static findOne<T extends BaseEntity>(this: ObjectType<T>, id?: string|number|Date|ObjectID, options?: FindOneOptions<T>): Promise<T|undefined>;\n\n /**\n * Finds first entity that matches given options.\n */\n static findOne<T extends BaseEntity>(this: ObjectType<T>, options?: FindOneOptions<T>): Promise<T|undefined>;\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOne<T extends BaseEntity>(this: ObjectType<T>, conditions?: FindConditions<T>, options?: FindOneOptions<T>): Promise<T|undefined>;\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOne<T extends BaseEntity>(this: ObjectType<T>, optionsOrConditions?: string|number|Date|ObjectID|FindOneOptions<T>|FindConditions<T>, maybeOptions?: FindOneOptions<T>): Promise<T|undefined> {\n return (this as any).getRepository().findOne(optionsOrConditions as any, maybeOptions);\n }\n\n /**\n * Finds first entity that matches given options.\n */\n static findOneOrFail<T extends BaseEntity>(this: ObjectType<T>, id?: string|number|Date|ObjectID, options?: FindOneOptions<T>): Promise<T>;\n\n /**\n * Finds first entity that matches given options.\n */\n static findOneOrFail<T extends BaseEntity>(this: ObjectType<T>, options?: FindOneOptions<T>): Promise<T>;\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneOrFail<T extends BaseEntity>(this: ObjectType<T>, conditions?: FindConditions<T>, options?: FindOneOptions<T>): Promise<T>;\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneOrFail<T extends BaseEntity>(this: ObjectType<T>, optionsOrConditions?: string|number|Date|ObjectID|FindOneOptions<T>|FindConditions<T>, maybeOptions?: FindOneOptions<T>): Promise<T> {\n return (this as any).getRepository().findOneOrFail(optionsOrConditions as any, maybeOptions);\n }\n\n /**\n * Executes a raw SQL query and returns a raw database results.\n * Raw query execution is supported only by relational databases (MongoDB is not supported).\n */\n static query<T extends BaseEntity>(this: ObjectType<T>, query: string, parameters?: any[]): Promise<any> {\n return (this as any).getRepository().query(query, parameters);\n }\n\n /**\n * Clears all the data from the given table/collection (truncates/drops it).\n */\n static clear<T extends BaseEntity>(this: ObjectType<T>, ): Promise<void> {\n return (this as any).getRepository().clear();\n }\n\n}\n"],"sourceRoot":".."}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../browser/src/repository/FindTreesOptions.ts"],"names":[],"mappings":"","file":"FindTreesOptions.js","sourcesContent":["/**\n * Special options passed to TreeRepository#findTrees\n */\nexport interface FindTreesOptions {\n\n /**\n * When loading a tree from a TreeRepository, limits the depth of the descendents loaded\n */\n depth?: number;\n\n}\n"],"sourceRoot":".."}
|
|
@@ -14,6 +14,7 @@ import { InsertResult } from "../query-builder/result/InsertResult";
|
|
|
14
14
|
import { QueryDeepPartialEntity } from "../query-builder/QueryPartialEntity";
|
|
15
15
|
import { ObjectID } from "../driver/mongodb/typings";
|
|
16
16
|
import { FindConditions } from "../find-options/FindConditions";
|
|
17
|
+
import { UpsertOptions } from "./UpsertOptions";
|
|
17
18
|
/**
|
|
18
19
|
* Repository is supposed to work with your entity objects. Find entities, insert, update, delete, etc.
|
|
19
20
|
*/
|
|
@@ -163,6 +164,12 @@ export declare class Repository<Entity extends ObjectLiteral> {
|
|
|
163
164
|
* Does not check if entity exist in the database.
|
|
164
165
|
*/
|
|
165
166
|
update(criteria: string | string[] | number | number[] | Date | Date[] | ObjectID | ObjectID[] | FindConditions<Entity>, partialEntity: QueryDeepPartialEntity<Entity>): Promise<UpdateResult>;
|
|
167
|
+
/**
|
|
168
|
+
* Inserts a given entity into the database, unless a unique constraint conflicts then updates the entity
|
|
169
|
+
* Unlike save method executes a primitive operation without cascades, relations and other operations included.
|
|
170
|
+
* Executes fast and efficient INSERT ... ON CONFLICT DO UPDATE/ON DUPLICATE KEY UPDATE query.
|
|
171
|
+
*/
|
|
172
|
+
upsert(entityOrEntities: QueryDeepPartialEntity<Entity> | (QueryDeepPartialEntity<Entity>[]), conflictPathsOrOptions: string[] | UpsertOptions<Entity>): Promise<InsertResult>;
|
|
166
173
|
/**
|
|
167
174
|
* Deletes entities by a given criteria.
|
|
168
175
|
* Unlike save method executes a primitive operation without cascades, relations and other operations included.
|
|
@@ -111,6 +111,14 @@ var Repository = /** @class */ (function () {
|
|
|
111
111
|
Repository.prototype.update = function (criteria, partialEntity) {
|
|
112
112
|
return this.manager.update(this.metadata.target, criteria, partialEntity);
|
|
113
113
|
};
|
|
114
|
+
/**
|
|
115
|
+
* Inserts a given entity into the database, unless a unique constraint conflicts then updates the entity
|
|
116
|
+
* Unlike save method executes a primitive operation without cascades, relations and other operations included.
|
|
117
|
+
* Executes fast and efficient INSERT ... ON CONFLICT DO UPDATE/ON DUPLICATE KEY UPDATE query.
|
|
118
|
+
*/
|
|
119
|
+
Repository.prototype.upsert = function (entityOrEntities, conflictPathsOrOptions) {
|
|
120
|
+
return this.manager.upsert(this.metadata.target, entityOrEntities, conflictPathsOrOptions);
|
|
121
|
+
};
|
|
114
122
|
/**
|
|
115
123
|
* Deletes entities by a given criteria.
|
|
116
124
|
* Unlike save method executes a primitive operation without cascades, relations and other operations included.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/repository/Repository.ts"],"names":[],"mappings":";AAiBA;;GAEG;AACH;IAAA;IAsZA,CAAC;IAjYG,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,uCAAkB,GAAlB,UAAmB,KAAc,EAAE,WAAyB;QACxD,OAAO,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAS,IAAI,CAAC,QAAQ,CAAC,MAAa,EAAE,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,WAAW,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC;IACpJ,CAAC;IAOD,sBAAI,8BAAM;QALV;;;;WAIG;aACH;YACI,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QAChC,CAAC;;;OAAA;IAED;;;OAGG;IACH,0BAAK,GAAL,UAAM,MAAc;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5D,CAAC;IAED;;OAEG;IACH,0BAAK,GAAL,UAAM,MAAc;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5D,CAAC;IAmBD;;;OAGG;IACH,2BAAM,GAAN,UAAO,iCAA6E;QAChF,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAM,IAAI,CAAC,QAAQ,CAAC,MAAa,EAAE,iCAAwC,CAAC,CAAC;IAC3G,CAAC;IAED;;OAEG;IACH,0BAAK,GAAL,UAAM,eAAuB;;QAAE,qBAAqC;aAArC,UAAqC,EAArC,qBAAqC,EAArC,IAAqC;YAArC,oCAAqC;;QAChE,OAAO,CAAA,KAAA,IAAI,CAAC,OAAO,CAAA,CAAC,KAAK,0BAAC,IAAI,CAAC,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metadata/EntityMetadata\";\nimport {FindManyOptions} from \"../find-options/FindManyOptions\";\nimport {ObjectLiteral} from \"../common/ObjectLiteral\";\nimport {FindOneOptions} from \"../find-options/FindOneOptions\";\nimport {DeepPartial} from \"../common/DeepPartial\";\nimport {SaveOptions} from \"./SaveOptions\";\nimport {RemoveOptions} from \"./RemoveOptions\";\nimport {EntityManager} from \"../entity-manager/EntityManager\";\nimport {QueryRunner} from \"../query-runner/QueryRunner\";\nimport {SelectQueryBuilder} from \"../query-builder/SelectQueryBuilder\";\nimport {DeleteResult} from \"../query-builder/result/DeleteResult\";\nimport {UpdateResult} from \"../query-builder/result/UpdateResult\";\nimport {InsertResult} from \"../query-builder/result/InsertResult\";\nimport {QueryDeepPartialEntity} from \"../query-builder/QueryPartialEntity\";\nimport {ObjectID} from \"../driver/mongodb/typings\";\nimport {FindConditions} from \"../find-options/FindConditions\";\n\n/**\n * Repository is supposed to work with your entity objects. Find entities, insert, update, delete, etc.\n */\nexport class Repository<Entity extends ObjectLiteral> {\n\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Entity Manager used by this repository.\n */\n readonly manager: EntityManager;\n\n /**\n * Entity metadata of the entity current repository manages.\n */\n readonly metadata: EntityMetadata;\n\n /**\n * Query runner provider used for this repository.\n */\n readonly queryRunner?: QueryRunner;\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates a new query builder that can be used to build a sql query.\n */\n createQueryBuilder(alias?: string, queryRunner?: QueryRunner): SelectQueryBuilder<Entity> {\n return this.manager.createQueryBuilder<Entity>(this.metadata.target as any, alias || this.metadata.targetName, queryRunner || this.queryRunner);\n }\n\n /**\n * Returns object that is managed by this repository.\n * If this repository manages entity from schema,\n * then it returns a name of that schema instead.\n */\n get target(): Function|string {\n return this.metadata.target;\n }\n\n /**\n * Checks if entity has an id.\n * If entity composite compose ids, it will check them all.\n */\n hasId(entity: Entity): boolean {\n return this.manager.hasId(this.metadata.target, entity);\n }\n\n /**\n * Gets entity mixed id.\n */\n getId(entity: Entity): any {\n return this.manager.getId(this.metadata.target, entity);\n }\n\n /**\n * Creates a new entity instance.\n */\n create(): Entity;\n\n /**\n * Creates new entities and copies all entity properties from given objects into their new entities.\n * Note that it copies only properties that are present in entity schema.\n */\n create(entityLikeArray: DeepPartial<Entity>[]): Entity[];\n\n /**\n * Creates a new entity instance and copies all entity properties from this object into a new entity.\n * Note that it copies only properties that are present in entity schema.\n */\n create(entityLike: DeepPartial<Entity>): Entity;\n\n /**\n * Creates a new entity instance or instances.\n * Can copy properties from the given object into new entities.\n */\n create(plainEntityLikeOrPlainEntityLikes?: DeepPartial<Entity>|DeepPartial<Entity>[]): Entity|Entity[] {\n return this.manager.create<any>(this.metadata.target as any, plainEntityLikeOrPlainEntityLikes as any);\n }\n\n /**\n * Merges multiple entities (or entity-like objects) into a given entity.\n */\n merge(mergeIntoEntity: Entity, ...entityLikes: DeepPartial<Entity>[]): Entity {\n return this.manager.merge(this.metadata.target as any, mergeIntoEntity, ...entityLikes);\n }\n\n /**\n * Creates a new entity from the given plain javascript object. If entity already exist in the database, then\n * it loads it (and everything related to it), replaces all values with the new ones from the given object\n * and returns this new entity. This new entity is actually a loaded from the db entity with all properties\n * replaced from the new object.\n *\n * Note that given entity-like object must have an entity id / primary key to find entity by.\n * Returns undefined if entity with given id was not found.\n */\n preload(entityLike: DeepPartial<Entity>): Promise<Entity|undefined> {\n return this.manager.preload(this.metadata.target as any, entityLike);\n }\n\n /**\n * Saves all given entities in the database.\n * If entities do not exist in the database then inserts, otherwise updates.\n */\n save<T extends DeepPartial<Entity>>(entities: T[], options: SaveOptions & { reload: false }): Promise<T[]>;\n\n /**\n * Saves all given entities in the database.\n * If entities do not exist in the database then inserts, otherwise updates.\n */\n save<T extends DeepPartial<Entity>>(entities: T[], options?: SaveOptions): Promise<(T & Entity)[]>;\n\n /**\n * Saves a given entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n save<T extends DeepPartial<Entity>>(entity: T, options: SaveOptions & { reload: false }): Promise<T>;\n\n /**\n * Saves a given entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n save<T extends DeepPartial<Entity>>(entity: T, options?: SaveOptions): Promise<T & Entity>;\n\n /**\n * Saves one or many given entities.\n */\n save<T extends DeepPartial<Entity>>(entityOrEntities: T|T[], options?: SaveOptions): Promise<T|T[]> {\n return this.manager.save<Entity, T>(this.metadata.target as any, entityOrEntities as any, options);\n }\n\n /**\n * Removes a given entities from the database.\n */\n remove(entities: Entity[], options?: RemoveOptions): Promise<Entity[]>;\n\n /**\n * Removes a given entity from the database.\n */\n remove(entity: Entity, options?: RemoveOptions): Promise<Entity>;\n\n /**\n * Removes one or many given entities.\n */\n remove(entityOrEntities: Entity|Entity[], options?: RemoveOptions): Promise<Entity|Entity[]> {\n return this.manager.remove(this.metadata.target as any, entityOrEntities as any, options);\n }\n\n /**\n * Records the delete date of all given entities.\n */\n softRemove<T extends DeepPartial<Entity>>(entities: T[], options: SaveOptions & { reload: false }): Promise<T[]>;\n\n /**\n * Records the delete date of all given entities.\n */\n softRemove<T extends DeepPartial<Entity>>(entities: T[], options?: SaveOptions): Promise<(T & Entity)[]>;\n\n /**\n * Records the delete date of a given entity.\n */\n softRemove<T extends DeepPartial<Entity>>(entity: T, options: SaveOptions & { reload: false }): Promise<T>;\n\n /**\n * Records the delete date of a given entity.\n */\n softRemove<T extends DeepPartial<Entity>>(entity: T, options?: SaveOptions): Promise<T & Entity>;\n\n /**\n * Records the delete date of one or many given entities.\n */\n softRemove<T extends DeepPartial<Entity>>(entityOrEntities: T|T[], options?: SaveOptions): Promise<T|T[]> {\n return this.manager.softRemove<Entity, T>(this.metadata.target as any, entityOrEntities as any, options);\n }\n\n /**\n * Recovers all given entities in the database.\n */\n recover<T extends DeepPartial<Entity>>(entities: T[], options: SaveOptions & { reload: false }): Promise<T[]>;\n\n /**\n * Recovers all given entities in the database.\n */\n recover<T extends DeepPartial<Entity>>(entities: T[], options?: SaveOptions): Promise<(T & Entity)[]>;\n\n /**\n * Recovers a given entity in the database.\n */\n recover<T extends DeepPartial<Entity>>(entity: T, options: SaveOptions & { reload: false }): Promise<T>;\n\n /**\n * Recovers a given entity in the database.\n */\n recover<T extends DeepPartial<Entity>>(entity: T, options?: SaveOptions): Promise<T & Entity>;\n\n /**\n * Recovers one or many given entities.\n */\n recover<T extends DeepPartial<Entity>>(entityOrEntities: T|T[], options?: SaveOptions): Promise<T|T[]> {\n return this.manager.recover<Entity, T>(this.metadata.target as any, entityOrEntities as any, options);\n }\n\n /**\n * Inserts a given entity into the database.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient INSERT query.\n * Does not check if entity exist in the database, so query will fail if duplicate entity is being inserted.\n */\n insert(entity: QueryDeepPartialEntity<Entity>|(QueryDeepPartialEntity<Entity>[])): Promise<InsertResult> {\n return this.manager.insert(this.metadata.target as any, entity);\n }\n\n /**\n * Updates entity partially. Entity can be found by a given conditions.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient UPDATE query.\n * Does not check if entity exist in the database.\n */\n update(criteria: string|string[]|number|number[]|Date|Date[]|ObjectID|ObjectID[]|FindConditions<Entity>, partialEntity: QueryDeepPartialEntity<Entity>): Promise<UpdateResult> {\n return this.manager.update(this.metadata.target as any, criteria as any, partialEntity);\n }\n\n /**\n * Deletes entities by a given criteria.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient DELETE query.\n * Does not check if entity exist in the database.\n */\n delete(criteria: string|string[]|number|number[]|Date|Date[]|ObjectID|ObjectID[]|FindConditions<Entity>): Promise<DeleteResult> {\n return this.manager.delete(this.metadata.target as any, criteria as any);\n }\n\n /**\n * Records the delete date of entities by a given criteria.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient SOFT-DELETE query.\n * Does not check if entity exist in the database.\n */\n softDelete(criteria: string|string[]|number|number[]|Date|Date[]|ObjectID|ObjectID[]|FindConditions<Entity>): Promise<UpdateResult> {\n return this.manager.softDelete(this.metadata.target as any, criteria as any);\n }\n\n /**\n * Restores entities by a given criteria.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient SOFT-DELETE query.\n * Does not check if entity exist in the database.\n */\n restore(criteria: string|string[]|number|number[]|Date|Date[]|ObjectID|ObjectID[]|FindConditions<Entity>): Promise<UpdateResult> {\n return this.manager.restore(this.metadata.target as any, criteria as any);\n }\n\n /**\n * Counts entities that match given options.\n */\n count(options?: FindManyOptions<Entity>): Promise<number>;\n\n /**\n * Counts entities that match given conditions.\n */\n count(conditions?: FindConditions<Entity>): Promise<number>;\n\n /**\n * Counts entities that match given find options or conditions.\n */\n count(optionsOrConditions?: FindManyOptions<Entity>|FindConditions<Entity>): Promise<number> {\n return this.manager.count(this.metadata.target as any, optionsOrConditions as any);\n }\n\n /**\n * Finds entities that match given options.\n */\n find(options?: FindManyOptions<Entity>): Promise<Entity[]>;\n\n /**\n * Finds entities that match given conditions.\n */\n find(conditions?: FindConditions<Entity>): Promise<Entity[]>;\n\n /**\n * Finds entities that match given find options or conditions.\n */\n find(optionsOrConditions?: FindManyOptions<Entity>|FindConditions<Entity>): Promise<Entity[]> {\n return this.manager.find(this.metadata.target as any, optionsOrConditions as any);\n }\n\n /**\n * Finds entities that match given find options.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n findAndCount(options?: FindManyOptions<Entity>): Promise<[ Entity[], number ]>;\n\n /**\n * Finds entities that match given conditions.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n findAndCount(conditions?: FindConditions<Entity>): Promise<[ Entity[], number ]>;\n\n /**\n * Finds entities that match given find options or conditions.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n findAndCount(optionsOrConditions?: FindManyOptions<Entity>|FindConditions<Entity>): Promise<[ Entity[], number ]> {\n return this.manager.findAndCount(this.metadata.target as any, optionsOrConditions as any);\n }\n\n /**\n * Finds entities by ids.\n * Optionally find options can be applied.\n */\n findByIds(ids: any[], options?: FindManyOptions<Entity>): Promise<Entity[]>;\n\n /**\n * Finds entities by ids.\n * Optionally conditions can be applied.\n */\n findByIds(ids: any[], conditions?: FindConditions<Entity>): Promise<Entity[]>;\n\n /**\n * Finds entities by ids.\n * Optionally find options can be applied.\n */\n findByIds(ids: any[], optionsOrConditions?: FindManyOptions<Entity>|FindConditions<Entity>): Promise<Entity[]> {\n return this.manager.findByIds(this.metadata.target as any, ids, optionsOrConditions as any);\n }\n\n /**\n * Finds first entity that matches given options.\n */\n findOne(id?: string|number|Date|ObjectID, options?: FindOneOptions<Entity>): Promise<Entity|undefined>;\n\n /**\n * Finds first entity that matches given options.\n */\n findOne(options?: FindOneOptions<Entity>): Promise<Entity|undefined>;\n\n /**\n * Finds first entity that matches given conditions.\n */\n findOne(conditions?: FindConditions<Entity>, options?: FindOneOptions<Entity>): Promise<Entity|undefined>;\n\n /**\n * Finds first entity that matches given conditions.\n */\n findOne(optionsOrConditions?: string|number|Date|ObjectID|FindOneOptions<Entity>|FindConditions<Entity>, maybeOptions?: FindOneOptions<Entity>): Promise<Entity|undefined> {\n return this.manager.findOne(this.metadata.target as any, optionsOrConditions as any, maybeOptions);\n }\n\n /**\n * Finds first entity that matches given options.\n */\n findOneOrFail(id?: string|number|Date|ObjectID, options?: FindOneOptions<Entity>): Promise<Entity>;\n\n /**\n * Finds first entity that matches given options.\n */\n findOneOrFail(options?: FindOneOptions<Entity>): Promise<Entity>;\n\n /**\n * Finds first entity that matches given conditions.\n */\n findOneOrFail(conditions?: FindConditions<Entity>, options?: FindOneOptions<Entity>): Promise<Entity>;\n\n /**\n * Finds first entity that matches given conditions.\n */\n findOneOrFail(optionsOrConditions?: string|number|Date|ObjectID|FindOneOptions<Entity>|FindConditions<Entity>, maybeOptions?: FindOneOptions<Entity>): Promise<Entity> {\n return this.manager.findOneOrFail(this.metadata.target as any, optionsOrConditions as any, maybeOptions);\n }\n\n /**\n * Executes a raw SQL query and returns a raw database results.\n * Raw query execution is supported only by relational databases (MongoDB is not supported).\n */\n query(query: string, parameters?: any[]): Promise<any> {\n return this.manager.query(query, parameters);\n }\n\n /**\n * Clears all the data from the given table/collection (truncates/drops it).\n *\n * Note: this method uses TRUNCATE and may not work as you expect in transactions on some platforms.\n * @see https://stackoverflow.com/a/5972738/925151\n */\n clear(): Promise<void> {\n return this.manager.clear(this.metadata.target);\n }\n\n /**\n * Increments some column by provided value of the entities matched given conditions.\n */\n increment(conditions: FindConditions<Entity>, propertyPath: string, value: number | string): Promise<UpdateResult> {\n return this.manager.increment(this.metadata.target, conditions, propertyPath, value);\n }\n\n /**\n * Decrements some column by provided value of the entities matched given conditions.\n */\n decrement(conditions: FindConditions<Entity>, propertyPath: string, value: number | string): Promise<UpdateResult> {\n return this.manager.decrement(this.metadata.target, conditions, propertyPath, value);\n }\n\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/repository/Repository.ts"],"names":[],"mappings":";AAkBA;;GAEG;AACH;IAAA;IAiaA,CAAC;IA5YG,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,uCAAkB,GAAlB,UAAmB,KAAc,EAAE,WAAyB;QACxD,OAAO,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAS,IAAI,CAAC,QAAQ,CAAC,MAAa,EAAE,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,WAAW,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC;IACpJ,CAAC;IAOD,sBAAI,8BAAM;QALV;;;;WAIG;aACH;YACI,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QAChC,CAAC;;;OAAA;IAED;;;OAGG;IACH,0BAAK,GAAL,UAAM,MAAc;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE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AAM,KAAa,EAAE,UAAkB;QACnC,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IACjD,CAAC;IAED;;;;;OAKG;IACH,0BAAK,GAAL;QACI,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACpD,CAAC;IAED;;OAEG;IACH,8BAAS,GAAT,UAAU,UAAkC,EAAE,YAAoB,EAAE,KAAsB;QACtF,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;IACzF,CAAC;IAED;;OAEG;IACH,8BAAS,GAAT,UAAU,UAAkC,EAAE,YAAoB,EAAE,KAAsB;QACtF,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;IACzF,CAAC;IAEL,iBAAC;AAAD,CAjaA,AAiaC,IAAA","file":"Repository.js","sourcesContent":["import {EntityMetadata} from \"../metadata/EntityMetadata\";\nimport {FindManyOptions} from \"../find-options/FindManyOptions\";\nimport {ObjectLiteral} from \"../common/ObjectLiteral\";\nimport {FindOneOptions} from \"../find-options/FindOneOptions\";\nimport {DeepPartial} from \"../common/DeepPartial\";\nimport {SaveOptions} from \"./SaveOptions\";\nimport {RemoveOptions} from \"./RemoveOptions\";\nimport {EntityManager} from \"../entity-manager/EntityManager\";\nimport {QueryRunner} from \"../query-runner/QueryRunner\";\nimport {SelectQueryBuilder} from \"../query-builder/SelectQueryBuilder\";\nimport {DeleteResult} from \"../query-builder/result/DeleteResult\";\nimport {UpdateResult} from \"../query-builder/result/UpdateResult\";\nimport {InsertResult} from \"../query-builder/result/InsertResult\";\nimport {QueryDeepPartialEntity} from \"../query-builder/QueryPartialEntity\";\nimport {ObjectID} from \"../driver/mongodb/typings\";\nimport {FindConditions} from \"../find-options/FindConditions\";\nimport {UpsertOptions} from \"./UpsertOptions\";\n\n/**\n * Repository is supposed to work with your entity objects. Find entities, insert, update, delete, etc.\n */\nexport class Repository<Entity extends ObjectLiteral> {\n\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Entity Manager used by this repository.\n */\n readonly manager: EntityManager;\n\n /**\n * Entity metadata of the entity current repository manages.\n */\n readonly metadata: EntityMetadata;\n\n /**\n * Query runner provider used for this repository.\n */\n readonly queryRunner?: QueryRunner;\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates a new query builder that can be used to build a sql query.\n */\n createQueryBuilder(alias?: string, queryRunner?: QueryRunner): SelectQueryBuilder<Entity> {\n return this.manager.createQueryBuilder<Entity>(this.metadata.target as any, alias || this.metadata.targetName, queryRunner || this.queryRunner);\n }\n\n /**\n * Returns object that is managed by this repository.\n * If this repository manages entity from schema,\n * then it returns a name of that schema instead.\n */\n get target(): Function|string {\n return this.metadata.target;\n }\n\n /**\n * Checks if entity has an id.\n * If entity composite compose ids, it will check them all.\n */\n hasId(entity: Entity): boolean {\n return this.manager.hasId(this.metadata.target, entity);\n }\n\n /**\n * Gets entity mixed id.\n */\n getId(entity: Entity): any {\n return this.manager.getId(this.metadata.target, entity);\n }\n\n /**\n * Creates a new entity instance.\n */\n create(): Entity;\n\n /**\n * Creates new entities and copies all entity properties from given objects into their new entities.\n * Note that it copies only properties that are present in entity schema.\n */\n create(entityLikeArray: DeepPartial<Entity>[]): Entity[];\n\n /**\n * Creates a new entity instance and copies all entity properties from this object into a new entity.\n * Note that it copies only properties that are present in entity schema.\n */\n create(entityLike: DeepPartial<Entity>): Entity;\n\n /**\n * Creates a new entity instance or instances.\n * Can copy properties from the given object into new entities.\n */\n create(plainEntityLikeOrPlainEntityLikes?: DeepPartial<Entity>|DeepPartial<Entity>[]): Entity|Entity[] {\n return this.manager.create<any>(this.metadata.target as any, plainEntityLikeOrPlainEntityLikes as any);\n }\n\n /**\n * Merges multiple entities (or entity-like objects) into a given entity.\n */\n merge(mergeIntoEntity: Entity, ...entityLikes: DeepPartial<Entity>[]): Entity {\n return this.manager.merge(this.metadata.target as any, mergeIntoEntity, ...entityLikes);\n }\n\n /**\n * Creates a new entity from the given plain javascript object. If entity already exist in the database, then\n * it loads it (and everything related to it), replaces all values with the new ones from the given object\n * and returns this new entity. This new entity is actually a loaded from the db entity with all properties\n * replaced from the new object.\n *\n * Note that given entity-like object must have an entity id / primary key to find entity by.\n * Returns undefined if entity with given id was not found.\n */\n preload(entityLike: DeepPartial<Entity>): Promise<Entity|undefined> {\n return this.manager.preload(this.metadata.target as any, entityLike);\n }\n\n /**\n * Saves all given entities in the database.\n * If entities do not exist in the database then inserts, otherwise updates.\n */\n save<T extends DeepPartial<Entity>>(entities: T[], options: SaveOptions & { reload: false }): Promise<T[]>;\n\n /**\n * Saves all given entities in the database.\n * If entities do not exist in the database then inserts, otherwise updates.\n */\n save<T extends DeepPartial<Entity>>(entities: T[], options?: SaveOptions): Promise<(T & Entity)[]>;\n\n /**\n * Saves a given entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n save<T extends DeepPartial<Entity>>(entity: T, options: SaveOptions & { reload: false }): Promise<T>;\n\n /**\n * Saves a given entity in the database.\n * If entity does not exist in the database then inserts, otherwise updates.\n */\n save<T extends DeepPartial<Entity>>(entity: T, options?: SaveOptions): Promise<T & Entity>;\n\n /**\n * Saves one or many given entities.\n */\n save<T extends DeepPartial<Entity>>(entityOrEntities: T|T[], options?: SaveOptions): Promise<T|T[]> {\n return this.manager.save<Entity, T>(this.metadata.target as any, entityOrEntities as any, options);\n }\n\n /**\n * Removes a given entities from the database.\n */\n remove(entities: Entity[], options?: RemoveOptions): Promise<Entity[]>;\n\n /**\n * Removes a given entity from the database.\n */\n remove(entity: Entity, options?: RemoveOptions): Promise<Entity>;\n\n /**\n * Removes one or many given entities.\n */\n remove(entityOrEntities: Entity|Entity[], options?: RemoveOptions): Promise<Entity|Entity[]> {\n return this.manager.remove(this.metadata.target as any, entityOrEntities as any, options);\n }\n\n /**\n * Records the delete date of all given entities.\n */\n softRemove<T extends DeepPartial<Entity>>(entities: T[], options: SaveOptions & { reload: false }): Promise<T[]>;\n\n /**\n * Records the delete date of all given entities.\n */\n softRemove<T extends DeepPartial<Entity>>(entities: T[], options?: SaveOptions): Promise<(T & Entity)[]>;\n\n /**\n * Records the delete date of a given entity.\n */\n softRemove<T extends DeepPartial<Entity>>(entity: T, options: SaveOptions & { reload: false }): Promise<T>;\n\n /**\n * Records the delete date of a given entity.\n */\n softRemove<T extends DeepPartial<Entity>>(entity: T, options?: SaveOptions): Promise<T & Entity>;\n\n /**\n * Records the delete date of one or many given entities.\n */\n softRemove<T extends DeepPartial<Entity>>(entityOrEntities: T|T[], options?: SaveOptions): Promise<T|T[]> {\n return this.manager.softRemove<Entity, T>(this.metadata.target as any, entityOrEntities as any, options);\n }\n\n /**\n * Recovers all given entities in the database.\n */\n recover<T extends DeepPartial<Entity>>(entities: T[], options: SaveOptions & { reload: false }): Promise<T[]>;\n\n /**\n * Recovers all given entities in the database.\n */\n recover<T extends DeepPartial<Entity>>(entities: T[], options?: SaveOptions): Promise<(T & Entity)[]>;\n\n /**\n * Recovers a given entity in the database.\n */\n recover<T extends DeepPartial<Entity>>(entity: T, options: SaveOptions & { reload: false }): Promise<T>;\n\n /**\n * Recovers a given entity in the database.\n */\n recover<T extends DeepPartial<Entity>>(entity: T, options?: SaveOptions): Promise<T & Entity>;\n\n /**\n * Recovers one or many given entities.\n */\n recover<T extends DeepPartial<Entity>>(entityOrEntities: T|T[], options?: SaveOptions): Promise<T|T[]> {\n return this.manager.recover<Entity, T>(this.metadata.target as any, entityOrEntities as any, options);\n }\n\n /**\n * Inserts a given entity into the database.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient INSERT query.\n * Does not check if entity exist in the database, so query will fail if duplicate entity is being inserted.\n */\n insert(entity: QueryDeepPartialEntity<Entity>|(QueryDeepPartialEntity<Entity>[])): Promise<InsertResult> {\n return this.manager.insert(this.metadata.target as any, entity);\n }\n\n /**\n * Updates entity partially. Entity can be found by a given conditions.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient UPDATE query.\n * Does not check if entity exist in the database.\n */\n update(criteria: string|string[]|number|number[]|Date|Date[]|ObjectID|ObjectID[]|FindConditions<Entity>, partialEntity: QueryDeepPartialEntity<Entity>): Promise<UpdateResult> {\n return this.manager.update(this.metadata.target as any, criteria as any, partialEntity);\n }\n\n /**\n * Inserts a given entity into the database, unless a unique constraint conflicts then updates the entity\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient INSERT ... ON CONFLICT DO UPDATE/ON DUPLICATE KEY UPDATE query.\n */\n upsert(\n entityOrEntities: QueryDeepPartialEntity<Entity> | (QueryDeepPartialEntity<Entity>[]),\n conflictPathsOrOptions: string[] | UpsertOptions<Entity>): Promise<InsertResult> {\n return this.manager.upsert(this.metadata.target as any, entityOrEntities, conflictPathsOrOptions);\n }\n\n /**\n * Deletes entities by a given criteria.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient DELETE query.\n * Does not check if entity exist in the database.\n */\n delete(criteria: string|string[]|number|number[]|Date|Date[]|ObjectID|ObjectID[]|FindConditions<Entity>): Promise<DeleteResult> {\n return this.manager.delete(this.metadata.target as any, criteria as any);\n }\n\n /**\n * Records the delete date of entities by a given criteria.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient SOFT-DELETE query.\n * Does not check if entity exist in the database.\n */\n softDelete(criteria: string|string[]|number|number[]|Date|Date[]|ObjectID|ObjectID[]|FindConditions<Entity>): Promise<UpdateResult> {\n return this.manager.softDelete(this.metadata.target as any, criteria as any);\n }\n\n /**\n * Restores entities by a given criteria.\n * Unlike save method executes a primitive operation without cascades, relations and other operations included.\n * Executes fast and efficient SOFT-DELETE query.\n * Does not check if entity exist in the database.\n */\n restore(criteria: string|string[]|number|number[]|Date|Date[]|ObjectID|ObjectID[]|FindConditions<Entity>): Promise<UpdateResult> {\n return this.manager.restore(this.metadata.target as any, criteria as any);\n }\n\n /**\n * Counts entities that match given options.\n */\n count(options?: FindManyOptions<Entity>): Promise<number>;\n\n /**\n * Counts entities that match given conditions.\n */\n count(conditions?: FindConditions<Entity>): Promise<number>;\n\n /**\n * Counts entities that match given find options or conditions.\n */\n count(optionsOrConditions?: FindManyOptions<Entity>|FindConditions<Entity>): Promise<number> {\n return this.manager.count(this.metadata.target as any, optionsOrConditions as any);\n }\n\n /**\n * Finds entities that match given options.\n */\n find(options?: FindManyOptions<Entity>): Promise<Entity[]>;\n\n /**\n * Finds entities that match given conditions.\n */\n find(conditions?: FindConditions<Entity>): Promise<Entity[]>;\n\n /**\n * Finds entities that match given find options or conditions.\n */\n find(optionsOrConditions?: FindManyOptions<Entity>|FindConditions<Entity>): Promise<Entity[]> {\n return this.manager.find(this.metadata.target as any, optionsOrConditions as any);\n }\n\n /**\n * Finds entities that match given find options.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n findAndCount(options?: FindManyOptions<Entity>): Promise<[ Entity[], number ]>;\n\n /**\n * Finds entities that match given conditions.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n findAndCount(conditions?: FindConditions<Entity>): Promise<[ Entity[], number ]>;\n\n /**\n * Finds entities that match given find options or conditions.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n findAndCount(optionsOrConditions?: FindManyOptions<Entity>|FindConditions<Entity>): Promise<[ Entity[], number ]> {\n return this.manager.findAndCount(this.metadata.target as any, optionsOrConditions as any);\n }\n\n /**\n * Finds entities by ids.\n * Optionally find options can be applied.\n */\n findByIds(ids: any[], options?: FindManyOptions<Entity>): Promise<Entity[]>;\n\n /**\n * Finds entities by ids.\n * Optionally conditions can be applied.\n */\n findByIds(ids: any[], conditions?: FindConditions<Entity>): Promise<Entity[]>;\n\n /**\n * Finds entities by ids.\n * Optionally find options can be applied.\n */\n findByIds(ids: any[], optionsOrConditions?: FindManyOptions<Entity>|FindConditions<Entity>): Promise<Entity[]> {\n return this.manager.findByIds(this.metadata.target as any, ids, optionsOrConditions as any);\n }\n\n /**\n * Finds first entity that matches given options.\n */\n findOne(id?: string|number|Date|ObjectID, options?: FindOneOptions<Entity>): Promise<Entity|undefined>;\n\n /**\n * Finds first entity that matches given options.\n */\n findOne(options?: FindOneOptions<Entity>): Promise<Entity|undefined>;\n\n /**\n * Finds first entity that matches given conditions.\n */\n findOne(conditions?: FindConditions<Entity>, options?: FindOneOptions<Entity>): Promise<Entity|undefined>;\n\n /**\n * Finds first entity that matches given conditions.\n */\n findOne(optionsOrConditions?: string|number|Date|ObjectID|FindOneOptions<Entity>|FindConditions<Entity>, maybeOptions?: FindOneOptions<Entity>): Promise<Entity|undefined> {\n return this.manager.findOne(this.metadata.target as any, optionsOrConditions as any, maybeOptions);\n }\n\n /**\n * Finds first entity that matches given options.\n */\n findOneOrFail(id?: string|number|Date|ObjectID, options?: FindOneOptions<Entity>): Promise<Entity>;\n\n /**\n * Finds first entity that matches given options.\n */\n findOneOrFail(options?: FindOneOptions<Entity>): Promise<Entity>;\n\n /**\n * Finds first entity that matches given conditions.\n */\n findOneOrFail(conditions?: FindConditions<Entity>, options?: FindOneOptions<Entity>): Promise<Entity>;\n\n /**\n * Finds first entity that matches given conditions.\n */\n findOneOrFail(optionsOrConditions?: string|number|Date|ObjectID|FindOneOptions<Entity>|FindConditions<Entity>, maybeOptions?: FindOneOptions<Entity>): Promise<Entity> {\n return this.manager.findOneOrFail(this.metadata.target as any, optionsOrConditions as any, maybeOptions);\n }\n\n /**\n * Executes a raw SQL query and returns a raw database results.\n * Raw query execution is supported only by relational databases (MongoDB is not supported).\n */\n query(query: string, parameters?: any[]): Promise<any> {\n return this.manager.query(query, parameters);\n }\n\n /**\n * Clears all the data from the given table/collection (truncates/drops it).\n *\n * Note: this method uses TRUNCATE and may not work as you expect in transactions on some platforms.\n * @see https://stackoverflow.com/a/5972738/925151\n */\n clear(): Promise<void> {\n return this.manager.clear(this.metadata.target);\n }\n\n /**\n * Increments some column by provided value of the entities matched given conditions.\n */\n increment(conditions: FindConditions<Entity>, propertyPath: string, value: number | string): Promise<UpdateResult> {\n return this.manager.increment(this.metadata.target, conditions, propertyPath, value);\n }\n\n /**\n * Decrements some column by provided value of the entities matched given conditions.\n */\n decrement(conditions: FindConditions<Entity>, propertyPath: string, value: number | string): Promise<UpdateResult> {\n return this.manager.decrement(this.metadata.target, conditions, propertyPath, value);\n }\n\n}\n"],"sourceRoot":".."}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Repository } from "./Repository";
|
|
2
2
|
import { SelectQueryBuilder } from "../query-builder/SelectQueryBuilder";
|
|
3
3
|
import { FindTreeOptions } from "../find-options/FindTreeOptions";
|
|
4
|
+
import { FindTreesOptions } from "./FindTreesOptions";
|
|
4
5
|
/**
|
|
5
6
|
* Repository with additional functions to work with trees.
|
|
6
7
|
*
|
|
@@ -60,7 +61,9 @@ export declare class TreeRepository<Entity> extends Repository<Entity> {
|
|
|
60
61
|
protected buildChildrenEntityTree(entity: any, entities: any[], relationMaps: {
|
|
61
62
|
id: any;
|
|
62
63
|
parentId: any;
|
|
63
|
-
}[]
|
|
64
|
+
}[], options: (FindTreesOptions & {
|
|
65
|
+
depth: number;
|
|
66
|
+
})): void;
|
|
64
67
|
protected buildParentEntityTree(entity: any, entities: any[], relationMaps: {
|
|
65
68
|
id: any;
|
|
66
69
|
parentId: any;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __awaiter, __extends, __generator } from "tslib";
|
|
1
|
+
import { __assign, __awaiter, __extends, __generator } from "tslib";
|
|
2
2
|
import { Repository } from "./Repository";
|
|
3
3
|
import { AbstractSqliteDriver } from "../driver/sqlite-abstract/AbstractSqliteDriver";
|
|
4
4
|
import { TypeORMError } from "../error/TypeORMError";
|
|
@@ -73,7 +73,7 @@ var TreeRepository = /** @class */ (function (_super) {
|
|
|
73
73
|
case 1:
|
|
74
74
|
entities = _a.sent();
|
|
75
75
|
relationMaps = this.createRelationMaps("treeEntity", entities.raw);
|
|
76
|
-
this.buildChildrenEntityTree(entity, entities.entities, relationMaps);
|
|
76
|
+
this.buildChildrenEntityTree(entity, entities.entities, relationMaps, __assign({ depth: -1 }, options));
|
|
77
77
|
return [2 /*return*/, entity];
|
|
78
78
|
}
|
|
79
79
|
});
|
|
@@ -256,15 +256,19 @@ var TreeRepository = /** @class */ (function (_super) {
|
|
|
256
256
|
};
|
|
257
257
|
});
|
|
258
258
|
};
|
|
259
|
-
TreeRepository.prototype.buildChildrenEntityTree = function (entity, entities, relationMaps) {
|
|
259
|
+
TreeRepository.prototype.buildChildrenEntityTree = function (entity, entities, relationMaps, options) {
|
|
260
260
|
var _this = this;
|
|
261
261
|
var childProperty = this.metadata.treeChildrenRelation.propertyName;
|
|
262
|
+
if (options.depth === 0) {
|
|
263
|
+
entity[childProperty] = [];
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
262
266
|
var parentEntityId = this.metadata.primaryColumns[0].getEntityValue(entity);
|
|
263
267
|
var childRelationMaps = relationMaps.filter(function (relationMap) { return relationMap.parentId === parentEntityId; });
|
|
264
268
|
var childIds = new Set(childRelationMaps.map(function (relationMap) { return relationMap.id; }));
|
|
265
269
|
entity[childProperty] = entities.filter(function (entity) { return childIds.has(_this.metadata.primaryColumns[0].getEntityValue(entity)); });
|
|
266
270
|
entity[childProperty].forEach(function (childEntity) {
|
|
267
|
-
_this.buildChildrenEntityTree(childEntity, entities, relationMaps);
|
|
271
|
+
_this.buildChildrenEntityTree(childEntity, entities, relationMaps, __assign(__assign({}, options), { depth: options.depth - 1 }));
|
|
268
272
|
});
|
|
269
273
|
};
|
|
270
274
|
TreeRepository.prototype.buildParentEntityTree = function (entity, entities, rel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,CAAC,GAAG,YAAY,CAAC;YACtC,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC;SAC9E;IACL,CAAC;IAEL,qBAAC;AAAD,CArRA,AAqRC,CArR2C,UAAU,GAqRrD","file":"TreeRepository.js","sourcesContent":["import {Repository} from \"./Repository\";\nimport {SelectQueryBuilder} from \"../query-builder/SelectQueryBuilder\";\nimport {ObjectLiteral} from \"../common/ObjectLiteral\";\nimport {AbstractSqliteDriver} from \"../driver/sqlite-abstract/AbstractSqliteDriver\";\nimport { TypeORMError } from \"../error/TypeORMError\";\nimport { FindTreeOptions } from \"../find-options/FindTreeOptions\";\nimport { FindOptionsUtils } from \"../find-options/FindOptionsUtils\";\n\n/**\n * Repository with additional functions to work with trees.\n *\n * @see Repository\n */\nexport class TreeRepository<Entity> extends Repository<Entity> {\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Gets complete trees for all roots in the table.\n */\n async findTrees(options?: FindTreeOptions): Promise<Entity[]> {\n const roots = await this.findRoots(options);\n await Promise.all(roots.map(root => this.findDescendantsTree(root, options)));\n return roots;\n }\n\n /**\n * Roots are entities that have no ancestors. Finds them all.\n */\n findRoots(options?: FindTreeOptions): Promise<Entity[]> {\n const escapeAlias = (alias: string) => this.manager.connection.driver.escape(alias);\n const escapeColumn = (column: string) => this.manager.connection.driver.escape(column);\n const parentPropertyName = this.manager.connection.namingStrategy.joinColumnName(\n this.metadata.treeParentRelation!.propertyName, this.metadata.primaryColumns[0].propertyName\n );\n\n const qb = this.createQueryBuilder(\"treeEntity\");\n FindOptionsUtils.applyOptionsToTreeQueryBuilder(qb, options);\n\n return qb\n .where(`${escapeAlias(\"treeEntity\")}.${escapeColumn(parentPropertyName)} IS NULL`)\n .getMany();\n }\n\n /**\n * Gets all children (descendants) of the given entity. Returns them all in a flat array.\n */\n findDescendants(entity: Entity, options?: FindTreeOptions): Promise<Entity[]> {\n const qb = this.createDescendantsQueryBuilder(\"treeEntity\", \"treeClosure\", entity);\n FindOptionsUtils.applyOptionsToTreeQueryBuilder(qb, options);\n return qb.getMany();\n }\n\n /**\n * Gets all children (descendants) of the given entity. Returns them in a tree - nested into each other.\n */\n async findDescendantsTree(entity: Entity, options?: FindTreeOptions): Promise<Entity> {\n // todo: throw exception if there is no column of this relation?\n\n const qb: SelectQueryBuilder<Entity> = this.createDescendantsQueryBuilder(\"treeEntity\", \"treeClosure\", entity);\n FindOptionsUtils.applyOptionsToTreeQueryBuilder(qb, options);\n\n const entities = await qb.getRawAndEntities();\n const relationMaps = this.createRelationMaps(\"treeEntity\", entities.raw);\n this.buildChildrenEntityTree(entity, entities.entities, relationMaps);\n\n return entity;\n }\n\n /**\n * Gets number of descendants of the entity.\n */\n countDescendants(entity: Entity): Promise<number> {\n return this\n .createDescendantsQueryBuilder(\"treeEntity\", \"treeClosure\", entity)\n .getCount();\n }\n\n /**\n * Creates a query builder used to get descendants of the entities in a tree.\n */\n createDescendantsQueryBuilder(alias: string, closureTableAlias: string, entity: Entity): SelectQueryBuilder<Entity> {\n\n // create shortcuts for better readability\n const escape = (alias: string) => this.manager.connection.driver.escape(alias);\n\n if (this.metadata.treeType === \"closure-table\") {\n\n const joinCondition = this.metadata.closureJunctionTable.descendantColumns.map(column => {\n return escape(closureTableAlias) + \".\" + escape(column.propertyPath) + \" = \" + escape(alias) + \".\" + escape(column.referencedColumn!.propertyPath);\n }).join(\" AND \");\n\n const parameters: ObjectLiteral = {};\n const whereCondition = this.metadata.closureJunctionTable.ancestorColumns.map(column => {\n parameters[column.referencedColumn!.propertyName] = column.referencedColumn!.getEntityValue(entity);\n return escape(closureTableAlias) + \".\" + escape(column.propertyPath) + \" = :\" + column.referencedColumn!.propertyName;\n }).join(\" AND \");\n\n return this\n .createQueryBuilder(alias)\n .innerJoin(this.metadata.closureJunctionTable.tableName, closureTableAlias, joinCondition)\n .where(whereCondition)\n .setParameters(parameters);\n\n } else if (this.metadata.treeType === \"nested-set\") {\n\n const whereCondition = alias + \".\" + this.metadata.nestedSetLeftColumn!.propertyPath + \" BETWEEN \" +\n \"joined.\" + this.metadata.nestedSetLeftColumn!.propertyPath + \" AND joined.\" + this.metadata.nestedSetRightColumn!.propertyPath;\n const parameters: ObjectLiteral = {};\n const joinCondition = this.metadata.treeParentRelation!.joinColumns.map(joinColumn => {\n const parameterName = joinColumn.referencedColumn!.propertyPath.replace(\".\", \"_\");\n parameters[parameterName] = joinColumn.referencedColumn!.getEntityValue(entity);\n return \"joined.\" + joinColumn.referencedColumn!.propertyPath + \" = :\" + parameterName;\n }).join(\" AND \");\n\n return this\n .createQueryBuilder(alias)\n .innerJoin(this.metadata.targetName, \"joined\", whereCondition)\n .where(joinCondition, parameters);\n\n } else if (this.metadata.treeType === \"materialized-path\") {\n return this\n .createQueryBuilder(alias)\n .where(qb => {\n const subQuery = qb.subQuery()\n .select(`${this.metadata.targetName}.${this.metadata.materializedPathColumn!.propertyPath}`, \"path\")\n .from(this.metadata.target, this.metadata.targetName)\n .whereInIds(this.metadata.getEntityIdMap(entity));\n\n if (this.manager.connection.driver instanceof AbstractSqliteDriver) {\n return `${alias}.${this.metadata.materializedPathColumn!.propertyPath} LIKE ${subQuery.getQuery()} || '%'`;\n } else {\n return `${alias}.${this.metadata.materializedPathColumn!.propertyPath} LIKE CONCAT(${subQuery.getQuery()}, '%')`;\n }\n });\n }\n\n throw new TypeORMError(`Supported only in tree entities`);\n }\n\n /**\n * Gets all parents (ancestors) of the given entity. Returns them all in a flat array.\n */\n findAncestors(entity: Entity, options?: FindTreeOptions): Promise<Entity[]> {\n const qb = this.createAncestorsQueryBuilder(\"treeEntity\", \"treeClosure\", entity);\n FindOptionsUtils.applyOptionsToTreeQueryBuilder(qb, options);\n return qb.getMany();\n }\n\n /**\n * Gets all parents (ancestors) of the given entity. Returns them in a tree - nested into each other.\n */\n async findAncestorsTree(entity: Entity, options?: FindTreeOptions): Promise<Entity> {\n // todo: throw exception if there is no column of this relation?\n const qb = this.createAncestorsQueryBuilder(\"treeEntity\", \"treeClosure\", entity);\n FindOptionsUtils.applyOptionsToTreeQueryBuilder(qb, options);\n\n const entities = await qb.getRawAndEntities();\n const relationMaps = this.createRelationMaps(\"treeEntity\", entities.raw);\n this.buildParentEntityTree(entity, entities.entities, relationMaps);\n return entity;\n }\n\n /**\n * Gets number of ancestors of the entity.\n */\n countAncestors(entity: Entity): Promise<number> {\n return this\n .createAncestorsQueryBuilder(\"treeEntity\", \"treeClosure\", entity)\n .getCount();\n }\n\n /**\n * Creates a query builder used to get ancestors of the entities in the tree.\n */\n createAncestorsQueryBuilder(alias: string, closureTableAlias: string, entity: Entity): SelectQueryBuilder<Entity> {\n\n // create shortcuts for better readability\n // const escape = (alias: string) => this.manager.connection.driver.escape(alias);\n\n if (this.metadata.treeType === \"closure-table\") {\n const joinCondition = this.metadata.closureJunctionTable.ancestorColumns.map(column => {\n return closureTableAlias + \".\" + column.propertyPath + \" = \" + alias + \".\" + column.referencedColumn!.propertyPath;\n }).join(\" AND \");\n\n const parameters: ObjectLiteral = {};\n const whereCondition = this.metadata.closureJunctionTable.descendantColumns.map(column => {\n parameters[column.referencedColumn!.propertyName] = column.referencedColumn!.getEntityValue(entity);\n return closureTableAlias + \".\" + column.propertyPath + \" = :\" + column.referencedColumn!.propertyName;\n }).join(\" AND \");\n\n return this\n .createQueryBuilder(alias)\n .innerJoin(this.metadata.closureJunctionTable.tableName, closureTableAlias, joinCondition)\n .where(whereCondition)\n .setParameters(parameters);\n\n } else if (this.metadata.treeType === \"nested-set\") {\n\n const joinCondition = \"joined.\" + this.metadata.nestedSetLeftColumn!.propertyPath + \" BETWEEN \" +\n alias + \".\" + this.metadata.nestedSetLeftColumn!.propertyPath + \" AND \" + alias + \".\" + this.metadata.nestedSetRightColumn!.propertyPath;\n const parameters: ObjectLiteral = {};\n const whereCondition = this.metadata.treeParentRelation!.joinColumns.map(joinColumn => {\n const parameterName = joinColumn.referencedColumn!.propertyPath.replace(\".\", \"_\");\n parameters[parameterName] = joinColumn.referencedColumn!.getEntityValue(entity);\n return \"joined.\" + joinColumn.referencedColumn!.propertyPath + \" = :\" + parameterName;\n }).join(\" AND \");\n\n return this\n .createQueryBuilder(alias)\n .innerJoin(this.metadata.targetName, \"joined\", joinCondition)\n .where(whereCondition, parameters);\n\n\n } else if (this.metadata.treeType === \"materialized-path\") {\n // example: SELECT * FROM category category WHERE (SELECT mpath FROM `category` WHERE id = 2) LIKE CONCAT(category.mpath, '%');\n return this\n .createQueryBuilder(alias)\n .where(qb => {\n const subQuery = qb.subQuery()\n .select(`${this.metadata.targetName}.${this.metadata.materializedPathColumn!.propertyPath}`, \"path\")\n .from(this.metadata.target, this.metadata.targetName)\n .whereInIds(this.metadata.getEntityIdMap(entity));\n\n if (this.manager.connection.driver instanceof AbstractSqliteDriver) {\n return `${subQuery.getQuery()} LIKE ${alias}.${this.metadata.materializedPathColumn!.propertyPath} || '%'`;\n\n } else {\n return `${subQuery.getQuery()} LIKE CONCAT(${alias}.${this.metadata.materializedPathColumn!.propertyPath}, '%')`;\n }\n });\n }\n\n throw new TypeORMError(`Supported only in tree entities`);\n }\n\n /**\n * Moves entity to the children of then given entity.\n *\n move(entity: Entity, to: Entity): Promise<void> {\n return Promise.resolve();\n } */\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n protected createRelationMaps(alias: string, rawResults: any[]): { id: any, parentId: any }[] {\n return rawResults.map(rawResult => {\n const joinColumn = this.metadata.treeParentRelation!.joinColumns[0];\n // fixes issue #2518, default to databaseName property when givenDatabaseName is not set\n const joinColumnName = joinColumn.givenDatabaseName || joinColumn.databaseName;\n const id = rawResult[alias + \"_\" + this.metadata.primaryColumns[0].databaseName];\n const parentId = rawResult[alias + \"_\" + joinColumnName];\n return {\n id: this.manager.connection.driver.prepareHydratedValue(id, this.metadata.primaryColumns[0]),\n parentId: this.manager.connection.driver.prepareHydratedValue(parentId, joinColumn),\n };\n });\n }\n\n protected buildChildrenEntityTree(entity: any, entities: any[], relationMaps: { id: any, parentId: any }[]): void {\n const childProperty = this.metadata.treeChildrenRelation!.propertyName;\n const parentEntityId = this.metadata.primaryColumns[0].getEntityValue(entity);\n const childRelationMaps = relationMaps.filter(relationMap => relationMap.parentId === parentEntityId);\n const childIds = new Set(childRelationMaps.map(relationMap => relationMap.id));\n entity[childProperty] = entities.filter(entity => childIds.has(this.metadata.primaryColumns[0].getEntityValue(entity)));\n entity[childProperty].forEach((childEntity: any) => {\n this.buildChildrenEntityTree(childEntity, entities, relationMaps);\n });\n }\n\n protected buildParentEntityTree(entity: any, entities: any[], relationMaps: { id: any, parentId: any }[]): void {\n const parentProperty = this.metadata.treeParentRelation!.propertyName;\n const entityId = this.metadata.primaryColumns[0].getEntityValue(entity);\n const parentRelationMap = relationMaps.find(relationMap => relationMap.id === entityId);\n const parentEntity = entities.find(entity => {\n if (!parentRelationMap)\n return false;\n\n return this.metadata.primaryColumns[0].getEntityValue(entity) === parentRelationMap.parentId;\n });\n if (parentEntity) {\n entity[parentProperty] = parentEntity;\n this.buildParentEntityTree(entity[parentProperty], entities, relationMaps);\n }\n }\n\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/repository/TreeRepository.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AAGxC,OAAO,EAAC,oBAAoB,EAAC,MAAM,gDAAgD,CAAC;AACpF,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAGpE;;;;GAIG;AACH;IAA4C,kCAAkB;IAA9D;;IA6RA,CAAC;IA3RG,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACG,kCAAS,GAAf,UAAgB,OAAyB;;;;;;4BACvB,qBAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAA;;w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port {ObjectLiteral} from \"../common/ObjectLiteral\";\nimport {AbstractSqliteDriver} from \"../driver/sqlite-abstract/AbstractSqliteDriver\";\nimport { TypeORMError } from \"../error/TypeORMError\";\nimport { FindTreeOptions } from \"../find-options/FindTreeOptions\";\nimport { FindOptionsUtils } from \"../find-options/FindOptionsUtils\";\nimport { FindTreesOptions } from \"./FindTreesOptions\";\n\n/**\n * Repository with additional functions to work with trees.\n *\n * @see Repository\n */\nexport class TreeRepository<Entity> extends Repository<Entity> {\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Gets complete trees for all roots in the table.\n */\n async findTrees(options?: FindTreeOptions): Promise<Entity[]> {\n const roots = await this.findRoots(options);\n await Promise.all(roots.map(root => this.findDescendantsTree(root, options)));\n return roots;\n }\n\n /**\n * Roots are entities that have no ancestors. Finds them all.\n */\n findRoots(options?: FindTreeOptions): Promise<Entity[]> {\n const escapeAlias = (alias: string) => this.manager.connection.driver.escape(alias);\n const escapeColumn = (column: string) => this.manager.connection.driver.escape(column);\n const parentPropertyName = this.manager.connection.namingStrategy.joinColumnName(\n this.metadata.treeParentRelation!.propertyName, this.metadata.primaryColumns[0].propertyName\n );\n\n const qb = this.createQueryBuilder(\"treeEntity\");\n FindOptionsUtils.applyOptionsToTreeQueryBuilder(qb, options);\n\n return qb\n .where(`${escapeAlias(\"treeEntity\")}.${escapeColumn(parentPropertyName)} IS NULL`)\n .getMany();\n }\n\n /**\n * Gets all children (descendants) of the given entity. Returns them all in a flat array.\n */\n findDescendants(entity: Entity, options?: FindTreeOptions): Promise<Entity[]> {\n const qb = this.createDescendantsQueryBuilder(\"treeEntity\", \"treeClosure\", entity);\n FindOptionsUtils.applyOptionsToTreeQueryBuilder(qb, options);\n return qb.getMany();\n }\n\n /**\n * Gets all children (descendants) of the given entity. Returns them in a tree - nested into each other.\n */\n async findDescendantsTree(entity: Entity, options?: FindTreeOptions): Promise<Entity> {\n // todo: throw exception if there is no column of this relation?\n\n const qb: SelectQueryBuilder<Entity> = this.createDescendantsQueryBuilder(\"treeEntity\", \"treeClosure\", entity);\n FindOptionsUtils.applyOptionsToTreeQueryBuilder(qb, options);\n\n const entities = await qb.getRawAndEntities();\n const relationMaps = this.createRelationMaps(\"treeEntity\", entities.raw);\n this.buildChildrenEntityTree(entity, entities.entities, relationMaps, {\n depth: -1,\n ...options\n\n });\n\n return entity;\n }\n\n /**\n * Gets number of descendants of the entity.\n */\n countDescendants(entity: Entity): Promise<number> {\n return this\n .createDescendantsQueryBuilder(\"treeEntity\", \"treeClosure\", entity)\n .getCount();\n }\n\n /**\n * Creates a query builder used to get descendants of the entities in a tree.\n */\n createDescendantsQueryBuilder(alias: string, closureTableAlias: string, entity: Entity): SelectQueryBuilder<Entity> {\n\n // create shortcuts for better readability\n const escape = (alias: string) => this.manager.connection.driver.escape(alias);\n\n if (this.metadata.treeType === \"closure-table\") {\n\n const joinCondition = this.metadata.closureJunctionTable.descendantColumns.map(column => {\n return escape(closureTableAlias) + \".\" + escape(column.propertyPath) + \" = \" + escape(alias) + \".\" + escape(column.referencedColumn!.propertyPath);\n }).join(\" AND \");\n\n const parameters: ObjectLiteral = {};\n const whereCondition = this.metadata.closureJunctionTable.ancestorColumns.map(column => {\n parameters[column.referencedColumn!.propertyName] = column.referencedColumn!.getEntityValue(entity);\n return escape(closureTableAlias) + \".\" + escape(column.propertyPath) + \" = :\" + column.referencedColumn!.propertyName;\n }).join(\" AND \");\n\n return this\n .createQueryBuilder(alias)\n .innerJoin(this.metadata.closureJunctionTable.tableName, closureTableAlias, joinCondition)\n .where(whereCondition)\n .setParameters(parameters);\n\n } else if (this.metadata.treeType === \"nested-set\") {\n\n const whereCondition = alias + \".\" + this.metadata.nestedSetLeftColumn!.propertyPath + \" BETWEEN \" +\n \"joined.\" + this.metadata.nestedSetLeftColumn!.propertyPath + \" AND joined.\" + this.metadata.nestedSetRightColumn!.propertyPath;\n const parameters: ObjectLiteral = {};\n const joinCondition = this.metadata.treeParentRelation!.joinColumns.map(joinColumn => {\n const parameterName = joinColumn.referencedColumn!.propertyPath.replace(\".\", \"_\");\n parameters[parameterName] = joinColumn.referencedColumn!.getEntityValue(entity);\n return \"joined.\" + joinColumn.referencedColumn!.propertyPath + \" = :\" + parameterName;\n }).join(\" AND \");\n\n return this\n .createQueryBuilder(alias)\n .innerJoin(this.metadata.targetName, \"joined\", whereCondition)\n .where(joinCondition, parameters);\n\n } else if (this.metadata.treeType === \"materialized-path\") {\n return this\n .createQueryBuilder(alias)\n .where(qb => {\n const subQuery = qb.subQuery()\n .select(`${this.metadata.targetName}.${this.metadata.materializedPathColumn!.propertyPath}`, \"path\")\n .from(this.metadata.target, this.metadata.targetName)\n .whereInIds(this.metadata.getEntityIdMap(entity));\n\n if (this.manager.connection.driver instanceof AbstractSqliteDriver) {\n return `${alias}.${this.metadata.materializedPathColumn!.propertyPath} LIKE ${subQuery.getQuery()} || '%'`;\n } else {\n return `${alias}.${this.metadata.materializedPathColumn!.propertyPath} LIKE CONCAT(${subQuery.getQuery()}, '%')`;\n }\n });\n }\n\n throw new TypeORMError(`Supported only in tree entities`);\n }\n\n /**\n * Gets all parents (ancestors) of the given entity. Returns them all in a flat array.\n */\n findAncestors(entity: Entity, options?: FindTreeOptions): Promise<Entity[]> {\n const qb = this.createAncestorsQueryBuilder(\"treeEntity\", \"treeClosure\", entity);\n FindOptionsUtils.applyOptionsToTreeQueryBuilder(qb, options);\n return qb.getMany();\n }\n\n /**\n * Gets all parents (ancestors) of the given entity. Returns them in a tree - nested into each other.\n */\n async findAncestorsTree(entity: Entity, options?: FindTreeOptions): Promise<Entity> {\n // todo: throw exception if there is no column of this relation?\n const qb = this.createAncestorsQueryBuilder(\"treeEntity\", \"treeClosure\", entity);\n FindOptionsUtils.applyOptionsToTreeQueryBuilder(qb, options);\n\n const entities = await qb.getRawAndEntities();\n const relationMaps = this.createRelationMaps(\"treeEntity\", entities.raw);\n this.buildParentEntityTree(entity, entities.entities, relationMaps);\n return entity;\n }\n\n /**\n * Gets number of ancestors of the entity.\n */\n countAncestors(entity: Entity): Promise<number> {\n return this\n .createAncestorsQueryBuilder(\"treeEntity\", \"treeClosure\", entity)\n .getCount();\n }\n\n /**\n * Creates a query builder used to get ancestors of the entities in the tree.\n */\n createAncestorsQueryBuilder(alias: string, closureTableAlias: string, entity: Entity): SelectQueryBuilder<Entity> {\n\n // create shortcuts for better readability\n // const escape = (alias: string) => this.manager.connection.driver.escape(alias);\n\n if (this.metadata.treeType === \"closure-table\") {\n const joinCondition = this.metadata.closureJunctionTable.ancestorColumns.map(column => {\n return closureTableAlias + \".\" + column.propertyPath + \" = \" + alias + \".\" + column.referencedColumn!.propertyPath;\n }).join(\" AND \");\n\n const parameters: ObjectLiteral = {};\n const whereCondition = this.metadata.closureJunctionTable.descendantColumns.map(column => {\n parameters[column.referencedColumn!.propertyName] = column.referencedColumn!.getEntityValue(entity);\n return closureTableAlias + \".\" + column.propertyPath + \" = :\" + column.referencedColumn!.propertyName;\n }).join(\" AND \");\n\n return this\n .createQueryBuilder(alias)\n .innerJoin(this.metadata.closureJunctionTable.tableName, closureTableAlias, joinCondition)\n .where(whereCondition)\n .setParameters(parameters);\n\n } else if (this.metadata.treeType === \"nested-set\") {\n\n const joinCondition = \"joined.\" + this.metadata.nestedSetLeftColumn!.propertyPath + \" BETWEEN \" +\n alias + \".\" + this.metadata.nestedSetLeftColumn!.propertyPath + \" AND \" + alias + \".\" + this.metadata.nestedSetRightColumn!.propertyPath;\n const parameters: ObjectLiteral = {};\n const whereCondition = this.metadata.treeParentRelation!.joinColumns.map(joinColumn => {\n const parameterName = joinColumn.referencedColumn!.propertyPath.replace(\".\", \"_\");\n parameters[parameterName] = joinColumn.referencedColumn!.getEntityValue(entity);\n return \"joined.\" + joinColumn.referencedColumn!.propertyPath + \" = :\" + parameterName;\n }).join(\" AND \");\n\n return this\n .createQueryBuilder(alias)\n .innerJoin(this.metadata.targetName, \"joined\", joinCondition)\n .where(whereCondition, parameters);\n\n\n } else if (this.metadata.treeType === \"materialized-path\") {\n // example: SELECT * FROM category category WHERE (SELECT mpath FROM `category` WHERE id = 2) LIKE CONCAT(category.mpath, '%');\n return this\n .createQueryBuilder(alias)\n .where(qb => {\n const subQuery = qb.subQuery()\n .select(`${this.metadata.targetName}.${this.metadata.materializedPathColumn!.propertyPath}`, \"path\")\n .from(this.metadata.target, this.metadata.targetName)\n .whereInIds(this.metadata.getEntityIdMap(entity));\n\n if (this.manager.connection.driver instanceof AbstractSqliteDriver) {\n return `${subQuery.getQuery()} LIKE ${alias}.${this.metadata.materializedPathColumn!.propertyPath} || '%'`;\n\n } else {\n return `${subQuery.getQuery()} LIKE CONCAT(${alias}.${this.metadata.materializedPathColumn!.propertyPath}, '%')`;\n }\n });\n }\n\n throw new TypeORMError(`Supported only in tree entities`);\n }\n\n /**\n * Moves entity to the children of then given entity.\n *\n move(entity: Entity, to: Entity): Promise<void> {\n return Promise.resolve();\n } */\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n protected createRelationMaps(alias: string, rawResults: any[]): { id: any, parentId: any }[] {\n return rawResults.map(rawResult => {\n const joinColumn = this.metadata.treeParentRelation!.joinColumns[0];\n // fixes issue #2518, default to databaseName property when givenDatabaseName is not set\n const joinColumnName = joinColumn.givenDatabaseName || joinColumn.databaseName;\n const id = rawResult[alias + \"_\" + this.metadata.primaryColumns[0].databaseName];\n const parentId = rawResult[alias + \"_\" + joinColumnName];\n return {\n id: this.manager.connection.driver.prepareHydratedValue(id, this.metadata.primaryColumns[0]),\n parentId: this.manager.connection.driver.prepareHydratedValue(parentId, joinColumn),\n };\n });\n }\n\n protected buildChildrenEntityTree(entity: any, entities: any[], relationMaps: { id: any, parentId: any }[], options: (FindTreesOptions & { depth: number })): void {\n const childProperty = this.metadata.treeChildrenRelation!.propertyName;\n if (options.depth === 0) {\n entity[childProperty] = [];\n return;\n }\n const parentEntityId = this.metadata.primaryColumns[0].getEntityValue(entity);\n const childRelationMaps = relationMaps.filter(relationMap => relationMap.parentId === parentEntityId);\n const childIds = new Set(childRelationMaps.map(relationMap => relationMap.id));\n entity[childProperty] = entities.filter(entity => childIds.has(this.metadata.primaryColumns[0].getEntityValue(entity)));\n entity[childProperty].forEach((childEntity: any) => {\n this.buildChildrenEntityTree(childEntity, entities, relationMaps, { ...options, depth: options.depth - 1 });\n });\n }\n\n protected buildParentEntityTree(entity: any, entities: any[], relationMaps: { id: any, parentId: any }[]): void {\n const parentProperty = this.metadata.treeParentRelation!.propertyName;\n const entityId = this.metadata.primaryColumns[0].getEntityValue(entity);\n const parentRelationMap = relationMaps.find(relationMap => relationMap.id === entityId);\n const parentEntity = entities.find(entity => {\n if (!parentRelationMap)\n return false;\n\n return this.metadata.primaryColumns[0].getEntityValue(entity) === parentRelationMap.parentId;\n });\n if (parentEntity) {\n entity[parentProperty] = parentEntity;\n this.buildParentEntityTree(entity[parentProperty], entities, relationMaps);\n }\n }\n\n}\n"],"sourceRoot":".."}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../browser/src/repository/UpsertOptions.ts"],"names":[],"mappings":"","file":"UpsertOptions.js","sourcesContent":["/**\n * Special options passed to Repository#upsert\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport interface UpsertOptions<Entity> {\n conflictPaths: string[]\n}\n"],"sourceRoot":".."}
|
|
@@ -29,7 +29,7 @@ export interface TableColumnOptions {
|
|
|
29
29
|
/**
|
|
30
30
|
* Specifies generation strategy if this column will use auto increment.
|
|
31
31
|
*/
|
|
32
|
-
generationStrategy?: "uuid" | "increment" | "rowid";
|
|
32
|
+
generationStrategy?: "uuid" | "increment" | "rowid" | "identity";
|
|
33
33
|
/**
|
|
34
34
|
* Indicates if column is a primary key.
|
|
35
35
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/schema-builder/options/TableColumnOptions.ts"],"names":[],"mappings":"","file":"TableColumnOptions.js","sourcesContent":["\n/**\n * Table's column options.\n */\nexport interface TableColumnOptions {\n\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Column name.\n */\n name: string;\n\n /**\n * Column type.\n */\n type: string;\n\n /**\n * Column's default value.\n */\n default?: any;\n\n /**\n * ON UPDATE trigger. Works only for MySQL.\n */\n onUpdate?: string;\n\n /**\n * Indicates if column is NULL, or is NOT NULL in the database.\n */\n isNullable?: boolean;\n\n /**\n * Indicates if column is auto-generated sequence.\n */\n isGenerated?: boolean;\n\n /**\n * Specifies generation strategy if this column will use auto increment.\n */\n generationStrategy?: \"uuid\"|\"increment\"|\"rowid\";\n\n /**\n * Indicates if column is a primary key.\n */\n isPrimary?: boolean;\n\n /**\n * Indicates if column has unique value.\n */\n isUnique?: boolean;\n\n /**\n * Indicates if column stores array.\n */\n isArray?: boolean;\n\n /**\n * Column's comment.\n */\n comment?: string;\n\n /**\n * Column type's length. Used only on some column types.\n * For example type = \"string\" and length = \"100\" means that ORM will create a column with type varchar(100).\n */\n length?: string;\n\n /**\n * Column type's display width. Used only on some column types in MySQL.\n * For example, INT(4) specifies an INT with a display width of four digits.\n */\n width?: number;\n\n /**\n * Defines column character set.\n */\n charset?: string;\n\n /**\n * Defines column collation.\n */\n collation?: string;\n\n /**\n * The precision for a decimal (exact numeric) column (applies only for decimal column), which is the maximum\n * number of digits that are stored for the values.\n */\n precision?: number|null;\n\n /**\n * The scale for a decimal (exact numeric) column (applies only for decimal column), which represents the number\n * of digits to the right of the decimal point and must not be greater than precision.\n */\n scale?: number;\n\n /**\n * Puts ZEROFILL attribute on to numeric column. Works only for MySQL.\n * If you specify ZEROFILL for a numeric column, MySQL automatically adds the UNSIGNED attribute to the column\n */\n zerofill?: boolean;\n\n /**\n * Puts UNSIGNED attribute on to numeric column. Works only for MySQL.\n */\n unsigned?: boolean;\n\n /**\n * Array of possible enumerated values.\n */\n enum?: string[];\n\n /**\n * Exact name of enum\n */\n enumName?: string;\n\n /**\n * Generated column expression. Supports only in MySQL.\n */\n asExpression?: string;\n\n /**\n * Generated column type. Supports only in MySQL.\n */\n generatedType?: \"VIRTUAL\"|\"STORED\";\n\n /**\n * Spatial Feature Type (Geometry, Point, Polygon, etc.)\n */\n spatialFeatureType?: string;\n\n /**\n * SRID (Spatial Reference ID (EPSG code))\n */\n srid?: number;\n}\n"],"sourceRoot":"../.."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/schema-builder/options/TableColumnOptions.ts"],"names":[],"mappings":"","file":"TableColumnOptions.js","sourcesContent":["\n/**\n * Table's column options.\n */\nexport interface TableColumnOptions {\n\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Column name.\n */\n name: string;\n\n /**\n * Column type.\n */\n type: string;\n\n /**\n * Column's default value.\n */\n default?: any;\n\n /**\n * ON UPDATE trigger. Works only for MySQL.\n */\n onUpdate?: string;\n\n /**\n * Indicates if column is NULL, or is NOT NULL in the database.\n */\n isNullable?: boolean;\n\n /**\n * Indicates if column is auto-generated sequence.\n */\n isGenerated?: boolean;\n\n /**\n * Specifies generation strategy if this column will use auto increment.\n */\n generationStrategy?: \"uuid\"|\"increment\"|\"rowid\"|\"identity\";\n\n /**\n * Indicates if column is a primary key.\n */\n isPrimary?: boolean;\n\n /**\n * Indicates if column has unique value.\n */\n isUnique?: boolean;\n\n /**\n * Indicates if column stores array.\n */\n isArray?: boolean;\n\n /**\n * Column's comment.\n */\n comment?: string;\n\n /**\n * Column type's length. Used only on some column types.\n * For example type = \"string\" and length = \"100\" means that ORM will create a column with type varchar(100).\n */\n length?: string;\n\n /**\n * Column type's display width. Used only on some column types in MySQL.\n * For example, INT(4) specifies an INT with a display width of four digits.\n */\n width?: number;\n\n /**\n * Defines column character set.\n */\n charset?: string;\n\n /**\n * Defines column collation.\n */\n collation?: string;\n\n /**\n * The precision for a decimal (exact numeric) column (applies only for decimal column), which is the maximum\n * number of digits that are stored for the values.\n */\n precision?: number|null;\n\n /**\n * The scale for a decimal (exact numeric) column (applies only for decimal column), which represents the number\n * of digits to the right of the decimal point and must not be greater than precision.\n */\n scale?: number;\n\n /**\n * Puts ZEROFILL attribute on to numeric column. Works only for MySQL.\n * If you specify ZEROFILL for a numeric column, MySQL automatically adds the UNSIGNED attribute to the column\n */\n zerofill?: boolean;\n\n /**\n * Puts UNSIGNED attribute on to numeric column. Works only for MySQL.\n */\n unsigned?: boolean;\n\n /**\n * Array of possible enumerated values.\n */\n enum?: string[];\n\n /**\n * Exact name of enum\n */\n enumName?: string;\n\n /**\n * Generated column expression. Supports only in MySQL.\n */\n asExpression?: string;\n\n /**\n * Generated column type. Supports only in MySQL.\n */\n generatedType?: \"VIRTUAL\"|\"STORED\";\n\n /**\n * Spatial Feature Type (Geometry, Point, Polygon, etc.)\n */\n spatialFeatureType?: string;\n\n /**\n * SRID (Spatial Reference ID (EPSG code))\n */\n srid?: number;\n}\n"],"sourceRoot":"../.."}
|
|
@@ -31,7 +31,7 @@ export declare class TableColumn {
|
|
|
31
31
|
* Specifies generation strategy if this column will use auto increment.
|
|
32
32
|
* `rowid` option supported only in CockroachDB.
|
|
33
33
|
*/
|
|
34
|
-
generationStrategy?: "uuid" | "increment" | "rowid";
|
|
34
|
+
generationStrategy?: "uuid" | "increment" | "rowid" | "identity";
|
|
35
35
|
/**
|
|
36
36
|
* Indicates if column is a primary key.
|
|
37
37
|
*/
|