typeorm 0.3.18-dev.65858f3 → 0.3.18-dev.7a58bbf
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/driver/Driver.d.ts +0 -4
- package/browser/driver/Driver.js.map +1 -1
- package/browser/driver/cockroachdb/CockroachDriver.d.ts +0 -4
- package/browser/driver/cockroachdb/CockroachDriver.js +1 -10
- package/browser/driver/cockroachdb/CockroachDriver.js.map +1 -1
- package/browser/driver/oracle/OracleDriver.d.ts +0 -4
- package/browser/driver/oracle/OracleDriver.js +2 -11
- package/browser/driver/oracle/OracleDriver.js.map +1 -1
- package/browser/driver/postgres/PostgresDriver.d.ts +0 -4
- package/browser/driver/postgres/PostgresDriver.js +1 -10
- package/browser/driver/postgres/PostgresDriver.js.map +1 -1
- package/browser/driver/spanner/SpannerDriver.d.ts +0 -4
- package/browser/driver/spanner/SpannerDriver.js +1 -10
- package/browser/driver/spanner/SpannerDriver.js.map +1 -1
- package/browser/driver/sqlserver/SqlServerDriver.d.ts +0 -4
- package/browser/driver/sqlserver/SqlServerDriver.js +1 -10
- package/browser/driver/sqlserver/SqlServerDriver.js.map +1 -1
- package/browser/entity-manager/EntityManager.d.ts +1 -5
- package/browser/entity-manager/EntityManager.js +1 -10
- package/browser/entity-manager/EntityManager.js.map +1 -1
- package/browser/persistence/SubjectExecutor.js +0 -3
- package/browser/persistence/SubjectExecutor.js.map +1 -1
- package/browser/query-builder/SelectQueryBuilder.js +1 -3
- package/browser/query-builder/SelectQueryBuilder.js.map +1 -1
- package/browser/repository/BaseEntity.d.ts +0 -12
- package/browser/repository/BaseEntity.js +0 -12
- package/browser/repository/BaseEntity.js.map +1 -1
- package/browser/repository/Repository.d.ts +1 -13
- package/browser/repository/Repository.js +1 -17
- package/browser/repository/Repository.js.map +1 -1
- package/browser/util/DateUtils.js +2 -4
- package/browser/util/DateUtils.js.map +1 -1
- package/driver/Driver.d.ts +0 -4
- package/driver/Driver.js.map +1 -1
- package/driver/cockroachdb/CockroachDriver.d.ts +0 -4
- package/driver/cockroachdb/CockroachDriver.js +1 -10
- package/driver/cockroachdb/CockroachDriver.js.map +1 -1
- package/driver/oracle/OracleDriver.d.ts +0 -4
- package/driver/oracle/OracleDriver.js +2 -11
- package/driver/oracle/OracleDriver.js.map +1 -1
- package/driver/postgres/PostgresDriver.d.ts +0 -4
- package/driver/postgres/PostgresDriver.js +1 -10
- package/driver/postgres/PostgresDriver.js.map +1 -1
- package/driver/spanner/SpannerDriver.d.ts +0 -4
- package/driver/spanner/SpannerDriver.js +1 -10
- package/driver/spanner/SpannerDriver.js.map +1 -1
- package/driver/sqlserver/SqlServerDriver.d.ts +0 -4
- package/driver/sqlserver/SqlServerDriver.js +1 -10
- package/driver/sqlserver/SqlServerDriver.js.map +1 -1
- package/entity-manager/EntityManager.d.ts +1 -5
- package/entity-manager/EntityManager.js +1 -10
- package/entity-manager/EntityManager.js.map +1 -1
- package/package.json +1 -1
- package/persistence/SubjectExecutor.js +0 -3
- package/persistence/SubjectExecutor.js.map +1 -1
- package/query-builder/SelectQueryBuilder.js +1 -3
- package/query-builder/SelectQueryBuilder.js.map +1 -1
- package/repository/BaseEntity.d.ts +0 -12
- package/repository/BaseEntity.js +0 -12
- package/repository/BaseEntity.js.map +1 -1
- package/repository/Repository.d.ts +1 -13
- package/repository/Repository.js +1 -17
- package/repository/Repository.js.map +1 -1
- package/util/DateUtils.js +2 -5
- package/util/DateUtils.js.map +1 -1
|
@@ -193,18 +193,6 @@ export declare class BaseEntity {
|
|
|
193
193
|
static delete<T extends BaseEntity>(this: {
|
|
194
194
|
new (): T;
|
|
195
195
|
} & typeof BaseEntity, criteria: string | string[] | number | number[] | Date | Date[] | ObjectId | ObjectId[] | FindOptionsWhere<T>): Promise<DeleteResult>;
|
|
196
|
-
/**
|
|
197
|
-
* Checks whether any entity exists that matches the given options.
|
|
198
|
-
*/
|
|
199
|
-
static exists<T extends BaseEntity>(this: {
|
|
200
|
-
new (): T;
|
|
201
|
-
} & typeof BaseEntity, options?: FindManyOptions<T>): Promise<boolean>;
|
|
202
|
-
/**
|
|
203
|
-
* Checks whether any entity exists that matches the given conditions.
|
|
204
|
-
*/
|
|
205
|
-
static existsBy<T extends BaseEntity>(this: {
|
|
206
|
-
new (): T;
|
|
207
|
-
} & typeof BaseEntity, where: FindOptionsWhere<T>): Promise<boolean>;
|
|
208
196
|
/**
|
|
209
197
|
* Counts entities that match given options.
|
|
210
198
|
*/
|
|
@@ -181,18 +181,6 @@ export class BaseEntity {
|
|
|
181
181
|
static delete(criteria) {
|
|
182
182
|
return this.getRepository().delete(criteria);
|
|
183
183
|
}
|
|
184
|
-
/**
|
|
185
|
-
* Checks whether any entity exists that matches the given options.
|
|
186
|
-
*/
|
|
187
|
-
static exists(options) {
|
|
188
|
-
return this.getRepository().exists(options);
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Checks whether any entity exists that matches the given conditions.
|
|
192
|
-
*/
|
|
193
|
-
static existsBy(where) {
|
|
194
|
-
return this.getRepository().existsBy(where);
|
|
195
|
-
}
|
|
196
184
|
/**
|
|
197
185
|
* Counts entities that match given options.
|
|
198
186
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/repository/BaseEntity.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAMjD;;GAEG;AACH,MAAM,OAAO,UAAU;IAUnB,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;;OAGG;IACH,KAAK;QACD,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC,CAAA;QACxD,OAAO,UAAU,CAAC,aAAa,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACjD,CAAC;IAED;;;OAGG;IACH,IAAI,CAAC,OAAqB;QACtB,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC,CAAA;QACxD,OAAO,UAAU,CAAC,aAAa,EAAE,C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AAA;IAC3D,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK;QAGR,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,KAAK,EAAE,CAAA;IAC1C,CAAC;CACJ","file":"BaseEntity.js","sourcesContent":["import { Repository } from \"./Repository\"\nimport { FindOptionsWhere } from \"../find-options/FindOptionsWhere\"\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 { DataSource } from \"../data-source\"\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\"\nimport { EntityTarget } from \"../common/EntityTarget\"\nimport { PickKeysByType } from \"../common/PickKeysByType\"\n\n/**\n * Base abstract entity for all entities, used in ActiveRecord patterns.\n */\nexport class BaseEntity {\n // -------------------------------------------------------------------------\n // Private Static Properties\n // -------------------------------------------------------------------------\n\n /**\n * DataSource used in all static methods of the BaseEntity.\n */\n private static dataSource: DataSource | null\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 const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.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 const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().save(this, options)\n }\n\n /**\n * Removes current entity from the database.\n */\n remove(options?: RemoveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().remove(this, options) as Promise<this>\n }\n\n /**\n * Records the delete date of current entity.\n */\n softRemove(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().softRemove(this, options)\n }\n\n /**\n * Recovers a given entity in the database.\n */\n recover(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().recover(this, options)\n }\n\n /**\n * Reloads entity data from the database.\n */\n async reload(): Promise<void> {\n const baseEntity = this.constructor as typeof BaseEntity\n const id = baseEntity.getRepository().metadata.getEntityIdMap(this)\n if (!id) {\n throw new Error(\n `Entity doesn't have id-s set, cannot reload entity`,\n )\n }\n const reloadedEntity: BaseEntity = await baseEntity\n .getRepository()\n .findOneByOrFail(id)\n\n ObjectUtils.assign(this, reloadedEntity)\n }\n\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Sets DataSource to be used by entity.\n */\n static useDataSource(dataSource: DataSource | null) {\n this.dataSource = dataSource\n }\n\n /**\n * Gets current entity's Repository.\n */\n static getRepository<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): Repository<T> {\n const dataSource = (this as typeof BaseEntity).dataSource\n if (!dataSource)\n throw new Error(`DataSource is not set for this entity.`)\n return dataSource.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(): EntityTarget<any> {\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>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n ): any {\n return this.getRepository<T>().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>(\n this: { new (): T } & typeof BaseEntity,\n alias?: string,\n ): SelectQueryBuilder<T> {\n return this.getRepository<T>().createQueryBuilder(alias)\n }\n\n /**\n * Creates a new entity instance.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): 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>(\n this: { new (): T } & typeof BaseEntity,\n entityLikeArray: DeepPartial<T>[],\n ): 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>(\n this: { new (): T } & typeof BaseEntity,\n entityLike: DeepPartial<T>,\n ): 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>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities?: any,\n ) {\n return this.getRepository<T>().create(entityOrEntities)\n }\n\n /**\n * Merges multiple entities (or entity-like objects) into a given entity.\n */\n static merge<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n mergeIntoEntity: T,\n ...entityLikes: DeepPartial<T>[]\n ): T {\n return this.getRepository<T>().merge(\n mergeIntoEntity,\n ...entityLikes,\n ) as T\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>(\n this: { new (): T } & typeof BaseEntity,\n entityLike: DeepPartial<T>,\n ): Promise<T | undefined> {\n const thisRepository = this.getRepository<T>()\n return thisRepository.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>(\n this: { new (): T } & typeof BaseEntity,\n entities: DeepPartial<T>[],\n options?: SaveOptions,\n ): 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>(\n this: { new (): T } & typeof BaseEntity,\n entity: DeepPartial<T>,\n options?: SaveOptions,\n ): Promise<T>\n\n /**\n * Saves one or many given entities.\n */\n static save<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: DeepPartial<T> | DeepPartial<T>[],\n options?: SaveOptions,\n ) {\n return this.getRepository<T>().save(entityOrEntities as any, options)\n }\n\n /**\n * Removes a given entities from the database.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: T[],\n options?: RemoveOptions,\n ): Promise<T[]>\n\n /**\n * Removes a given entity from the database.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n options?: RemoveOptions,\n ): Promise<T>\n\n /**\n * Removes one or many given entities.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: T | T[],\n options?: RemoveOptions,\n ) {\n return this.getRepository<T>().remove(entityOrEntities as any, options)\n }\n\n /**\n * Records the delete date of all given entities.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: T[],\n options?: SaveOptions,\n ): Promise<T[]>\n\n /**\n * Records the delete date of a given entity.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n options?: SaveOptions,\n ): Promise<T>\n\n /**\n * Records the delete date of one or many given entities.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ) {\n return this.getRepository<T>().softRemove(\n entityOrEntities as any,\n options,\n )\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>(\n this: { new (): T } & typeof BaseEntity,\n entity: QueryDeepPartialEntity<T> | QueryDeepPartialEntity<T>[],\n ): Promise<InsertResult> {\n return this.getRepository<T>().insert(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 static update<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectId\n | ObjectId[]\n | FindOptionsWhere<T>,\n partialEntity: QueryDeepPartialEntity<T>,\n ): Promise<UpdateResult> {\n return this.getRepository<T>().update(criteria, 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 static upsert<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities:\n | QueryDeepPartialEntity<T>\n | QueryDeepPartialEntity<T>[],\n conflictPathsOrOptions: string[] | UpsertOptions<T>,\n ): Promise<InsertResult> {\n return this.getRepository<T>().upsert(\n entityOrEntities,\n conflictPathsOrOptions,\n )\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>(\n this: { new (): T } & typeof BaseEntity,\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectId\n | ObjectId[]\n | FindOptionsWhere<T>,\n ): Promise<DeleteResult> {\n return this.getRepository<T>().delete(criteria)\n }\n\n /**\n * Checks whether any entity exists that matches the given options.\n */\n static exists<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<boolean> {\n return this.getRepository<T>().exists(options)\n }\n\n /**\n * Checks whether any entity exists that matches the given conditions.\n */\n static existsBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<boolean> {\n return this.getRepository<T>().existsBy(where)\n }\n\n /**\n * Counts entities that match given options.\n */\n static count<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<number> {\n return this.getRepository<T>().count(options)\n }\n\n /**\n * Counts entities that match given WHERE conditions.\n */\n static countBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<number> {\n return this.getRepository<T>().countBy(where)\n }\n\n /**\n * Return the SUM of a column\n */\n static sum<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n columnName: PickKeysByType<T, number>,\n where: FindOptionsWhere<T>,\n ): Promise<number | null> {\n return this.getRepository<T>().sum(columnName, where)\n }\n\n /**\n * Return the AVG of a column\n */\n static average<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n columnName: PickKeysByType<T, number>,\n where: FindOptionsWhere<T>,\n ): Promise<number | null> {\n return this.getRepository<T>().average(columnName, where)\n }\n\n /**\n * Return the MIN of a column\n */\n static minimum<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n columnName: PickKeysByType<T, number>,\n where: FindOptionsWhere<T>,\n ): Promise<number | null> {\n return this.getRepository<T>().minimum(columnName, where)\n }\n\n /**\n * Return the MAX of a column\n */\n static maximum<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n columnName: PickKeysByType<T, number>,\n where: FindOptionsWhere<T>,\n ): Promise<number | null> {\n return this.getRepository<T>().maximum(columnName, where)\n }\n\n /**\n * Finds entities that match given options.\n */\n static find<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<T[]> {\n return this.getRepository<T>().find(options)\n }\n\n /**\n * Finds entities that match given WHERE conditions.\n */\n static findBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T[]> {\n return this.getRepository<T>().findBy(where)\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>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<[T[], number]> {\n return this.getRepository<T>().findAndCount(options)\n }\n\n /**\n * Finds entities that match given WHERE conditions.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n static findAndCountBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<[T[], number]> {\n return this.getRepository<T>().findAndCountBy(where)\n }\n\n /**\n * Finds entities by ids.\n * Optionally find options can be applied.\n *\n * @deprecated use `findBy` method instead in conjunction with `In` operator, for example:\n *\n * .findBy({\n * id: In([1, 2, 3])\n * })\n */\n static findByIds<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ids: any[],\n ): Promise<T[]> {\n return this.getRepository<T>().findByIds(ids)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOne<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options: FindOneOptions<T>,\n ): Promise<T | null> {\n return this.getRepository<T>().findOne(options)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T | null> {\n return this.getRepository<T>().findOneBy(where)\n }\n\n /**\n * Finds first entity that matches given options.\n *\n * @deprecated use `findOneBy` method instead in conjunction with `In` operator, for example:\n *\n * .findOneBy({\n * id: 1 // where \"id\" is your primary column name\n * })\n */\n static findOneById<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n id: string | number | Date | ObjectId,\n ): Promise<T | null> {\n return this.getRepository<T>().findOneById(id)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneOrFail<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options: FindOneOptions<T>,\n ): Promise<T> {\n return this.getRepository<T>().findOneOrFail(options)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneByOrFail<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T> {\n return this.getRepository<T>().findOneByOrFail(where)\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>(\n this: { new (): T } & typeof BaseEntity,\n query: string,\n parameters?: any[],\n ): Promise<any> {\n return this.getRepository<T>().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>(\n this: { new (): T } & typeof BaseEntity,\n ): Promise<void> {\n return this.getRepository<T>().clear()\n }\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/repository/BaseEntity.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAMjD;;GAEG;AACH,MAAM,OAAO,UAAU;IAUnB,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;;OAGG;IACH,KAAK;QACD,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC,CAAA;QACxD,OAAO,UAAU,CAAC,aAAa,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACjD,CAAC;IAED;;;OAGG;IACH,IAAI,CAAC,OAAqB;QACtB,MAAM,UAAU,GAAG,IAAI,CAAC,WAAgC,CAAA;QACxD,OAAO,UAAU,CAAC,aAAa,EAAE,CAAC,IA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C;IAED;;;;;;;;;OASG;IACH,MAAM,CAAC,SAAS,CAEZ,GAAU;QAEV,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;IACjD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,OAAO,CAEV,OAA0B;QAE1B,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IACnD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,SAAS,CAEZ,KAA0B;QAE1B,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IACnD,CAAC;IAED;;;;;;;;OAQG;IACH,MAAM,CAAC,WAAW,CAEd,EAAqC;QAErC,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;IAClD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,aAAa,CAEhB,OAA0B;QAE1B,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;IACzD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,eAAe,CAElB,KAA0B;QAE1B,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,eAAe,CAAC,KAAK,CAAC,CAAA;IACzD,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,KAAK,CAER,KAAa,EACb,UAAkB;QAElB,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,KAAK,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;IAC3D,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK;QAGR,OAAO,IAAI,CAAC,aAAa,EAAK,CAAC,KAAK,EAAE,CAAA;IAC1C,CAAC;CACJ","file":"BaseEntity.js","sourcesContent":["import { Repository } from \"./Repository\"\nimport { FindOptionsWhere } from \"../find-options/FindOptionsWhere\"\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 { DataSource } from \"../data-source\"\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\"\nimport { EntityTarget } from \"../common/EntityTarget\"\nimport { PickKeysByType } from \"../common/PickKeysByType\"\n\n/**\n * Base abstract entity for all entities, used in ActiveRecord patterns.\n */\nexport class BaseEntity {\n // -------------------------------------------------------------------------\n // Private Static Properties\n // -------------------------------------------------------------------------\n\n /**\n * DataSource used in all static methods of the BaseEntity.\n */\n private static dataSource: DataSource | null\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 const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.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 const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().save(this, options)\n }\n\n /**\n * Removes current entity from the database.\n */\n remove(options?: RemoveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().remove(this, options) as Promise<this>\n }\n\n /**\n * Records the delete date of current entity.\n */\n softRemove(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().softRemove(this, options)\n }\n\n /**\n * Recovers a given entity in the database.\n */\n recover(options?: SaveOptions): Promise<this> {\n const baseEntity = this.constructor as typeof BaseEntity\n return baseEntity.getRepository().recover(this, options)\n }\n\n /**\n * Reloads entity data from the database.\n */\n async reload(): Promise<void> {\n const baseEntity = this.constructor as typeof BaseEntity\n const id = baseEntity.getRepository().metadata.getEntityIdMap(this)\n if (!id) {\n throw new Error(\n `Entity doesn't have id-s set, cannot reload entity`,\n )\n }\n const reloadedEntity: BaseEntity = await baseEntity\n .getRepository()\n .findOneByOrFail(id)\n\n ObjectUtils.assign(this, reloadedEntity)\n }\n\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Sets DataSource to be used by entity.\n */\n static useDataSource(dataSource: DataSource | null) {\n this.dataSource = dataSource\n }\n\n /**\n * Gets current entity's Repository.\n */\n static getRepository<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): Repository<T> {\n const dataSource = (this as typeof BaseEntity).dataSource\n if (!dataSource)\n throw new Error(`DataSource is not set for this entity.`)\n return dataSource.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(): EntityTarget<any> {\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>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n ): any {\n return this.getRepository<T>().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>(\n this: { new (): T } & typeof BaseEntity,\n alias?: string,\n ): SelectQueryBuilder<T> {\n return this.getRepository<T>().createQueryBuilder(alias)\n }\n\n /**\n * Creates a new entity instance.\n */\n static create<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ): 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>(\n this: { new (): T } & typeof BaseEntity,\n entityLikeArray: DeepPartial<T>[],\n ): 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>(\n this: { new (): T } & typeof BaseEntity,\n entityLike: DeepPartial<T>,\n ): 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>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities?: any,\n ) {\n return this.getRepository<T>().create(entityOrEntities)\n }\n\n /**\n * Merges multiple entities (or entity-like objects) into a given entity.\n */\n static merge<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n mergeIntoEntity: T,\n ...entityLikes: DeepPartial<T>[]\n ): T {\n return this.getRepository<T>().merge(\n mergeIntoEntity,\n ...entityLikes,\n ) as T\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>(\n this: { new (): T } & typeof BaseEntity,\n entityLike: DeepPartial<T>,\n ): Promise<T | undefined> {\n const thisRepository = this.getRepository<T>()\n return thisRepository.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>(\n this: { new (): T } & typeof BaseEntity,\n entities: DeepPartial<T>[],\n options?: SaveOptions,\n ): 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>(\n this: { new (): T } & typeof BaseEntity,\n entity: DeepPartial<T>,\n options?: SaveOptions,\n ): Promise<T>\n\n /**\n * Saves one or many given entities.\n */\n static save<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: DeepPartial<T> | DeepPartial<T>[],\n options?: SaveOptions,\n ) {\n return this.getRepository<T>().save(entityOrEntities as any, options)\n }\n\n /**\n * Removes a given entities from the database.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: T[],\n options?: RemoveOptions,\n ): Promise<T[]>\n\n /**\n * Removes a given entity from the database.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n options?: RemoveOptions,\n ): Promise<T>\n\n /**\n * Removes one or many given entities.\n */\n static remove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: T | T[],\n options?: RemoveOptions,\n ) {\n return this.getRepository<T>().remove(entityOrEntities as any, options)\n }\n\n /**\n * Records the delete date of all given entities.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entities: T[],\n options?: SaveOptions,\n ): Promise<T[]>\n\n /**\n * Records the delete date of a given entity.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entity: T,\n options?: SaveOptions,\n ): Promise<T>\n\n /**\n * Records the delete date of one or many given entities.\n */\n static softRemove<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ) {\n return this.getRepository<T>().softRemove(\n entityOrEntities as any,\n options,\n )\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>(\n this: { new (): T } & typeof BaseEntity,\n entity: QueryDeepPartialEntity<T> | QueryDeepPartialEntity<T>[],\n ): Promise<InsertResult> {\n return this.getRepository<T>().insert(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 static update<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectId\n | ObjectId[]\n | FindOptionsWhere<T>,\n partialEntity: QueryDeepPartialEntity<T>,\n ): Promise<UpdateResult> {\n return this.getRepository<T>().update(criteria, 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 static upsert<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n entityOrEntities:\n | QueryDeepPartialEntity<T>\n | QueryDeepPartialEntity<T>[],\n conflictPathsOrOptions: string[] | UpsertOptions<T>,\n ): Promise<InsertResult> {\n return this.getRepository<T>().upsert(\n entityOrEntities,\n conflictPathsOrOptions,\n )\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>(\n this: { new (): T } & typeof BaseEntity,\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectId\n | ObjectId[]\n | FindOptionsWhere<T>,\n ): Promise<DeleteResult> {\n return this.getRepository<T>().delete(criteria)\n }\n\n /**\n * Counts entities that match given options.\n */\n static count<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<number> {\n return this.getRepository<T>().count(options)\n }\n\n /**\n * Counts entities that match given WHERE conditions.\n */\n static countBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<number> {\n return this.getRepository<T>().countBy(where)\n }\n\n /**\n * Return the SUM of a column\n */\n static sum<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n columnName: PickKeysByType<T, number>,\n where: FindOptionsWhere<T>,\n ): Promise<number | null> {\n return this.getRepository<T>().sum(columnName, where)\n }\n\n /**\n * Return the AVG of a column\n */\n static average<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n columnName: PickKeysByType<T, number>,\n where: FindOptionsWhere<T>,\n ): Promise<number | null> {\n return this.getRepository<T>().average(columnName, where)\n }\n\n /**\n * Return the MIN of a column\n */\n static minimum<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n columnName: PickKeysByType<T, number>,\n where: FindOptionsWhere<T>,\n ): Promise<number | null> {\n return this.getRepository<T>().minimum(columnName, where)\n }\n\n /**\n * Return the MAX of a column\n */\n static maximum<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n columnName: PickKeysByType<T, number>,\n where: FindOptionsWhere<T>,\n ): Promise<number | null> {\n return this.getRepository<T>().maximum(columnName, where)\n }\n\n /**\n * Finds entities that match given options.\n */\n static find<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<T[]> {\n return this.getRepository<T>().find(options)\n }\n\n /**\n * Finds entities that match given WHERE conditions.\n */\n static findBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T[]> {\n return this.getRepository<T>().findBy(where)\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>(\n this: { new (): T } & typeof BaseEntity,\n options?: FindManyOptions<T>,\n ): Promise<[T[], number]> {\n return this.getRepository<T>().findAndCount(options)\n }\n\n /**\n * Finds entities that match given WHERE conditions.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n static findAndCountBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<[T[], number]> {\n return this.getRepository<T>().findAndCountBy(where)\n }\n\n /**\n * Finds entities by ids.\n * Optionally find options can be applied.\n *\n * @deprecated use `findBy` method instead in conjunction with `In` operator, for example:\n *\n * .findBy({\n * id: In([1, 2, 3])\n * })\n */\n static findByIds<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n ids: any[],\n ): Promise<T[]> {\n return this.getRepository<T>().findByIds(ids)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOne<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options: FindOneOptions<T>,\n ): Promise<T | null> {\n return this.getRepository<T>().findOne(options)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneBy<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T | null> {\n return this.getRepository<T>().findOneBy(where)\n }\n\n /**\n * Finds first entity that matches given options.\n *\n * @deprecated use `findOneBy` method instead in conjunction with `In` operator, for example:\n *\n * .findOneBy({\n * id: 1 // where \"id\" is your primary column name\n * })\n */\n static findOneById<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n id: string | number | Date | ObjectId,\n ): Promise<T | null> {\n return this.getRepository<T>().findOneById(id)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneOrFail<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n options: FindOneOptions<T>,\n ): Promise<T> {\n return this.getRepository<T>().findOneOrFail(options)\n }\n\n /**\n * Finds first entity that matches given conditions.\n */\n static findOneByOrFail<T extends BaseEntity>(\n this: { new (): T } & typeof BaseEntity,\n where: FindOptionsWhere<T>,\n ): Promise<T> {\n return this.getRepository<T>().findOneByOrFail(where)\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>(\n this: { new (): T } & typeof BaseEntity,\n query: string,\n parameters?: any[],\n ): Promise<any> {\n return this.getRepository<T>().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>(\n this: { new (): T } & typeof BaseEntity,\n ): Promise<void> {\n return this.getRepository<T>().clear()\n }\n}\n"],"sourceRoot":".."}
|
|
@@ -194,21 +194,9 @@ export declare class Repository<Entity extends ObjectLiteral> {
|
|
|
194
194
|
*/
|
|
195
195
|
restore(criteria: string | string[] | number | number[] | Date | Date[] | ObjectId | ObjectId[] | FindOptionsWhere<Entity>): Promise<UpdateResult>;
|
|
196
196
|
/**
|
|
197
|
-
* Checks whether any entity exists that
|
|
198
|
-
*
|
|
199
|
-
* @deprecated use `exists` method instead, for example:
|
|
200
|
-
*
|
|
201
|
-
* .exists()
|
|
197
|
+
* Checks whether any entity exists that match given options.
|
|
202
198
|
*/
|
|
203
199
|
exist(options?: FindManyOptions<Entity>): Promise<boolean>;
|
|
204
|
-
/**
|
|
205
|
-
* Checks whether any entity exists that matches the given options.
|
|
206
|
-
*/
|
|
207
|
-
exists(options?: FindManyOptions<Entity>): Promise<boolean>;
|
|
208
|
-
/**
|
|
209
|
-
* Checks whether any entity exists that matches the given conditions.
|
|
210
|
-
*/
|
|
211
|
-
existsBy(where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[]): Promise<boolean>;
|
|
212
200
|
/**
|
|
213
201
|
* Counts entities that match given options.
|
|
214
202
|
* Useful for pagination.
|
|
@@ -144,27 +144,11 @@ export class Repository {
|
|
|
144
144
|
return this.manager.restore(this.metadata.target, criteria);
|
|
145
145
|
}
|
|
146
146
|
/**
|
|
147
|
-
* Checks whether any entity exists that
|
|
148
|
-
*
|
|
149
|
-
* @deprecated use `exists` method instead, for example:
|
|
150
|
-
*
|
|
151
|
-
* .exists()
|
|
147
|
+
* Checks whether any entity exists that match given options.
|
|
152
148
|
*/
|
|
153
149
|
exist(options) {
|
|
154
150
|
return this.manager.exists(this.metadata.target, options);
|
|
155
151
|
}
|
|
156
|
-
/**
|
|
157
|
-
* Checks whether any entity exists that matches the given options.
|
|
158
|
-
*/
|
|
159
|
-
exists(options) {
|
|
160
|
-
return this.manager.exists(this.metadata.target, options);
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Checks whether any entity exists that matches the given conditions.
|
|
164
|
-
*/
|
|
165
|
-
existsBy(where) {
|
|
166
|
-
return this.manager.existsBy(this.metadata.target, where);
|
|
167
|
-
}
|
|
168
152
|
/**
|
|
169
153
|
* Counts entities that match given options.
|
|
170
154
|
* Useful for pagination.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/repository/Repository.ts"],"names":[],"mappings":"AAmBA;;GAEG;AACH,MAAM,OAAO,UAAU;IAsBnB,4EAA4E;IAC5E,YAAY;IACZ,4EAA4E;IAE5E;;OAEG;IACH,IAAI,QAAQ;QACR,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC3D,CAAC;IAED,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YACI,MAA4B,EAC5B,OAAsB,EACtB,WAAyB;QAEzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;IAClC,CAAC;IAED,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,kBAAkB,CACd,KAAc,EACd,WAAyB;QAEzB,OAAO,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAClC,IAAI,CAAC,QAAQ,CAAC,MAAa,EAC3B,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,EACjC,WAAW,IAAI,IAAI,CAAC,WAAW,CAClC,CAAA;IACL,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,MAAc;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IA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,CAAC,MAAM,EACpB,UAAU,EACV,YAAY,EACZ,KAAK,CACR,CAAA;IACL,CAAC;IAED;;OAEG;IACH,MAAM,CACF,OAA6D;QAE7D,WAAW;QACX,eAAe;QACf,gBAAgB;QAChB,KAAK;QACL,MAAM,QAAQ,GAAQ,IAAI,CAAC,WAAW,CAAA;QACtC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,IAAI,CAAA;QAC7C,MAAM,UAAU,GAAG,KAAM,SAAQ,QAAQ;YACrC,YACI,MAA4B,EAC5B,OAAsB,EACtB,WAAyB;gBAEzB,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC,CAAA;YACvC,CAAC;SACJ,CAAA;QACD,KAAK,MAAM,MAAM,IAAI,OAAO;YACxB,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;QAClD,OAAO,IAAI,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,CAAQ,CAAA;IAC9D,CAAC;CACJ","file":"Repository.js","sourcesContent":["import { 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 { FindOptionsWhere } from \"../find-options/FindOptionsWhere\"\nimport { UpsertOptions } from \"./UpsertOptions\"\nimport { EntityTarget } from \"../common/EntityTarget\"\nimport { PickKeysByType } from \"../common/PickKeysByType\"\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 // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Entity target 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 readonly target: EntityTarget<Entity>\n\n /**\n * Entity Manager used by this repository.\n */\n readonly manager: EntityManager\n\n /**\n * Query runner provider used for this repository.\n */\n readonly queryRunner?: QueryRunner\n\n // -------------------------------------------------------------------------\n // Accessors\n // -------------------------------------------------------------------------\n\n /**\n * Entity metadata of the entity current repository manages.\n */\n get metadata() {\n return this.manager.connection.getMetadata(this.target)\n }\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(\n target: EntityTarget<Entity>,\n manager: EntityManager,\n queryRunner?: QueryRunner,\n ) {\n this.target = target\n this.manager = manager\n this.queryRunner = queryRunner\n }\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(\n alias?: string,\n queryRunner?: QueryRunner,\n ): SelectQueryBuilder<Entity> {\n return this.manager.createQueryBuilder<Entity>(\n this.metadata.target as any,\n alias || this.metadata.targetName,\n queryRunner || this.queryRunner,\n )\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(\n plainEntityLikeOrPlainEntityLikes?:\n | DeepPartial<Entity>\n | DeepPartial<Entity>[],\n ): Entity | Entity[] {\n return this.manager.create<any>(\n this.metadata.target as any,\n plainEntityLikeOrPlainEntityLikes as any,\n )\n }\n\n /**\n * Merges multiple entities (or entity-like objects) into a given entity.\n */\n merge(\n mergeIntoEntity: Entity,\n ...entityLikes: DeepPartial<Entity>[]\n ): Entity {\n return this.manager.merge(\n this.metadata.target as any,\n mergeIntoEntity,\n ...entityLikes,\n )\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>>(\n entities: T[],\n options: SaveOptions & { reload: false },\n ): 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>>(\n entities: T[],\n options?: SaveOptions,\n ): 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>>(\n entity: T,\n options: SaveOptions & { reload: false },\n ): 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>>(\n entity: T,\n options?: SaveOptions,\n ): Promise<T & Entity>\n\n /**\n * Saves one or many given entities.\n */\n save<T extends DeepPartial<Entity>>(\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ): Promise<T | T[]> {\n return this.manager.save<Entity, T>(\n this.metadata.target as any,\n entityOrEntities as any,\n options,\n )\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(\n entityOrEntities: Entity | Entity[],\n options?: RemoveOptions,\n ): Promise<Entity | Entity[]> {\n return this.manager.remove(\n this.metadata.target as any,\n entityOrEntities as any,\n options,\n )\n }\n\n /**\n * Records the delete date of all given entities.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entities: T[],\n options: SaveOptions & { reload: false },\n ): Promise<T[]>\n\n /**\n * Records the delete date of all given entities.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entities: T[],\n options?: SaveOptions,\n ): Promise<(T & Entity)[]>\n\n /**\n * Records the delete date of a given entity.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entity: T,\n options: SaveOptions & { reload: false },\n ): Promise<T>\n\n /**\n * Records the delete date of a given entity.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entity: T,\n options?: SaveOptions,\n ): Promise<T & Entity>\n\n /**\n * Records the delete date of one or many given entities.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ): Promise<T | T[]> {\n return this.manager.softRemove<Entity, T>(\n this.metadata.target as any,\n entityOrEntities as any,\n options,\n )\n }\n\n /**\n * Recovers all given entities in the database.\n */\n recover<T extends DeepPartial<Entity>>(\n entities: T[],\n options: SaveOptions & { reload: false },\n ): Promise<T[]>\n\n /**\n * Recovers all given entities in the database.\n */\n recover<T extends DeepPartial<Entity>>(\n entities: T[],\n options?: SaveOptions,\n ): Promise<(T & Entity)[]>\n\n /**\n * Recovers a given entity in the database.\n */\n recover<T extends DeepPartial<Entity>>(\n entity: T,\n options: SaveOptions & { reload: false },\n ): Promise<T>\n\n /**\n * Recovers a given entity in the database.\n */\n recover<T extends DeepPartial<Entity>>(\n entity: T,\n options?: SaveOptions,\n ): Promise<T & Entity>\n\n /**\n * Recovers one or many given entities.\n */\n recover<T extends DeepPartial<Entity>>(\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ): Promise<T | T[]> {\n return this.manager.recover<Entity, T>(\n this.metadata.target as any,\n entityOrEntities as any,\n options,\n )\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(\n entity:\n | QueryDeepPartialEntity<Entity>\n | QueryDeepPartialEntity<Entity>[],\n ): 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(\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectId\n | ObjectId[]\n | FindOptionsWhere<Entity>,\n partialEntity: QueryDeepPartialEntity<Entity>,\n ): Promise<UpdateResult> {\n return this.manager.update(\n this.metadata.target as any,\n criteria as any,\n partialEntity,\n )\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:\n | QueryDeepPartialEntity<Entity>\n | QueryDeepPartialEntity<Entity>[],\n conflictPathsOrOptions: string[] | UpsertOptions<Entity>,\n ): Promise<InsertResult> {\n return this.manager.upsert(\n this.metadata.target as any,\n entityOrEntities,\n conflictPathsOrOptions,\n )\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(\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectId\n | ObjectId[]\n | FindOptionsWhere<Entity>,\n ): 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(\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectId\n | ObjectId[]\n | FindOptionsWhere<Entity>,\n ): Promise<UpdateResult> {\n return this.manager.softDelete(\n this.metadata.target as any,\n criteria as any,\n )\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(\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectId\n | ObjectId[]\n | FindOptionsWhere<Entity>,\n ): Promise<UpdateResult> {\n return this.manager.restore(\n this.metadata.target as any,\n criteria as any,\n )\n }\n\n /**\n * Checks whether any entity exists that matches the given options.\n *\n * @deprecated use `exists` method instead, for example:\n *\n * .exists()\n */\n exist(options?: FindManyOptions<Entity>): Promise<boolean> {\n return this.manager.exists(this.metadata.target, options)\n }\n\n /**\n * Checks whether any entity exists that matches the given options.\n */\n exists(options?: FindManyOptions<Entity>): Promise<boolean> {\n return this.manager.exists(this.metadata.target, options)\n }\n\n /**\n * Checks whether any entity exists that matches the given conditions.\n */\n existsBy(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<boolean> {\n return this.manager.existsBy(this.metadata.target, where)\n }\n\n /**\n * Counts entities that match given options.\n * Useful for pagination.\n */\n count(options?: FindManyOptions<Entity>): Promise<number> {\n return this.manager.count(this.metadata.target, options)\n }\n\n /**\n * Counts entities that match given conditions.\n * Useful for pagination.\n */\n countBy(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<number> {\n return this.manager.countBy(this.metadata.target, where)\n }\n\n /**\n * Return the SUM of a column\n */\n sum(\n columnName: PickKeysByType<Entity, number>,\n where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<number | null> {\n return this.manager.sum(this.metadata.target, columnName, where)\n }\n\n /**\n * Return the AVG of a column\n */\n average(\n columnName: PickKeysByType<Entity, number>,\n where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<number | null> {\n return this.manager.average(this.metadata.target, columnName, where)\n }\n\n /**\n * Return the MIN of a column\n */\n minimum(\n columnName: PickKeysByType<Entity, number>,\n where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<number | null> {\n return this.manager.minimum(this.metadata.target, columnName, where)\n }\n\n /**\n * Return the MAX of a column\n */\n maximum(\n columnName: PickKeysByType<Entity, number>,\n where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<number | null> {\n return this.manager.maximum(this.metadata.target, columnName, where)\n }\n\n /**\n * Finds entities that match given find options.\n */\n async find(options?: FindManyOptions<Entity>): Promise<Entity[]> {\n return this.manager.find(this.metadata.target, options)\n }\n\n /**\n * Finds entities that match given find options.\n */\n async findBy(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<Entity[]> {\n return this.manager.findBy(this.metadata.target, where)\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(\n options?: FindManyOptions<Entity>,\n ): Promise<[Entity[], number]> {\n return this.manager.findAndCount(this.metadata.target, options)\n }\n\n /**\n * Finds entities that match given WHERE conditions.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n findAndCountBy(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<[Entity[], number]> {\n return this.manager.findAndCountBy(this.metadata.target, where)\n }\n\n /**\n * Finds entities with ids.\n * Optionally find options or conditions can be applied.\n *\n * @deprecated use `findBy` method instead in conjunction with `In` operator, for example:\n *\n * .findBy({\n * id: In([1, 2, 3])\n * })\n */\n async findByIds(ids: any[]): Promise<Entity[]> {\n return this.manager.findByIds(this.metadata.target, ids)\n }\n\n /**\n * Finds first entity by a given find options.\n * If entity was not found in the database - returns null.\n */\n async findOne(options: FindOneOptions<Entity>): Promise<Entity | null> {\n return this.manager.findOne(this.metadata.target, options)\n }\n\n /**\n * Finds first entity that matches given where condition.\n * If entity was not found in the database - returns null.\n */\n async findOneBy(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<Entity | null> {\n return this.manager.findOneBy(this.metadata.target, where)\n }\n\n /**\n * Finds first entity that matches given id.\n * If entity was not found in the database - returns null.\n *\n * @deprecated use `findOneBy` method instead in conjunction with `In` operator, for example:\n *\n * .findOneBy({\n * id: 1 // where \"id\" is your primary column name\n * })\n */\n async findOneById(\n id: number | string | Date | ObjectId,\n ): Promise<Entity | null> {\n return this.manager.findOneById(this.metadata.target, id)\n }\n\n /**\n * Finds first entity by a given find options.\n * If entity was not found in the database - rejects with error.\n */\n async findOneOrFail(options: FindOneOptions<Entity>): Promise<Entity> {\n return this.manager.findOneOrFail(this.metadata.target, options)\n }\n\n /**\n * Finds first entity that matches given where condition.\n * If entity was not found in the database - rejects with error.\n */\n async findOneByOrFail(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<Entity> {\n return this.manager.findOneByOrFail(this.metadata.target, where)\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(\n conditions: FindOptionsWhere<Entity>,\n propertyPath: string,\n value: number | string,\n ): Promise<UpdateResult> {\n return this.manager.increment(\n this.metadata.target,\n conditions,\n propertyPath,\n value,\n )\n }\n\n /**\n * Decrements some column by provided value of the entities matched given conditions.\n */\n decrement(\n conditions: FindOptionsWhere<Entity>,\n propertyPath: string,\n value: number | string,\n ): Promise<UpdateResult> {\n return this.manager.decrement(\n this.metadata.target,\n conditions,\n propertyPath,\n value,\n )\n }\n\n /**\n * Extends repository with provided functions.\n */\n extend<CustomRepository>(\n customs: CustomRepository & ThisType<this & CustomRepository>,\n ): this & CustomRepository {\n // return {\n // ...this,\n // ...custom\n // };\n const thisRepo: any = this.constructor\n const { target, manager, queryRunner } = this\n const ChildClass = class extends thisRepo {\n constructor(\n target: EntityTarget<Entity>,\n manager: EntityManager,\n queryRunner?: QueryRunner,\n ) {\n super(target, manager, queryRunner)\n }\n }\n for (const custom in customs)\n ChildClass.prototype[custom] = customs[custom]\n return new ChildClass(target, manager, queryRunner) as any\n }\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/repository/Repository.ts"],"names":[],"mappings":"AAmBA;;GAEG;AACH,MAAM,OAAO,UAAU;IAsBnB,4EAA4E;IAC5E,YAAY;IACZ,4EAA4E;IAE5E;;OAEG;IACH,IAAI,QAAQ;QACR,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC3D,CAAC;IAED,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YACI,MAA4B,EAC5B,OAAsB,EACtB,WAAyB;QAEzB,IAAI,CAAC,MAAM,G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EACV,YAAY,EACZ,KAAK,CACR,CAAA;IACL,CAAC;IAED;;OAEG;IACH,SAAS,CACL,UAAoC,EACpC,YAAoB,EACpB,KAAsB;QAEtB,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CACzB,IAAI,CAAC,QAAQ,CAAC,MAAM,EACpB,UAAU,EACV,YAAY,EACZ,KAAK,CACR,CAAA;IACL,CAAC;IAED;;OAEG;IACH,MAAM,CACF,OAA6D;QAE7D,WAAW;QACX,eAAe;QACf,gBAAgB;QAChB,KAAK;QACL,MAAM,QAAQ,GAAQ,IAAI,CAAC,WAAW,CAAA;QACtC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,IAAI,CAAA;QAC7C,MAAM,UAAU,GAAG,KAAM,SAAQ,QAAQ;YACrC,YACI,MAA4B,EAC5B,OAAsB,EACtB,WAAyB;gBAEzB,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC,CAAA;YACvC,CAAC;SACJ,CAAA;QACD,KAAK,MAAM,MAAM,IAAI,OAAO;YACxB,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;QAClD,OAAO,IAAI,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,CAAQ,CAAA;IAC9D,CAAC;CACJ","file":"Repository.js","sourcesContent":["import { 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 { FindOptionsWhere } from \"../find-options/FindOptionsWhere\"\nimport { UpsertOptions } from \"./UpsertOptions\"\nimport { EntityTarget } from \"../common/EntityTarget\"\nimport { PickKeysByType } from \"../common/PickKeysByType\"\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 // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Entity target 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 readonly target: EntityTarget<Entity>\n\n /**\n * Entity Manager used by this repository.\n */\n readonly manager: EntityManager\n\n /**\n * Query runner provider used for this repository.\n */\n readonly queryRunner?: QueryRunner\n\n // -------------------------------------------------------------------------\n // Accessors\n // -------------------------------------------------------------------------\n\n /**\n * Entity metadata of the entity current repository manages.\n */\n get metadata() {\n return this.manager.connection.getMetadata(this.target)\n }\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(\n target: EntityTarget<Entity>,\n manager: EntityManager,\n queryRunner?: QueryRunner,\n ) {\n this.target = target\n this.manager = manager\n this.queryRunner = queryRunner\n }\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(\n alias?: string,\n queryRunner?: QueryRunner,\n ): SelectQueryBuilder<Entity> {\n return this.manager.createQueryBuilder<Entity>(\n this.metadata.target as any,\n alias || this.metadata.targetName,\n queryRunner || this.queryRunner,\n )\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(\n plainEntityLikeOrPlainEntityLikes?:\n | DeepPartial<Entity>\n | DeepPartial<Entity>[],\n ): Entity | Entity[] {\n return this.manager.create<any>(\n this.metadata.target as any,\n plainEntityLikeOrPlainEntityLikes as any,\n )\n }\n\n /**\n * Merges multiple entities (or entity-like objects) into a given entity.\n */\n merge(\n mergeIntoEntity: Entity,\n ...entityLikes: DeepPartial<Entity>[]\n ): Entity {\n return this.manager.merge(\n this.metadata.target as any,\n mergeIntoEntity,\n ...entityLikes,\n )\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>>(\n entities: T[],\n options: SaveOptions & { reload: false },\n ): 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>>(\n entities: T[],\n options?: SaveOptions,\n ): 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>>(\n entity: T,\n options: SaveOptions & { reload: false },\n ): 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>>(\n entity: T,\n options?: SaveOptions,\n ): Promise<T & Entity>\n\n /**\n * Saves one or many given entities.\n */\n save<T extends DeepPartial<Entity>>(\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ): Promise<T | T[]> {\n return this.manager.save<Entity, T>(\n this.metadata.target as any,\n entityOrEntities as any,\n options,\n )\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(\n entityOrEntities: Entity | Entity[],\n options?: RemoveOptions,\n ): Promise<Entity | Entity[]> {\n return this.manager.remove(\n this.metadata.target as any,\n entityOrEntities as any,\n options,\n )\n }\n\n /**\n * Records the delete date of all given entities.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entities: T[],\n options: SaveOptions & { reload: false },\n ): Promise<T[]>\n\n /**\n * Records the delete date of all given entities.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entities: T[],\n options?: SaveOptions,\n ): Promise<(T & Entity)[]>\n\n /**\n * Records the delete date of a given entity.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entity: T,\n options: SaveOptions & { reload: false },\n ): Promise<T>\n\n /**\n * Records the delete date of a given entity.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entity: T,\n options?: SaveOptions,\n ): Promise<T & Entity>\n\n /**\n * Records the delete date of one or many given entities.\n */\n softRemove<T extends DeepPartial<Entity>>(\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ): Promise<T | T[]> {\n return this.manager.softRemove<Entity, T>(\n this.metadata.target as any,\n entityOrEntities as any,\n options,\n )\n }\n\n /**\n * Recovers all given entities in the database.\n */\n recover<T extends DeepPartial<Entity>>(\n entities: T[],\n options: SaveOptions & { reload: false },\n ): Promise<T[]>\n\n /**\n * Recovers all given entities in the database.\n */\n recover<T extends DeepPartial<Entity>>(\n entities: T[],\n options?: SaveOptions,\n ): Promise<(T & Entity)[]>\n\n /**\n * Recovers a given entity in the database.\n */\n recover<T extends DeepPartial<Entity>>(\n entity: T,\n options: SaveOptions & { reload: false },\n ): Promise<T>\n\n /**\n * Recovers a given entity in the database.\n */\n recover<T extends DeepPartial<Entity>>(\n entity: T,\n options?: SaveOptions,\n ): Promise<T & Entity>\n\n /**\n * Recovers one or many given entities.\n */\n recover<T extends DeepPartial<Entity>>(\n entityOrEntities: T | T[],\n options?: SaveOptions,\n ): Promise<T | T[]> {\n return this.manager.recover<Entity, T>(\n this.metadata.target as any,\n entityOrEntities as any,\n options,\n )\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(\n entity:\n | QueryDeepPartialEntity<Entity>\n | QueryDeepPartialEntity<Entity>[],\n ): 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(\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectId\n | ObjectId[]\n | FindOptionsWhere<Entity>,\n partialEntity: QueryDeepPartialEntity<Entity>,\n ): Promise<UpdateResult> {\n return this.manager.update(\n this.metadata.target as any,\n criteria as any,\n partialEntity,\n )\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:\n | QueryDeepPartialEntity<Entity>\n | QueryDeepPartialEntity<Entity>[],\n conflictPathsOrOptions: string[] | UpsertOptions<Entity>,\n ): Promise<InsertResult> {\n return this.manager.upsert(\n this.metadata.target as any,\n entityOrEntities,\n conflictPathsOrOptions,\n )\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(\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectId\n | ObjectId[]\n | FindOptionsWhere<Entity>,\n ): 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(\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectId\n | ObjectId[]\n | FindOptionsWhere<Entity>,\n ): Promise<UpdateResult> {\n return this.manager.softDelete(\n this.metadata.target as any,\n criteria as any,\n )\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(\n criteria:\n | string\n | string[]\n | number\n | number[]\n | Date\n | Date[]\n | ObjectId\n | ObjectId[]\n | FindOptionsWhere<Entity>,\n ): Promise<UpdateResult> {\n return this.manager.restore(\n this.metadata.target as any,\n criteria as any,\n )\n }\n\n /**\n * Checks whether any entity exists that match given options.\n */\n exist(options?: FindManyOptions<Entity>): Promise<boolean> {\n return this.manager.exists(this.metadata.target, options)\n }\n\n /**\n * Counts entities that match given options.\n * Useful for pagination.\n */\n count(options?: FindManyOptions<Entity>): Promise<number> {\n return this.manager.count(this.metadata.target, options)\n }\n\n /**\n * Counts entities that match given conditions.\n * Useful for pagination.\n */\n countBy(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<number> {\n return this.manager.countBy(this.metadata.target, where)\n }\n\n /**\n * Return the SUM of a column\n */\n sum(\n columnName: PickKeysByType<Entity, number>,\n where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<number | null> {\n return this.manager.sum(this.metadata.target, columnName, where)\n }\n\n /**\n * Return the AVG of a column\n */\n average(\n columnName: PickKeysByType<Entity, number>,\n where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<number | null> {\n return this.manager.average(this.metadata.target, columnName, where)\n }\n\n /**\n * Return the MIN of a column\n */\n minimum(\n columnName: PickKeysByType<Entity, number>,\n where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<number | null> {\n return this.manager.minimum(this.metadata.target, columnName, where)\n }\n\n /**\n * Return the MAX of a column\n */\n maximum(\n columnName: PickKeysByType<Entity, number>,\n where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<number | null> {\n return this.manager.maximum(this.metadata.target, columnName, where)\n }\n\n /**\n * Finds entities that match given find options.\n */\n async find(options?: FindManyOptions<Entity>): Promise<Entity[]> {\n return this.manager.find(this.metadata.target, options)\n }\n\n /**\n * Finds entities that match given find options.\n */\n async findBy(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<Entity[]> {\n return this.manager.findBy(this.metadata.target, where)\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(\n options?: FindManyOptions<Entity>,\n ): Promise<[Entity[], number]> {\n return this.manager.findAndCount(this.metadata.target, options)\n }\n\n /**\n * Finds entities that match given WHERE conditions.\n * Also counts all entities that match given conditions,\n * but ignores pagination settings (from and take options).\n */\n findAndCountBy(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<[Entity[], number]> {\n return this.manager.findAndCountBy(this.metadata.target, where)\n }\n\n /**\n * Finds entities with ids.\n * Optionally find options or conditions can be applied.\n *\n * @deprecated use `findBy` method instead in conjunction with `In` operator, for example:\n *\n * .findBy({\n * id: In([1, 2, 3])\n * })\n */\n async findByIds(ids: any[]): Promise<Entity[]> {\n return this.manager.findByIds(this.metadata.target, ids)\n }\n\n /**\n * Finds first entity by a given find options.\n * If entity was not found in the database - returns null.\n */\n async findOne(options: FindOneOptions<Entity>): Promise<Entity | null> {\n return this.manager.findOne(this.metadata.target, options)\n }\n\n /**\n * Finds first entity that matches given where condition.\n * If entity was not found in the database - returns null.\n */\n async findOneBy(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<Entity | null> {\n return this.manager.findOneBy(this.metadata.target, where)\n }\n\n /**\n * Finds first entity that matches given id.\n * If entity was not found in the database - returns null.\n *\n * @deprecated use `findOneBy` method instead in conjunction with `In` operator, for example:\n *\n * .findOneBy({\n * id: 1 // where \"id\" is your primary column name\n * })\n */\n async findOneById(\n id: number | string | Date | ObjectId,\n ): Promise<Entity | null> {\n return this.manager.findOneById(this.metadata.target, id)\n }\n\n /**\n * Finds first entity by a given find options.\n * If entity was not found in the database - rejects with error.\n */\n async findOneOrFail(options: FindOneOptions<Entity>): Promise<Entity> {\n return this.manager.findOneOrFail(this.metadata.target, options)\n }\n\n /**\n * Finds first entity that matches given where condition.\n * If entity was not found in the database - rejects with error.\n */\n async findOneByOrFail(\n where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n ): Promise<Entity> {\n return this.manager.findOneByOrFail(this.metadata.target, where)\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(\n conditions: FindOptionsWhere<Entity>,\n propertyPath: string,\n value: number | string,\n ): Promise<UpdateResult> {\n return this.manager.increment(\n this.metadata.target,\n conditions,\n propertyPath,\n value,\n )\n }\n\n /**\n * Decrements some column by provided value of the entities matched given conditions.\n */\n decrement(\n conditions: FindOptionsWhere<Entity>,\n propertyPath: string,\n value: number | string,\n ): Promise<UpdateResult> {\n return this.manager.decrement(\n this.metadata.target,\n conditions,\n propertyPath,\n value,\n )\n }\n\n /**\n * Extends repository with provided functions.\n */\n extend<CustomRepository>(\n customs: CustomRepository & ThisType<this & CustomRepository>,\n ): this & CustomRepository {\n // return {\n // ...this,\n // ...custom\n // };\n const thisRepo: any = this.constructor\n const { target, manager, queryRunner } = this\n const ChildClass = class extends thisRepo {\n constructor(\n target: EntityTarget<Entity>,\n manager: EntityManager,\n queryRunner?: QueryRunner,\n ) {\n super(target, manager, queryRunner)\n }\n }\n for (const custom in customs)\n ChildClass.prototype[custom] = customs[custom]\n return new ChildClass(target, manager, queryRunner) as any\n }\n}\n"],"sourceRoot":".."}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { parseISO } from "date-fns";
|
|
2
2
|
/**
|
|
3
3
|
* Provides utilities to transform hydrated and persisted data.
|
|
4
4
|
*/
|
|
@@ -47,9 +47,7 @@ export class DateUtils {
|
|
|
47
47
|
*
|
|
48
48
|
* https://stackoverflow.com/a/2587398
|
|
49
49
|
*/
|
|
50
|
-
let date = typeof mixedDate === "string"
|
|
51
|
-
? dayjs(mixedDate).toDate()
|
|
52
|
-
: mixedDate;
|
|
50
|
+
let date = typeof mixedDate === "string" ? parseISO(mixedDate) : mixedDate;
|
|
53
51
|
if (toUtc)
|
|
54
52
|
date = new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getU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BAAyB;IACzB,4EAA4E;IAE5E;;OAEG;IACK,MAAM,CAAC,mBAAmB,CAAC,KAAa,EAAE,WAAW,GAAG,CAAC;QAC7D,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;QAEnC,OAAO,MAAM,CAAC,GAAG,GAAG,GAAG,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,CAAA;IACvD,CAAC;IAED;;OAEG;IACK,MAAM,CAAC,kBAAkB,CAAC,KAAa;QAC3C,IAAI,KAAK,GAAG,EAAE,EAAE;YACZ,OAAO,IAAI,GAAG,KAAK,CAAA;SACtB;aAAM,IAAI,KAAK,GAAG,GAAG,EAAE;YACpB,OAAO,GAAG,GAAG,KAAK,CAAA;SACrB;aAAM;YACH,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;SACvB;IACL,CAAC;CACJ","file":"DateUtils.js","sourcesContent":["import { ColumnMetadata } from \"../metadata/ColumnMetadata\"\nimport dayjs from \"dayjs\"\n\n/**\n * Provides utilities to transform hydrated and persisted data.\n */\nexport class DateUtils {\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Normalizes date object hydrated from the database.\n */\n static normalizeHydratedDate(\n mixedDate: Date | string | undefined,\n ): Date | string | undefined {\n if (!mixedDate) return mixedDate\n\n return typeof mixedDate === \"string\"\n ? new Date(mixedDate)\n : (mixedDate as Date)\n }\n\n /**\n * Converts given value into date string in a \"YYYY-MM-DD\" format.\n */\n static mixedDateToDateString(value: string | Date): string {\n if (value instanceof Date) {\n return (\n this.formatZerolessValue(value.getFullYear(), 4) +\n \"-\" +\n this.formatZerolessValue(value.getMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getDate())\n )\n }\n\n return value\n }\n\n /**\n * Converts given value into date object.\n */\n static mixedDateToDate(\n mixedDate: Date | string,\n toUtc: boolean = false,\n useMilliseconds = true,\n ): Date {\n /**\n * new Date(ISOString) is not a reliable parser to date strings.\n * It's better to use 'date-fns' parser to parser string in ISO Format.\n *\n * The problem here is with wrong timezone.\n *\n * For example:\n *\n * ``new Date('2021-04-28')`` will generate `2021-04-28T00:00:00.000Z`\n * in my timezone, which is not true for my timezone (GMT-0300). It should\n * be `2021-04-28T03:00:00.000Z` as `new Date(2021, 3, 28)` generates.\n *\n * https://stackoverflow.com/a/2587398\n */\n let date =\n typeof mixedDate === \"string\"\n ? dayjs(mixedDate).toDate()\n : mixedDate\n\n if (toUtc)\n date = new Date(\n date.getUTCFullYear(),\n date.getUTCMonth(),\n date.getUTCDate(),\n date.getUTCHours(),\n date.getUTCMinutes(),\n date.getUTCSeconds(),\n date.getUTCMilliseconds(),\n )\n\n if (!useMilliseconds) date.setUTCMilliseconds(0)\n\n return date\n }\n\n /**\n * Converts given value into time string in a \"HH:mm:ss\" format.\n */\n static mixedDateToTimeString(\n value: Date | any,\n skipSeconds: boolean = false,\n ): string | any {\n if (value instanceof Date)\n return (\n this.formatZerolessValue(value.getHours()) +\n \":\" +\n this.formatZerolessValue(value.getMinutes()) +\n (!skipSeconds\n ? \":\" + this.formatZerolessValue(value.getSeconds())\n : \"\")\n )\n\n return value\n }\n\n /**\n * Converts given value into time string in a \"HH:mm:ss\" format.\n */\n static mixedTimeToDate(value: Date | any): string | any {\n if (typeof value === \"string\") {\n const [hours, minutes, seconds] = value.split(\":\")\n const date = new Date()\n if (hours) date.setHours(parseInt(hours))\n if (minutes) date.setMinutes(parseInt(minutes))\n if (seconds) date.setSeconds(parseInt(seconds))\n return date\n }\n\n return value\n }\n\n /**\n * Converts given string value with \"-\" separator into a \"HH:mm:ss\" format.\n */\n static mixedTimeToString(\n value: string | any,\n skipSeconds: boolean = false,\n ): string | any {\n value =\n value instanceof Date\n ? value.getHours() +\n \":\" +\n value.getMinutes() +\n (!skipSeconds ? \":\" + value.getSeconds() : \"\")\n : value\n if (typeof value === \"string\") {\n return value\n .split(\":\")\n .map((v) => (v.length === 1 ? \"0\" + v : v)) // append zero at beginning if we have a first-zero-less number\n .join(\":\")\n }\n\n return value\n }\n\n /**\n * Converts given value into datetime string in a \"YYYY-MM-DD HH-mm-ss\" format.\n */\n static mixedDateToDatetimeString(\n value: Date | any,\n useMilliseconds?: boolean,\n ): string | any {\n if (typeof value === \"string\") {\n value = new Date(value)\n }\n if (value instanceof Date) {\n let finalValue =\n this.formatZerolessValue(value.getFullYear(), 4) +\n \"-\" +\n this.formatZerolessValue(value.getMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getDate()) +\n \" \" +\n this.formatZerolessValue(value.getHours()) +\n \":\" +\n this.formatZerolessValue(value.getMinutes()) +\n \":\" +\n this.formatZerolessValue(value.getSeconds())\n\n if (useMilliseconds)\n finalValue += `.${this.formatMilliseconds(\n value.getMilliseconds(),\n )}`\n\n value = finalValue\n }\n\n return value\n }\n\n /**\n * Converts given value into utc datetime string in a \"YYYY-MM-DD HH-mm-ss.sss\" format.\n */\n static mixedDateToUtcDatetimeString(value: Date | any): string | any {\n if (typeof value === \"string\") {\n value = new Date(value)\n }\n if (value instanceof Date) {\n return (\n this.formatZerolessValue(value.getUTCFullYear(), 4) +\n \"-\" +\n this.formatZerolessValue(value.getUTCMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getUTCDate()) +\n \" \" +\n this.formatZerolessValue(value.getUTCHours()) +\n \":\" +\n this.formatZerolessValue(value.getUTCMinutes()) +\n \":\" +\n this.formatZerolessValue(value.getUTCSeconds()) +\n \".\" +\n this.formatMilliseconds(value.getUTCMilliseconds())\n )\n }\n\n return value\n }\n\n /**\n * Converts each item in the given array to string joined by \",\" separator.\n */\n static simpleArrayToString(value: any[] | any): string[] | any {\n if (Array.isArray(value)) {\n return (value as any[]).map((i) => String(i)).join(\",\")\n }\n\n return value\n }\n\n /**\n * Converts given string to simple array split by \",\" separator.\n */\n static stringToSimpleArray(value: string | any): string | any {\n if (typeof value === \"string\") {\n if (value.length > 0) {\n return value.split(\",\")\n } else {\n return []\n }\n }\n\n return value\n }\n\n static simpleJsonToString(value: any): string {\n return JSON.stringify(value)\n }\n\n static stringToSimpleJson(value: any) {\n return typeof value === \"string\" ? JSON.parse(value) : value\n }\n\n static simpleEnumToString(value: any) {\n return \"\" + value\n }\n\n static stringToSimpleEnum(value: any, columnMetadata: ColumnMetadata) {\n if (\n columnMetadata.enum &&\n !isNaN(value) &&\n columnMetadata.enum.indexOf(parseInt(value)) >= 0\n ) {\n // convert to number if that exists in poosible enum options\n value = parseInt(value)\n }\n\n return value\n }\n\n // -------------------------------------------------------------------------\n // Private Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Formats given number to \"0x\" format, e.g. if the totalLength = 2 and the value is 1 then it will return \"01\".\n */\n private static formatZerolessValue(value: number, totalLength = 2): string {\n const pad = \"0\".repeat(totalLength)\n\n return String(`${pad}${value}`).slice(-totalLength)\n }\n\n /**\n * Formats given number to \"0x\" format, e.g. if it is 1 then it will return \"01\".\n */\n private static formatMilliseconds(value: number): string {\n if (value < 10) {\n return \"00\" + value\n } else if (value < 100) {\n return \"0\" + value\n } else {\n return String(value)\n }\n }\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/util/DateUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAEnC;;GAEG;AACH,MAAM,OAAO,SAAS;IAClB,4EAA4E;IAC5E,wBAAwB;IACxB,4EAA4E;IAE5E;;OAEG;IACH,MAAM,CAAC,qBAAqB,CACxB,SAAoC;QAEpC,IAAI,CAAC,SAAS;YAAE,OAAO,SAAS,CAAA;QAEhC,OAAO,OAAO,SAAS,KAAK,QAAQ;YAChC,CAAC,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC;YACrB,CAAC,CAAE,SAAkB,CAAA;IAC7B,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,qBAAqB,CAAC,KAAoB;QAC7C,IAAI,KAAK,YAAY,IAAI,EAAE;YACvB,OAAO,CACH,I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etadata\"\nimport { parseISO } from \"date-fns\"\n\n/**\n * Provides utilities to transform hydrated and persisted data.\n */\nexport class DateUtils {\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Normalizes date object hydrated from the database.\n */\n static normalizeHydratedDate(\n mixedDate: Date | string | undefined,\n ): Date | string | undefined {\n if (!mixedDate) return mixedDate\n\n return typeof mixedDate === \"string\"\n ? new Date(mixedDate)\n : (mixedDate as Date)\n }\n\n /**\n * Converts given value into date string in a \"YYYY-MM-DD\" format.\n */\n static mixedDateToDateString(value: string | Date): string {\n if (value instanceof Date) {\n return (\n this.formatZerolessValue(value.getFullYear(), 4) +\n \"-\" +\n this.formatZerolessValue(value.getMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getDate())\n )\n }\n\n return value\n }\n\n /**\n * Converts given value into date object.\n */\n static mixedDateToDate(\n mixedDate: Date | string,\n toUtc: boolean = false,\n useMilliseconds = true,\n ): Date {\n /**\n * new Date(ISOString) is not a reliable parser to date strings.\n * It's better to use 'date-fns' parser to parser string in ISO Format.\n *\n * The problem here is with wrong timezone.\n *\n * For example:\n *\n * ``new Date('2021-04-28')`` will generate `2021-04-28T00:00:00.000Z`\n * in my timezone, which is not true for my timezone (GMT-0300). It should\n * be `2021-04-28T03:00:00.000Z` as `new Date(2021, 3, 28)` generates.\n *\n * https://stackoverflow.com/a/2587398\n */\n let date =\n typeof mixedDate === \"string\" ? parseISO(mixedDate) : mixedDate\n\n if (toUtc)\n date = new Date(\n date.getUTCFullYear(),\n date.getUTCMonth(),\n date.getUTCDate(),\n date.getUTCHours(),\n date.getUTCMinutes(),\n date.getUTCSeconds(),\n date.getUTCMilliseconds(),\n )\n\n if (!useMilliseconds) date.setUTCMilliseconds(0)\n\n return date\n }\n\n /**\n * Converts given value into time string in a \"HH:mm:ss\" format.\n */\n static mixedDateToTimeString(\n value: Date | any,\n skipSeconds: boolean = false,\n ): string | any {\n if (value instanceof Date)\n return (\n this.formatZerolessValue(value.getHours()) +\n \":\" +\n this.formatZerolessValue(value.getMinutes()) +\n (!skipSeconds\n ? \":\" + this.formatZerolessValue(value.getSeconds())\n : \"\")\n )\n\n return value\n }\n\n /**\n * Converts given value into time string in a \"HH:mm:ss\" format.\n */\n static mixedTimeToDate(value: Date | any): string | any {\n if (typeof value === \"string\") {\n const [hours, minutes, seconds] = value.split(\":\")\n const date = new Date()\n if (hours) date.setHours(parseInt(hours))\n if (minutes) date.setMinutes(parseInt(minutes))\n if (seconds) date.setSeconds(parseInt(seconds))\n return date\n }\n\n return value\n }\n\n /**\n * Converts given string value with \"-\" separator into a \"HH:mm:ss\" format.\n */\n static mixedTimeToString(\n value: string | any,\n skipSeconds: boolean = false,\n ): string | any {\n value =\n value instanceof Date\n ? value.getHours() +\n \":\" +\n value.getMinutes() +\n (!skipSeconds ? \":\" + value.getSeconds() : \"\")\n : value\n if (typeof value === \"string\") {\n return value\n .split(\":\")\n .map((v) => (v.length === 1 ? \"0\" + v : v)) // append zero at beginning if we have a first-zero-less number\n .join(\":\")\n }\n\n return value\n }\n\n /**\n * Converts given value into datetime string in a \"YYYY-MM-DD HH-mm-ss\" format.\n */\n static mixedDateToDatetimeString(\n value: Date | any,\n useMilliseconds?: boolean,\n ): string | any {\n if (typeof value === \"string\") {\n value = new Date(value)\n }\n if (value instanceof Date) {\n let finalValue =\n this.formatZerolessValue(value.getFullYear(), 4) +\n \"-\" +\n this.formatZerolessValue(value.getMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getDate()) +\n \" \" +\n this.formatZerolessValue(value.getHours()) +\n \":\" +\n this.formatZerolessValue(value.getMinutes()) +\n \":\" +\n this.formatZerolessValue(value.getSeconds())\n\n if (useMilliseconds)\n finalValue += `.${this.formatMilliseconds(\n value.getMilliseconds(),\n )}`\n\n value = finalValue\n }\n\n return value\n }\n\n /**\n * Converts given value into utc datetime string in a \"YYYY-MM-DD HH-mm-ss.sss\" format.\n */\n static mixedDateToUtcDatetimeString(value: Date | any): string | any {\n if (typeof value === \"string\") {\n value = new Date(value)\n }\n if (value instanceof Date) {\n return (\n this.formatZerolessValue(value.getUTCFullYear(), 4) +\n \"-\" +\n this.formatZerolessValue(value.getUTCMonth() + 1) +\n \"-\" +\n this.formatZerolessValue(value.getUTCDate()) +\n \" \" +\n this.formatZerolessValue(value.getUTCHours()) +\n \":\" +\n this.formatZerolessValue(value.getUTCMinutes()) +\n \":\" +\n this.formatZerolessValue(value.getUTCSeconds()) +\n \".\" +\n this.formatMilliseconds(value.getUTCMilliseconds())\n )\n }\n\n return value\n }\n\n /**\n * Converts each item in the given array to string joined by \",\" separator.\n */\n static simpleArrayToString(value: any[] | any): string[] | any {\n if (Array.isArray(value)) {\n return (value as any[]).map((i) => String(i)).join(\",\")\n }\n\n return value\n }\n\n /**\n * Converts given string to simple array split by \",\" separator.\n */\n static stringToSimpleArray(value: string | any): string | any {\n if (typeof value === \"string\") {\n if (value.length > 0) {\n return value.split(\",\")\n } else {\n return []\n }\n }\n\n return value\n }\n\n static simpleJsonToString(value: any): string {\n return JSON.stringify(value)\n }\n\n static stringToSimpleJson(value: any) {\n return typeof value === \"string\" ? JSON.parse(value) : value\n }\n\n static simpleEnumToString(value: any) {\n return \"\" + value\n }\n\n static stringToSimpleEnum(value: any, columnMetadata: ColumnMetadata) {\n if (\n columnMetadata.enum &&\n !isNaN(value) &&\n columnMetadata.enum.indexOf(parseInt(value)) >= 0\n ) {\n // convert to number if that exists in poosible enum options\n value = parseInt(value)\n }\n\n return value\n }\n\n // -------------------------------------------------------------------------\n // Private Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Formats given number to \"0x\" format, e.g. if the totalLength = 2 and the value is 1 then it will return \"01\".\n */\n private static formatZerolessValue(value: number, totalLength = 2): string {\n const pad = \"0\".repeat(totalLength)\n\n return String(`${pad}${value}`).slice(-totalLength)\n }\n\n /**\n * Formats given number to \"0x\" format, e.g. if it is 1 then it will return \"01\".\n */\n private static formatMilliseconds(value: number): string {\n if (value < 10) {\n return \"00\" + value\n } else if (value < 100) {\n return \"0\" + value\n } else {\n return String(value)\n }\n }\n}\n"],"sourceRoot":".."}
|
package/driver/Driver.d.ts
CHANGED
|
@@ -93,10 +93,6 @@ export interface Driver {
|
|
|
93
93
|
* Column types are driver dependant.
|
|
94
94
|
*/
|
|
95
95
|
mappedDataTypes: MappedColumnTypes;
|
|
96
|
-
/**
|
|
97
|
-
* The prefix used for the parameters
|
|
98
|
-
*/
|
|
99
|
-
parametersPrefix?: string;
|
|
100
96
|
/**
|
|
101
97
|
* Max length allowed by the DBMS for aliases (execution of queries).
|
|
102
98
|
*/
|
package/driver/Driver.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/driver/Driver.ts"],"names":[],"mappings":"","file":"Driver.js","sourcesContent":["import { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { ColumnMetadata } from \"../metadata/ColumnMetadata\"\nimport { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { ColumnType } from \"./types/ColumnTypes\"\nimport { CteCapabilities } from \"./types/CteCapabilities\"\nimport { MappedColumnTypes } from \"./types/MappedColumnTypes\"\nimport { SchemaBuilder } from \"../schema-builder/SchemaBuilder\"\nimport { DataTypeDefaults } from \"./types/DataTypeDefaults\"\nimport { BaseDataSourceOptions } from \"../data-source/BaseDataSourceOptions\"\nimport { TableColumn } from \"../schema-builder/table/TableColumn\"\nimport { EntityMetadata } from \"../metadata/EntityMetadata\"\nimport { ReplicationMode } from \"./types/ReplicationMode\"\nimport { Table } from \"../schema-builder/table/Table\"\nimport { View } from \"../schema-builder/view/View\"\nimport { TableForeignKey } from \"../schema-builder/table/TableForeignKey\"\nimport { UpsertType } from \"./types/UpsertType\"\nimport { OnDeleteType } from \"../metadata/types/OnDeleteType\"\nimport { OnUpdateType } from \"../metadata/types/OnUpdateType\"\n\nexport type ReturningType = \"insert\" | \"update\" | \"delete\"\n\n/**\n * Driver organizes TypeORM communication with specific database management system.\n */\nexport interface Driver {\n /**\n * Connection options.\n */\n options: BaseDataSourceOptions\n\n /**\n * Database version/release. Often requires a SQL query to the DB, so it is not always set\n */\n version?: string\n\n /**\n * Database name used to perform all write queries.\n *\n * todo: probably move into query runner.\n */\n database?: string\n\n /**\n * Schema name used to perform all write queries.\n */\n schema?: string\n\n /**\n * Indicates if replication is enabled.\n */\n isReplicated: boolean\n\n /**\n * Indicates if tree tables are supported by this driver.\n */\n treeSupport: boolean\n\n /**\n * Represent transaction support by this driver\n */\n transactionSupport: \"simple\" | \"nested\" | \"none\"\n\n /**\n * Gets list of supported column data types by a driver.\n */\n supportedDataTypes: ColumnType[]\n\n /**\n * Returns type of upsert supported by driver if any\n */\n supportedUpsertTypes: UpsertType[]\n\n /**\n * Returns list of supported onDelete types by driver\n */\n supportedOnDeleteTypes?: OnDeleteType[]\n\n /**\n * Returns list of supported onUpdate types by driver\n */\n supportedOnUpdateTypes?: OnUpdateType[]\n\n /**\n * Default values of length, precision and scale depends on column data type.\n * Used in the cases when length/precision/scale is not specified by user.\n */\n dataTypeDefaults: DataTypeDefaults\n\n /**\n * Gets list of spatial column data types.\n */\n spatialTypes: ColumnType[]\n\n /**\n * Gets list of column data types that support length by a driver.\n */\n withLengthColumnTypes: ColumnType[]\n\n /**\n * Gets list of column data types that support precision by a driver.\n */\n withPrecisionColumnTypes: ColumnType[]\n\n /**\n * Gets list of column data types that support scale by a driver.\n */\n withScaleColumnTypes: ColumnType[]\n\n /**\n * Orm has special columns and we need to know what database column types should be for those types.\n * Column types are driver dependant.\n */\n mappedDataTypes: MappedColumnTypes\n\n /**\n *
|
|
1
|
+
{"version":3,"sources":["../../src/driver/Driver.ts"],"names":[],"mappings":"","file":"Driver.js","sourcesContent":["import { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { ColumnMetadata } from \"../metadata/ColumnMetadata\"\nimport { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { ColumnType } from \"./types/ColumnTypes\"\nimport { CteCapabilities } from \"./types/CteCapabilities\"\nimport { MappedColumnTypes } from \"./types/MappedColumnTypes\"\nimport { SchemaBuilder } from \"../schema-builder/SchemaBuilder\"\nimport { DataTypeDefaults } from \"./types/DataTypeDefaults\"\nimport { BaseDataSourceOptions } from \"../data-source/BaseDataSourceOptions\"\nimport { TableColumn } from \"../schema-builder/table/TableColumn\"\nimport { EntityMetadata } from \"../metadata/EntityMetadata\"\nimport { ReplicationMode } from \"./types/ReplicationMode\"\nimport { Table } from \"../schema-builder/table/Table\"\nimport { View } from \"../schema-builder/view/View\"\nimport { TableForeignKey } from \"../schema-builder/table/TableForeignKey\"\nimport { UpsertType } from \"./types/UpsertType\"\nimport { OnDeleteType } from \"../metadata/types/OnDeleteType\"\nimport { OnUpdateType } from \"../metadata/types/OnUpdateType\"\n\nexport type ReturningType = \"insert\" | \"update\" | \"delete\"\n\n/**\n * Driver organizes TypeORM communication with specific database management system.\n */\nexport interface Driver {\n /**\n * Connection options.\n */\n options: BaseDataSourceOptions\n\n /**\n * Database version/release. Often requires a SQL query to the DB, so it is not always set\n */\n version?: string\n\n /**\n * Database name used to perform all write queries.\n *\n * todo: probably move into query runner.\n */\n database?: string\n\n /**\n * Schema name used to perform all write queries.\n */\n schema?: string\n\n /**\n * Indicates if replication is enabled.\n */\n isReplicated: boolean\n\n /**\n * Indicates if tree tables are supported by this driver.\n */\n treeSupport: boolean\n\n /**\n * Represent transaction support by this driver\n */\n transactionSupport: \"simple\" | \"nested\" | \"none\"\n\n /**\n * Gets list of supported column data types by a driver.\n */\n supportedDataTypes: ColumnType[]\n\n /**\n * Returns type of upsert supported by driver if any\n */\n supportedUpsertTypes: UpsertType[]\n\n /**\n * Returns list of supported onDelete types by driver\n */\n supportedOnDeleteTypes?: OnDeleteType[]\n\n /**\n * Returns list of supported onUpdate types by driver\n */\n supportedOnUpdateTypes?: OnUpdateType[]\n\n /**\n * Default values of length, precision and scale depends on column data type.\n * Used in the cases when length/precision/scale is not specified by user.\n */\n dataTypeDefaults: DataTypeDefaults\n\n /**\n * Gets list of spatial column data types.\n */\n spatialTypes: ColumnType[]\n\n /**\n * Gets list of column data types that support length by a driver.\n */\n withLengthColumnTypes: ColumnType[]\n\n /**\n * Gets list of column data types that support precision by a driver.\n */\n withPrecisionColumnTypes: ColumnType[]\n\n /**\n * Gets list of column data types that support scale by a driver.\n */\n withScaleColumnTypes: ColumnType[]\n\n /**\n * Orm has special columns and we need to know what database column types should be for those types.\n * Column types are driver dependant.\n */\n mappedDataTypes: MappedColumnTypes\n\n /**\n * Max length allowed by the DBMS for aliases (execution of queries).\n */\n maxAliasLength?: number\n\n cteCapabilities: CteCapabilities\n\n /**\n * Dummy table name\n */\n dummyTableName?: string\n\n /**\n * Performs connection to the database.\n * Depend on driver type it may create a connection pool.\n */\n connect(): Promise<void>\n\n /**\n * Makes any action after connection (e.g. create extensions in Postgres driver).\n */\n afterConnect(): Promise<void>\n\n /**\n * Closes connection with database and releases all resources.\n */\n disconnect(): Promise<void>\n\n /**\n * Synchronizes database schema (creates tables, indices, etc).\n */\n createSchemaBuilder(): SchemaBuilder\n\n /**\n * Creates a query runner used for common queries.\n */\n createQueryRunner(mode: ReplicationMode): QueryRunner\n\n /**\n * Replaces parameters in the given sql with special escaping character\n * and an array of parameter names to be passed to a query.\n */\n escapeQueryWithParameters(\n sql: string,\n parameters: ObjectLiteral,\n nativeParameters: ObjectLiteral,\n ): [string, any[]]\n\n /**\n * Escapes a table name, column name or an alias.\n *\n * todo: probably escape should be able to handle dots in the names and automatically escape them\n */\n escape(name: string): string\n\n /**\n * Build full table name with database name, schema name and table name.\n * E.g. myDB.mySchema.myTable\n */\n buildTableName(\n tableName: string,\n schema?: string,\n database?: string,\n ): string\n\n /**\n * Parse a target table name or other types and return a normalized table definition.\n */\n parseTableName(\n target: EntityMetadata | Table | View | TableForeignKey | string,\n ): { tableName: string; schema?: string; database?: string }\n\n /**\n * Prepares given value to a value to be persisted, based on its column type and metadata.\n */\n preparePersistentValue(value: any, column: ColumnMetadata): any\n\n /**\n * Prepares given value to a value to be persisted, based on its column type.\n */\n prepareHydratedValue(value: any, column: ColumnMetadata): any\n\n /**\n * Transforms type of the given column to a database column type.\n */\n normalizeType(column: {\n type?: ColumnType | string\n length?: number | string\n precision?: number | null\n scale?: number\n isArray?: boolean\n }): string\n\n /**\n * Normalizes \"default\" value of the column.\n */\n normalizeDefault(columnMetadata: ColumnMetadata): string | undefined\n\n /**\n * Normalizes \"isUnique\" value of the column.\n */\n normalizeIsUnique(column: ColumnMetadata): boolean\n\n /**\n * Calculates column length taking into account the default length values.\n */\n getColumnLength(column: ColumnMetadata): string\n\n /**\n * Normalizes \"default\" value of the column.\n */\n createFullType(column: TableColumn): string\n\n /**\n * Obtains a new database connection to a master server.\n * Used for replication.\n * If replication is not setup then returns default connection's database connection.\n */\n obtainMasterConnection(): Promise<any>\n\n /**\n * Obtains a new database connection to a slave server.\n * Used for replication.\n * If replication is not setup then returns master (default) connection's database connection.\n */\n obtainSlaveConnection(): Promise<any>\n\n /**\n * Creates generated map of values generated or returned by database after INSERT query.\n */\n createGeneratedMap(\n metadata: EntityMetadata,\n insertResult: any,\n entityIndex?: number,\n entityNum?: number,\n ): ObjectLiteral | undefined\n\n /**\n * Differentiate columns of this table and columns from the given column metadatas columns\n * and returns only changed.\n */\n findChangedColumns(\n tableColumns: TableColumn[],\n columnMetadatas: ColumnMetadata[],\n ): ColumnMetadata[]\n\n /**\n * Returns true if driver supports RETURNING / OUTPUT statement.\n */\n isReturningSqlSupported(returningType: ReturningType): boolean\n\n /**\n * Returns true if driver supports uuid values generation on its own.\n */\n isUUIDGenerationSupported(): boolean\n\n /**\n * Returns true if driver supports fulltext indices.\n */\n isFullTextColumnTypeSupported(): boolean\n\n /**\n * Creates an escaped parameter.\n */\n createParameter(parameterName: string, index: number): string\n}\n"],"sourceRoot":".."}
|
|
@@ -107,10 +107,6 @@ export declare class CockroachDriver implements Driver {
|
|
|
107
107
|
* Column types are driver dependant.
|
|
108
108
|
*/
|
|
109
109
|
mappedDataTypes: MappedColumnTypes;
|
|
110
|
-
/**
|
|
111
|
-
* The prefix used for the parameters
|
|
112
|
-
*/
|
|
113
|
-
parametersPrefix: string;
|
|
114
110
|
/**
|
|
115
111
|
* Default values of length, precision and scale depends on column data type.
|
|
116
112
|
* Used in the cases when length/precision/scale is not specified by user.
|
|
@@ -152,10 +152,6 @@ class CockroachDriver {
|
|
|
152
152
|
metadataName: "varchar",
|
|
153
153
|
metadataValue: "string",
|
|
154
154
|
};
|
|
155
|
-
/**
|
|
156
|
-
* The prefix used for the parameters
|
|
157
|
-
*/
|
|
158
|
-
this.parametersPrefix = "$";
|
|
159
155
|
/**
|
|
160
156
|
* Default values of length, precision and scale depends on column data type.
|
|
161
157
|
* Used in the cases when length/precision/scale is not specified by user.
|
|
@@ -377,14 +373,10 @@ class CockroachDriver {
|
|
|
377
373
|
const escapedParameters = Object.keys(nativeParameters).map((key) => nativeParameters[key]);
|
|
378
374
|
if (!parameters || !Object.keys(parameters).length)
|
|
379
375
|
return [sql, escapedParameters];
|
|
380
|
-
const parameterIndexMap = new Map();
|
|
381
376
|
sql = sql.replace(/:(\.\.\.)?([A-Za-z0-9_.]+)/g, (full, isArray, key) => {
|
|
382
377
|
if (!parameters.hasOwnProperty(key)) {
|
|
383
378
|
return full;
|
|
384
379
|
}
|
|
385
|
-
if (parameterIndexMap.has(key)) {
|
|
386
|
-
return this.parametersPrefix + parameterIndexMap.get(key);
|
|
387
|
-
}
|
|
388
380
|
let value = parameters[key];
|
|
389
381
|
if (isArray) {
|
|
390
382
|
return value
|
|
@@ -398,7 +390,6 @@ class CockroachDriver {
|
|
|
398
390
|
return value();
|
|
399
391
|
}
|
|
400
392
|
escapedParameters.push(value);
|
|
401
|
-
parameterIndexMap.set(key, escapedParameters.length);
|
|
402
393
|
return this.createParameter(key, escapedParameters.length - 1);
|
|
403
394
|
}); // todo: make replace only in value statements, otherwise problems
|
|
404
395
|
return [sql, escapedParameters];
|
|
@@ -762,7 +753,7 @@ class CockroachDriver {
|
|
|
762
753
|
* Creates an escaped parameter.
|
|
763
754
|
*/
|
|
764
755
|
createParameter(parameterName, index) {
|
|
765
|
-
return
|
|
756
|
+
return "$" + (index + 1);
|
|
766
757
|
}
|
|
767
758
|
// -------------------------------------------------------------------------
|
|
768
759
|
// Public Methods
|