chore: typescript version upgrade (#7422)

This commit is contained in:
Umed Khudoiberdiev 2021-02-25 19:57:14 +05:00 committed by GitHub
parent d6df200772
commit c52ba29d94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 137 additions and 135 deletions

20
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "typeorm",
"version": "0.2.30",
"version": "0.2.31",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -74,6 +74,12 @@
"psl": "^1.1.28",
"punycode": "^2.1.1"
}
},
"tslib": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
"integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==",
"dev": true
}
}
},
@ -11293,9 +11299,9 @@
}
},
"tslib": {
"version": "1.13.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.13.0.tgz",
"integrity": "sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q=="
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.1.0.tgz",
"integrity": "sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A=="
},
"tsutils": {
"version": "3.17.1",
@ -11372,9 +11378,9 @@
}
},
"typescript": {
"version": "3.6.5",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.6.5.tgz",
"integrity": "sha512-BEjlc0Z06ORZKbtcxGrIvvwYs5hAnuo6TKdNFL55frVDlB+na3z5bsLhFaIxmT+dPWgBIjMo6aNnTOgHHmHgiQ==",
"version": "4.2.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.2.tgz",
"integrity": "sha512-tbb+NVrLfnsJy3M59lsDgrzWIflR4d4TIUjz+heUnHZwdF7YsrMTKoRERiIvI2lvBG95dfpLxB21WZhys1bgaQ==",
"dev": true
},
"uglify-js": {

View File

@ -112,7 +112,7 @@
"sqlite3": "^5.0.0",
"ts-node": "^9.0.0",
"typeorm-aurora-data-api-driver": "^1.4.0",
"typescript": "~3.6.0"
"typescript": "^4.2.2"
},
"dependencies": {
"@sqltools/formatter": "1.2.2",
@ -127,7 +127,7 @@
"mkdirp": "^1.0.4",
"reflect-metadata": "^0.1.13",
"sha.js": "^2.4.11",
"tslib": "^1.13.0",
"tslib": "^2.1.0",
"xml2js": "^0.4.23",
"yargonaut": "^1.1.2",
"yargs": "^16.0.3"

View File

@ -44,8 +44,10 @@ createConnection(options).then(connection => {
.save(entity)
.then(entity => {
console.log("EverythingEntity has been saved. Lets insert a new one to update it later");
delete entity.id;
return postRepository.save(entity);
return postRepository.save({
...entity,
id: undefined
}) as Promise<EverythingEntity>;
})
.then(entity => {
console.log("Second entity has been inserted. Lets update it");
@ -74,9 +76,10 @@ createConnection(options).then(connection => {
})
.then(entity => {
console.log("Entity has been updated. Persist once again to make find and remove then");
delete entity.id;
return postRepository.save(entity);
return postRepository.save({
...entity,
id: undefined
}) as Promise<EverythingEntity>;
})
.then(entity => {
return postRepository.findOne(entity.id);

View File

@ -26,13 +26,13 @@ export class Post {
@JoinColumn()
category: PostCategory;
// post has relation with details. cascade inserts here means if new PostDetails instance will be set to this
// post has relation with details. cascade inserts here means if new PostDetails instance will be set to this
// relation it will be inserted automatically to the db when you save this Post entity
@OneToOne(type => PostDetails, details => details.post, {
cascade: ["insert"]
})
@JoinColumn()
details: PostDetails;
details?: PostDetails;
// post has relation with details. cascade update here means if new PostDetail instance will be set to this relation
// it will be inserted automatically to the db when you save this Post entity
@ -60,4 +60,4 @@ export class Post {
@JoinColumn()
author: PostAuthor;
}
}

View File

@ -24,12 +24,12 @@ export class Post {
})
category: PostCategory;
// post has relation with details. cascade inserts here means if new PostDetails instance will be set to this
// post has relation with details. cascade inserts here means if new PostDetails instance will be set to this
// relation it will be inserted automatically to the db when you save this Post entity
@ManyToOne(type => PostDetails, details => details.posts, {
cascade: ["insert"]
})
details: PostDetails;
details?: PostDetails;
// post has relation with details. cascade update here means if new PostDetail instance will be set to this relation
// it will be inserted automatically to the db when you save this Post entity
@ -53,4 +53,4 @@ export class Post {
@ManyToOne(type => PostAuthor, author => author.posts)
author: PostAuthor;
}
}

View File

@ -306,7 +306,7 @@ export class PostgresDriver implements Driver {
if (extensionsMetadata.hasExtensions) {
await Promise.all([this.master, ...this.slaves].map(pool => {
return new Promise((ok, fail) => {
return new Promise<void>((ok, fail) => {
pool.connect(async (err: any, connection: any, release: Function) => {
await this.enableExtensions(extensionsMetadata, connection);
if (err) return fail(err);

View File

@ -62,6 +62,10 @@ import { BroadcasterResult } from "../subscriber/BroadcasterResult";
*/
export class MongoEntityManager extends EntityManager {
get mongoQueryRunner(): MongoQueryRunner {
return (this.connection.driver as MongoDriver).queryRunner as MongoQueryRunner;
}
// -------------------------------------------------------------------------
// Constructor
// -------------------------------------------------------------------------
@ -70,17 +74,6 @@ export class MongoEntityManager extends EntityManager {
super(connection);
}
// -------------------------------------------------------------------------
// Overridden Properties
// -------------------------------------------------------------------------
/**
* Gets query runner used to execute queries.
*/
get queryRunner(): MongoQueryRunner {
return (this.connection.driver as MongoDriver).queryRunner!;
}
// -------------------------------------------------------------------------
// Overridden Methods
// -------------------------------------------------------------------------
@ -262,7 +255,7 @@ export class MongoEntityManager extends EntityManager {
*/
createCursor<Entity, T = any>(entityClassOrName: EntityTarget<Entity>, query?: ObjectLiteral): Cursor<T> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.cursor(metadata.tableName, query);
return this.mongoQueryRunner.cursor(metadata.tableName, query);
}
/**
@ -281,7 +274,7 @@ export class MongoEntityManager extends EntityManager {
*/
aggregate<Entity, R = any>(entityClassOrName: EntityTarget<Entity>, pipeline: ObjectLiteral[], options?: CollectionAggregationOptions): AggregationCursor<R> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.aggregate(metadata.tableName, pipeline, options);
return this.mongoQueryRunner.aggregate(metadata.tableName, pipeline, options);
}
/**
@ -290,7 +283,7 @@ export class MongoEntityManager extends EntityManager {
*/
aggregateEntity<Entity>(entityClassOrName: EntityTarget<Entity>, pipeline: ObjectLiteral[], options?: CollectionAggregationOptions): AggregationCursor<Entity> {
const metadata = this.connection.getMetadata(entityClassOrName);
const cursor = this.queryRunner.aggregate(metadata.tableName, pipeline, options);
const cursor = this.mongoQueryRunner.aggregate(metadata.tableName, pipeline, options);
this.applyEntityTransformationToCursor(metadata, cursor);
return cursor;
}
@ -300,7 +293,7 @@ export class MongoEntityManager extends EntityManager {
*/
bulkWrite<Entity>(entityClassOrName: EntityTarget<Entity>, operations: ObjectLiteral[], options?: CollectionBulkWriteOptions): Promise<BulkWriteOpResultObject> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.bulkWrite(metadata.tableName, operations, options);
return this.mongoQueryRunner.bulkWrite(metadata.tableName, operations, options);
}
/**
@ -308,7 +301,7 @@ export class MongoEntityManager extends EntityManager {
*/
count<Entity>(entityClassOrName: EntityTarget<Entity>, query?: ObjectLiteral, options?: MongoCountPreferences): Promise<number> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.count(metadata.tableName, query, options);
return this.mongoQueryRunner.count(metadata.tableName, query, options);
}
/**
@ -316,7 +309,7 @@ export class MongoEntityManager extends EntityManager {
*/
createCollectionIndex<Entity>(entityClassOrName: EntityTarget<Entity>, fieldOrSpec: string | any, options?: MongodbIndexOptions): Promise<string> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.createCollectionIndex(metadata.tableName, fieldOrSpec, options);
return this.mongoQueryRunner.createCollectionIndex(metadata.tableName, fieldOrSpec, options);
}
/**
@ -326,7 +319,7 @@ export class MongoEntityManager extends EntityManager {
*/
createCollectionIndexes<Entity>(entityClassOrName: EntityTarget<Entity>, indexSpecs: ObjectLiteral[]): Promise<void> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.createCollectionIndexes(metadata.tableName, indexSpecs);
return this.mongoQueryRunner.createCollectionIndexes(metadata.tableName, indexSpecs);
}
/**
@ -334,7 +327,7 @@ export class MongoEntityManager extends EntityManager {
*/
deleteMany<Entity>(entityClassOrName: EntityTarget<Entity>, query: ObjectLiteral, options?: CollectionOptions): Promise<DeleteWriteOpResultObject> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.deleteMany(metadata.tableName, query, options);
return this.mongoQueryRunner.deleteMany(metadata.tableName, query, options);
}
/**
@ -342,7 +335,7 @@ export class MongoEntityManager extends EntityManager {
*/
deleteOne<Entity>(entityClassOrName: EntityTarget<Entity>, query: ObjectLiteral, options?: CollectionOptions): Promise<DeleteWriteOpResultObject> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.deleteOne(metadata.tableName, query, options);
return this.mongoQueryRunner.deleteOne(metadata.tableName, query, options);
}
/**
@ -350,7 +343,7 @@ export class MongoEntityManager extends EntityManager {
*/
distinct<Entity>(entityClassOrName: EntityTarget<Entity>, key: string, query: ObjectLiteral, options?: { readPreference?: ReadPreference | string }): Promise<any> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.distinct(metadata.tableName, key, query, options);
return this.mongoQueryRunner.distinct(metadata.tableName, key, query, options);
}
/**
@ -358,7 +351,7 @@ export class MongoEntityManager extends EntityManager {
*/
dropCollectionIndex<Entity>(entityClassOrName: EntityTarget<Entity>, indexName: string, options?: CollectionOptions): Promise<any> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.dropCollectionIndex(metadata.tableName, indexName, options);
return this.mongoQueryRunner.dropCollectionIndex(metadata.tableName, indexName, options);
}
/**
@ -366,7 +359,7 @@ export class MongoEntityManager extends EntityManager {
*/
dropCollectionIndexes<Entity>(entityClassOrName: EntityTarget<Entity>): Promise<any> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.dropCollectionIndexes(metadata.tableName);
return this.mongoQueryRunner.dropCollectionIndexes(metadata.tableName);
}
/**
@ -374,7 +367,7 @@ export class MongoEntityManager extends EntityManager {
*/
findOneAndDelete<Entity>(entityClassOrName: EntityTarget<Entity>, query: ObjectLiteral, options?: { projection?: Object, sort?: Object, maxTimeMS?: number }): Promise<FindAndModifyWriteOpResultObject> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.findOneAndDelete(metadata.tableName, query, options);
return this.mongoQueryRunner.findOneAndDelete(metadata.tableName, query, options);
}
/**
@ -382,7 +375,7 @@ export class MongoEntityManager extends EntityManager {
*/
findOneAndReplace<Entity>(entityClassOrName: EntityTarget<Entity>, query: ObjectLiteral, replacement: Object, options?: FindOneAndReplaceOption): Promise<FindAndModifyWriteOpResultObject> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.findOneAndReplace(metadata.tableName, query, replacement, options);
return this.mongoQueryRunner.findOneAndReplace(metadata.tableName, query, replacement, options);
}
/**
@ -390,7 +383,7 @@ export class MongoEntityManager extends EntityManager {
*/
findOneAndUpdate<Entity>(entityClassOrName: EntityTarget<Entity>, query: ObjectLiteral, update: Object, options?: FindOneAndReplaceOption): Promise<FindAndModifyWriteOpResultObject> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.findOneAndUpdate(metadata.tableName, query, update, options);
return this.mongoQueryRunner.findOneAndUpdate(metadata.tableName, query, update, options);
}
/**
@ -398,7 +391,7 @@ export class MongoEntityManager extends EntityManager {
*/
geoHaystackSearch<Entity>(entityClassOrName: EntityTarget<Entity>, x: number, y: number, options?: GeoHaystackSearchOptions): Promise<any> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.geoHaystackSearch(metadata.tableName, x, y, options);
return this.mongoQueryRunner.geoHaystackSearch(metadata.tableName, x, y, options);
}
/**
@ -406,7 +399,7 @@ export class MongoEntityManager extends EntityManager {
*/
geoNear<Entity>(entityClassOrName: EntityTarget<Entity>, x: number, y: number, options?: GeoNearOptions): Promise<any> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.geoNear(metadata.tableName, x, y, options);
return this.mongoQueryRunner.geoNear(metadata.tableName, x, y, options);
}
/**
@ -414,7 +407,7 @@ export class MongoEntityManager extends EntityManager {
*/
group<Entity>(entityClassOrName: EntityTarget<Entity>, keys: Object | Array<any> | Function | Code, condition: Object, initial: Object, reduce: Function | Code, finalize: Function | Code, command: boolean, options?: { readPreference?: ReadPreference | string }): Promise<any> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.group(metadata.tableName, keys, condition, initial, reduce, finalize, command, options);
return this.mongoQueryRunner.group(metadata.tableName, keys, condition, initial, reduce, finalize, command, options);
}
/**
@ -422,7 +415,7 @@ export class MongoEntityManager extends EntityManager {
*/
collectionIndexes<Entity>(entityClassOrName: EntityTarget<Entity>): Promise<any> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.collectionIndexes(metadata.tableName);
return this.mongoQueryRunner.collectionIndexes(metadata.tableName);
}
/**
@ -430,7 +423,7 @@ export class MongoEntityManager extends EntityManager {
*/
collectionIndexExists<Entity>(entityClassOrName: EntityTarget<Entity>, indexes: string | string[]): Promise<boolean> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.collectionIndexExists(metadata.tableName, indexes);
return this.mongoQueryRunner.collectionIndexExists(metadata.tableName, indexes);
}
/**
@ -438,7 +431,7 @@ export class MongoEntityManager extends EntityManager {
*/
collectionIndexInformation<Entity>(entityClassOrName: EntityTarget<Entity>, options?: { full: boolean }): Promise<any> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.collectionIndexInformation(metadata.tableName, options);
return this.mongoQueryRunner.collectionIndexInformation(metadata.tableName, options);
}
/**
@ -446,7 +439,7 @@ export class MongoEntityManager extends EntityManager {
*/
initializeOrderedBulkOp<Entity>(entityClassOrName: EntityTarget<Entity>, options?: CollectionOptions): OrderedBulkOperation {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.initializeOrderedBulkOp(metadata.tableName, options);
return this.mongoQueryRunner.initializeOrderedBulkOp(metadata.tableName, options);
}
/**
@ -454,7 +447,7 @@ export class MongoEntityManager extends EntityManager {
*/
initializeUnorderedBulkOp<Entity>(entityClassOrName: EntityTarget<Entity>, options?: CollectionOptions): UnorderedBulkOperation {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.initializeUnorderedBulkOp(metadata.tableName, options);
return this.mongoQueryRunner.initializeUnorderedBulkOp(metadata.tableName, options);
}
/**
@ -462,7 +455,7 @@ export class MongoEntityManager extends EntityManager {
*/
insertMany<Entity>(entityClassOrName: EntityTarget<Entity>, docs: ObjectLiteral[], options?: CollectionInsertManyOptions): Promise<InsertWriteOpResult> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.insertMany(metadata.tableName, docs, options);
return this.mongoQueryRunner.insertMany(metadata.tableName, docs, options);
}
/**
@ -470,7 +463,7 @@ export class MongoEntityManager extends EntityManager {
*/
insertOne<Entity>(entityClassOrName: EntityTarget<Entity>, doc: ObjectLiteral, options?: CollectionInsertOneOptions): Promise<InsertOneWriteOpResult> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.insertOne(metadata.tableName, doc, options);
return this.mongoQueryRunner.insertOne(metadata.tableName, doc, options);
}
/**
@ -478,7 +471,7 @@ export class MongoEntityManager extends EntityManager {
*/
isCapped<Entity>(entityClassOrName: EntityTarget<Entity>): Promise<any> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.isCapped(metadata.tableName);
return this.mongoQueryRunner.isCapped(metadata.tableName);
}
/**
@ -486,7 +479,7 @@ export class MongoEntityManager extends EntityManager {
*/
listCollectionIndexes<Entity>(entityClassOrName: EntityTarget<Entity>, options?: { batchSize?: number, readPreference?: ReadPreference | string }): CommandCursor {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.listCollectionIndexes(metadata.tableName, options);
return this.mongoQueryRunner.listCollectionIndexes(metadata.tableName, options);
}
/**
@ -494,7 +487,7 @@ export class MongoEntityManager extends EntityManager {
*/
mapReduce<Entity>(entityClassOrName: EntityTarget<Entity>, map: Function | string, reduce: Function | string, options?: MapReduceOptions): Promise<any> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.mapReduce(metadata.tableName, map, reduce, options);
return this.mongoQueryRunner.mapReduce(metadata.tableName, map, reduce, options);
}
/**
@ -503,7 +496,7 @@ export class MongoEntityManager extends EntityManager {
*/
parallelCollectionScan<Entity>(entityClassOrName: EntityTarget<Entity>, options?: ParallelCollectionScanOptions): Promise<Cursor<Entity>[]> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.parallelCollectionScan(metadata.tableName, options);
return this.mongoQueryRunner.parallelCollectionScan(metadata.tableName, options);
}
/**
@ -511,7 +504,7 @@ export class MongoEntityManager extends EntityManager {
*/
reIndex<Entity>(entityClassOrName: EntityTarget<Entity>): Promise<any> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.reIndex(metadata.tableName);
return this.mongoQueryRunner.reIndex(metadata.tableName);
}
/**
@ -519,7 +512,7 @@ export class MongoEntityManager extends EntityManager {
*/
rename<Entity>(entityClassOrName: EntityTarget<Entity>, newName: string, options?: { dropTarget?: boolean }): Promise<Collection<any>> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.rename(metadata.tableName, newName, options);
return this.mongoQueryRunner.rename(metadata.tableName, newName, options);
}
/**
@ -527,7 +520,7 @@ export class MongoEntityManager extends EntityManager {
*/
replaceOne<Entity>(entityClassOrName: EntityTarget<Entity>, query: ObjectLiteral, doc: ObjectLiteral, options?: ReplaceOneOptions): Promise<UpdateWriteOpResult> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.replaceOne(metadata.tableName, query, doc, options);
return this.mongoQueryRunner.replaceOne(metadata.tableName, query, doc, options);
}
/**
@ -535,12 +528,12 @@ export class MongoEntityManager extends EntityManager {
*/
stats<Entity>(entityClassOrName: EntityTarget<Entity>, options?: { scale: number }): Promise<CollStats> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.stats(metadata.tableName, options);
return this.mongoQueryRunner.stats(metadata.tableName, options);
}
watch<Entity>(entityClassOrName: EntityTarget<Entity>, pipeline?: Object[], options?: ChangeStreamOptions): ChangeStream {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.watch(metadata.tableName, pipeline, options);
return this.mongoQueryRunner.watch(metadata.tableName, pipeline, options);
}
/**
@ -548,7 +541,7 @@ export class MongoEntityManager extends EntityManager {
*/
updateMany<Entity>(entityClassOrName: EntityTarget<Entity>, query: ObjectLiteral, update: ObjectLiteral, options?: { upsert?: boolean, w?: any, wtimeout?: number, j?: boolean }): Promise<UpdateWriteOpResult> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.updateMany(metadata.tableName, query, update, options);
return this.mongoQueryRunner.updateMany(metadata.tableName, query, update, options);
}
/**
@ -556,7 +549,7 @@ export class MongoEntityManager extends EntityManager {
*/
updateOne<Entity>(entityClassOrName: EntityTarget<Entity>, query: ObjectLiteral, update: ObjectLiteral, options?: ReplaceOneOptions): Promise<UpdateWriteOpResult> {
const metadata = this.connection.getMetadata(entityClassOrName);
return this.queryRunner.updateOne(metadata.tableName, query, update, options);
return this.mongoQueryRunner.updateOne(metadata.tableName, query, update, options);
}
// -------------------------------------------------------------------------
@ -664,7 +657,7 @@ export class MongoEntityManager extends EntityManager {
*/
protected applyEntityTransformationToCursor<Entity>(metadata: EntityMetadata, cursor: Cursor<Entity> | AggregationCursor<Entity>) {
const ParentCursor = PlatformTools.load("mongodb").Cursor;
const queryRunner = this.queryRunner;
const queryRunner = this.mongoQueryRunner;
cursor.toArray = function (callback?: MongoCallback<Entity[]>) {
if (callback) {
ParentCursor.prototype.toArray.call(this, (error: MongoError, results: Entity[]): void => {

View File

@ -97,9 +97,9 @@ export abstract class BaseQueryRunner {
// Protected Abstract Methods
// -------------------------------------------------------------------------
protected abstract async loadTables(tablePaths: string[]): Promise<Table[]>;
protected abstract loadTables(tablePaths: string[]): Promise<Table[]>;
protected abstract async loadViews(tablePaths: string[]): Promise<View[]>;
protected abstract loadViews(tablePaths: string[]): Promise<View[]>;
// -------------------------------------------------------------------------
// Public Methods

View File

@ -64,7 +64,7 @@ describe("one-to-one", function() {
return;
let newPost: Post, details: PostDetails, savedPost: Post;
before(reloadDatabase);
before(function() {
@ -72,7 +72,7 @@ describe("one-to-one", function() {
details.authorName = "Umed";
details.comment = "this is post";
details.metadata = "post,posting,postman";
newPost = new Post();
newPost.text = "Hello post";
newPost.title = "this is post title";
@ -85,12 +85,12 @@ describe("one-to-one", function() {
});
it("should return the same post details instance after its created", function () {
savedPost.details.should.be.equal(newPost.details);
savedPost.details!.should.be.equal(newPost.details);
});
it("should have a new generated id after post is created", function () {
expect(savedPost.id).not.to.be.undefined;
expect(savedPost.details.id).not.to.be.undefined;
expect(savedPost.details!.id).not.to.be.undefined;
});
it("should have inserted post in the database", function() {
@ -100,7 +100,7 @@ describe("one-to-one", function() {
expectedPost.id = savedPost.id;
expectedPost.text = savedPost.text;
expectedPost.title = savedPost.title;
return postRepository.findOne(savedPost.id).should.eventually.eql(expectedPost);
});
@ -108,12 +108,12 @@ describe("one-to-one", function() {
if (!connection)
return;
const expectedDetails = new PostDetails();
expectedDetails.id = savedPost.details.id;
expectedDetails.authorName = savedPost.details.authorName;
expectedDetails.comment = savedPost.details.comment;
expectedDetails.metadata = savedPost.details.metadata;
expectedDetails.id = savedPost.details!.id;
expectedDetails.authorName = savedPost.details!.authorName;
expectedDetails.comment = savedPost.details!.comment;
expectedDetails.metadata = savedPost.details!.metadata;
const loadedPostDetails = await postDetailsRepository.findOne(savedPost.details.id);
const loadedPostDetails = await postDetailsRepository.findOne(savedPost.details!.id);
loadedPostDetails!.should.be.eql(expectedDetails);
});
@ -125,11 +125,11 @@ describe("one-to-one", function() {
expectedPost.text = savedPost.text;
expectedPost.title = savedPost.title;
expectedPost.details = new PostDetails();
expectedPost.details.id = savedPost.details.id;
expectedPost.details.authorName = savedPost.details.authorName;
expectedPost.details.comment = savedPost.details.comment;
expectedPost.details.metadata = savedPost.details.metadata;
expectedPost.details!.id = savedPost.details!.id;
expectedPost.details!.authorName = savedPost.details!.authorName;
expectedPost.details!.comment = savedPost.details!.comment;
expectedPost.details!.metadata = savedPost.details!.metadata;
const post = await postRepository
.createQueryBuilder("post")
.leftJoinAndSelect("post.details", "details")
@ -146,16 +146,16 @@ describe("one-to-one", function() {
return;
const expectedDetails = new PostDetails();
expectedDetails.id = savedPost.details.id;
expectedDetails.authorName = savedPost.details.authorName;
expectedDetails.comment = savedPost.details.comment;
expectedDetails.metadata = savedPost.details.metadata;
expectedDetails.id = savedPost.details!.id;
expectedDetails.authorName = savedPost.details!.authorName;
expectedDetails.comment = savedPost.details!.comment;
expectedDetails.metadata = savedPost.details!.metadata;
expectedDetails.post = new Post();
expectedDetails.post.id = savedPost.id;
expectedDetails.post.text = savedPost.text;
expectedDetails.post.title = savedPost.title;
return postDetailsRepository
.createQueryBuilder("details")
.leftJoinAndSelect("details.post", "post")
@ -170,7 +170,7 @@ describe("one-to-one", function() {
expectedPost.id = savedPost.id;
expectedPost.text = savedPost.text;
expectedPost.title = savedPost.title;
return postRepository
.createQueryBuilder("post")
.where("post.id=:id", { id: savedPost.id })
@ -180,11 +180,11 @@ describe("one-to-one", function() {
it("should load saved post without details if left joins are not specified", function() {
const expectedDetails = new PostDetails();
expectedDetails.id = savedPost.details.id;
expectedDetails.authorName = savedPost.details.authorName;
expectedDetails.comment = savedPost.details.comment;
expectedDetails.metadata = savedPost.details.metadata;
expectedDetails.id = savedPost.details!.id;
expectedDetails.authorName = savedPost.details!.authorName;
expectedDetails.comment = savedPost.details!.comment;
expectedDetails.metadata = savedPost.details!.metadata;
return postDetailsRepository
.createQueryBuilder("details")
.where("details.id=:id", { id: savedPost.id })
@ -268,7 +268,7 @@ describe("one-to-one", function() {
.getSingleResult()
.should.be.rejectedWith(Error);*/ // not working, find fix
});
});
describe("cascade updates should not be executed when cascadeUpdate option is not set", function() {
@ -294,7 +294,7 @@ describe("one-to-one", function() {
});
it("should ignore updates in the model and do not update the db when entity is updated", function () {
newPost.details.comment = "i am updated comment";
newPost.details!.comment = "i am updated comment";
return postRepository.save(newPost).then(updatedPost => {
updatedPost.details!.comment!.should.be.equal("i am updated comment");
return postRepository
@ -304,7 +304,7 @@ describe("one-to-one", function() {
.setParameter("id", updatedPost.id)
.getOne();
}).then(updatedPostReloaded => {
updatedPostReloaded!.details.comment.should.be.equal("this is post");
updatedPostReloaded!.details!.comment.should.be.equal("this is post");
});
}); // todo: also check that updates throw exception in strict cascades mode
});
@ -343,7 +343,7 @@ describe("one-to-one", function() {
.setParameter("id", updatedPost.id)
.getOne();
}).then(updatedPostReloaded => {
updatedPostReloaded!.details.comment.should.be.equal("this is post");
updatedPostReloaded!.details!.comment.should.be.equal("this is post");
});
});
});
@ -391,7 +391,7 @@ describe("one-to-one", function() {
.where("post.id=:id")
.setParameter("id", newPost.id)
.getOne();
}).then(reloadedPost => {
reloadedPost!.image.url.should.be.equal("new-logo.png");
});

View File

@ -62,7 +62,7 @@ describe("many-to-one", function() {
if (!connection)
return;
let newPost: Post, details: PostDetails, savedPost: Post;
before(reloadDatabase);
before(function() {
@ -70,7 +70,7 @@ describe("many-to-one", function() {
details.authorName = "Umed";
details.comment = "this is post";
details.metadata = "post,posting,postman";
newPost = new Post();
newPost.text = "Hello post";
newPost.title = "this is post title";
@ -83,12 +83,12 @@ describe("many-to-one", function() {
});
it("should return the same post details instance after its created", function () {
savedPost.details.should.be.equal(newPost.details);
savedPost.details!.should.be.equal(newPost.details);
});
it("should have a new generated id after post is created", function () {
expect(savedPost.id).not.to.be.undefined;
expect(savedPost.details.id).not.to.be.undefined;
expect(savedPost.details!.id).not.to.be.undefined;
});
it("should have inserted post in the database", function() {
@ -98,7 +98,7 @@ describe("many-to-one", function() {
expectedPost.id = savedPost.id;
expectedPost.text = savedPost.text;
expectedPost.title = savedPost.title;
return postRepository.findOne(savedPost.id).should.eventually.eql(expectedPost);
});
@ -106,12 +106,12 @@ describe("many-to-one", function() {
if (!connection)
return;
const expectedDetails = new PostDetails();
expectedDetails.id = savedPost.details.id;
expectedDetails.authorName = savedPost.details.authorName;
expectedDetails.comment = savedPost.details.comment;
expectedDetails.metadata = savedPost.details.metadata;
return postDetailsRepository.findOne(savedPost.details.id).should.eventually.eql(expectedDetails);
expectedDetails.id = savedPost.details!.id;
expectedDetails.authorName = savedPost.details!.authorName;
expectedDetails.comment = savedPost.details!.comment;
expectedDetails.metadata = savedPost.details!.metadata;
return postDetailsRepository.findOne(savedPost.details!.id).should.eventually.eql(expectedDetails);
});
it("should load post and its details if left join used", function() {
@ -122,11 +122,11 @@ describe("many-to-one", function() {
expectedPost.text = savedPost.text;
expectedPost.title = savedPost.title;
expectedPost.details = new PostDetails();
expectedPost.details.id = savedPost.details.id;
expectedPost.details.authorName = savedPost.details.authorName;
expectedPost.details.comment = savedPost.details.comment;
expectedPost.details.metadata = savedPost.details.metadata;
expectedPost.details.id = savedPost.details!.id;
expectedPost.details.authorName = savedPost.details!.authorName;
expectedPost.details.comment = savedPost.details!.comment;
expectedPost.details.metadata = savedPost.details!.metadata;
return postRepository
.createQueryBuilder("post")
.leftJoinAndSelect("post.details", "details")
@ -141,19 +141,19 @@ describe("many-to-one", function() {
return;
const expectedDetails = new PostDetails();
expectedDetails.id = savedPost.details.id;
expectedDetails.authorName = savedPost.details.authorName;
expectedDetails.comment = savedPost.details.comment;
expectedDetails.metadata = savedPost.details.metadata;
expectedDetails.id = savedPost.details!.id;
expectedDetails.authorName = savedPost.details!.authorName;
expectedDetails.comment = savedPost.details!.comment;
expectedDetails.metadata = savedPost.details!.metadata;
const expectedPost = new Post();
expectedPost.id = savedPost.id;
expectedPost.text = savedPost.text;
expectedPost.title = savedPost.title;
expectedDetails.posts = [];
expectedDetails.posts.push(expectedPost);
return postDetailsRepository
.createQueryBuilder("details")
.leftJoinAndSelect("details.posts", "posts")
@ -170,7 +170,7 @@ describe("many-to-one", function() {
expectedPost.id = savedPost.id;
expectedPost.text = savedPost.text;
expectedPost.title = savedPost.title;
return postRepository
.createQueryBuilder("post")
.where("post.id=:id", { id: savedPost.id })
@ -182,11 +182,11 @@ describe("many-to-one", function() {
if (!connection)
return;
const expectedDetails = new PostDetails();
expectedDetails.id = savedPost.details.id;
expectedDetails.authorName = savedPost.details.authorName;
expectedDetails.comment = savedPost.details.comment;
expectedDetails.metadata = savedPost.details.metadata;
expectedDetails.id = savedPost.details!.id;
expectedDetails.authorName = savedPost.details!.authorName;
expectedDetails.comment = savedPost.details!.comment;
expectedDetails.metadata = savedPost.details!.metadata;
return postDetailsRepository
.createQueryBuilder("details")
.where("details.id=:id", { id: savedPost.id })
@ -275,7 +275,7 @@ describe("many-to-one", function() {
.getSingleResult()
.should.be.rejectedWith(Error);*/ // not working, find fix
});
});
describe("cascade updates should not be executed when cascadeUpdate option is not set", function() {
@ -301,7 +301,7 @@ describe("many-to-one", function() {
});
it("should ignore updates in the model and do not update the db when entity is updated", function () {
newPost.details.comment = "i am updated comment";
newPost.details!.comment = "i am updated comment";
return postRepository.save(newPost).then(updatedPost => {
updatedPost.details!.comment!.should.be.equal("i am updated comment");
return postRepository
@ -311,7 +311,7 @@ describe("many-to-one", function() {
.setParameter("id", updatedPost.id)
.getOne();
}).then(updatedPostReloaded => {
updatedPostReloaded!.details.comment!.should.be.equal("this is post");
updatedPostReloaded!.details!.comment!.should.be.equal("this is post");
});
}); // todo: also check that updates throw exception in strict cascades mode
});
@ -348,7 +348,7 @@ describe("many-to-one", function() {
.setParameter("id", updatedPost.id)
.getOne();
}).then(updatedPostReloaded => {
updatedPostReloaded!.details.comment!.should.be.equal("this is post");
updatedPostReloaded!.details!.comment!.should.be.equal("this is post");
});
});
});
@ -395,7 +395,7 @@ describe("many-to-one", function() {
.where("post.id=:id")
.setParameter("id", newPost.id)
.getOne();
}).then(reloadedPost => {
reloadedPost!.image.url.should.be.equal("new-logo.png");
});