From 2a59f621ee52143711d13ead9f14c8c4872539b3 Mon Sep 17 00:00:00 2001 From: Umed Khudoiberdiev Date: Sun, 18 Sep 2016 22:55:59 +0500 Subject: [PATCH] refactored connection stuff; optimized all imports --- sample/sample10-mixed/entity/Category.ts | 4 +- sample/sample10-mixed/entity/Chapter.ts | 4 +- sample/sample10-mixed/entity/Cover.ts | 4 +- sample/sample10-mixed/entity/Image.ts | 4 +- sample/sample10-mixed/entity/ImageDetails.ts | 4 +- sample/sample10-mixed/entity/Post.ts | 4 +- sample/sample10-mixed/entity/PostDetails.ts | 4 +- .../entity/EverythingEntity.ts | 3 +- .../entity/Post.ts | 3 +- .../entity/Blog.ts | 5 +- .../entity/Post.ts | 5 +- .../entity/PostAuthor.ts | 3 +- .../entity/PostCategory.ts | 3 +- .../entity/PostUser.ts | 3 +- .../entity/Post.ts | 5 +- .../entity/PostAuthor.ts | 4 +- .../sample15-we-are-reactive/entity/Post.ts | 3 +- sample/sample17-versioning/entity/Post.ts | 3 +- .../sample18-lazy-relations/entity/Author.ts | 3 +- .../entity/Category.ts | 3 +- sample/sample18-lazy-relations/entity/Post.ts | 3 +- .../entity/Author.ts | 3 +- .../entity/Category.ts | 3 +- .../entity/Post.ts | 3 +- .../entity/PostMetadata.ts | 3 +- sample/sample2-one-to-one/entity/Post.ts | 4 +- .../sample2-one-to-one/entity/PostAuthor.ts | 4 +- .../sample2-one-to-one/entity/PostCategory.ts | 3 +- .../sample2-one-to-one/entity/PostDetails.ts | 4 +- sample/sample2-one-to-one/entity/PostImage.ts | 4 +- .../entity/PostInformation.ts | 4 +- .../sample2-one-to-one/entity/PostMetadata.ts | 4 +- .../entity/Author.ts | 3 +- .../entity/Category.ts | 3 +- .../entity/Post.ts | 3 +- .../entity/Author.ts | 3 +- .../entity/Category.ts | 3 +- .../entity/Post.ts | 3 +- sample/sample23-nested-joins/entity/Author.ts | 3 +- .../sample23-nested-joins/entity/Category.ts | 3 +- sample/sample23-nested-joins/entity/Post.ts | 3 +- .../entity/Author.ts | 3 +- .../entity/Post.ts | 3 +- .../sample26-embedded-tables/entity/Post.ts | 3 +- .../entity/Question.ts | 3 +- sample/sample3-many-to-one/entity/Post.ts | 4 +- .../sample3-many-to-one/entity/PostAuthor.ts | 4 +- .../entity/PostCategory.ts | 3 +- .../sample3-many-to-one/entity/PostDetails.ts | 4 +- .../sample3-many-to-one/entity/PostImage.ts | 4 +- .../entity/PostInformation.ts | 4 +- .../entity/PostMetadata.ts | 4 +- sample/sample4-many-to-many/entity/Post.ts | 4 +- .../sample4-many-to-many/entity/PostAuthor.ts | 4 +- .../entity/PostCategory.ts | 3 +- .../entity/PostDetails.ts | 5 +- .../sample4-many-to-many/entity/PostImage.ts | 4 +- .../entity/PostInformation.ts | 4 +- .../entity/PostMetadata.ts | 4 +- sample/sample5-subscribers/entity/Post.ts | 5 +- .../sample5-subscribers/entity/PostAuthor.ts | 3 +- .../entity/PostCategory.ts | 3 +- sample/sample6-abstract-table/entity/Blog.ts | 3 +- sample/sample6-abstract-table/entity/Post.ts | 3 +- .../entity/PostAuthor.ts | 3 +- .../entity/PostCategory.ts | 3 +- sample/sample7-pagination/entity/Post.ts | 4 +- .../sample7-pagination/entity/PostAuthor.ts | 3 +- .../sample7-pagination/entity/PostCategory.ts | 3 +- .../entity/Category.ts | 4 +- .../sample9-entity-listeners/entity/Post.ts | 4 +- .../entity/PostAuthor.ts | 3 +- .../entity/PostCategory.ts | 3 +- src/commands/QueryCommand.ts | 4 +- src/commands/SchemaDropCommand.ts | 6 +- src/commands/SchemaSyncCommand.ts | 6 +- src/connection/ConnectionManager.ts | 412 +++++++++++++----- src/connection/ConnectionOptions.ts | 39 +- src/connection/OrmConfigConnectionOptions.ts | 17 - .../error/AlreadyHasActiveConnectionError.ts | 6 +- .../error/CannotCloseNotConnectedError.ts | 3 + .../CannotConnectAlreadyConnectedError.ts | 3 + .../CannotDetermineConnectionOptionsError.ts | 19 + ...CannotGetEntityManagerNotConnectedError.ts | 3 + .../CannotImportAlreadyConnectedError.ts | 4 + .../error/CannotSyncNotConnectedError.ts | 3 + ...annotUseNamingStrategyNotConnectedError.ts | 3 + .../error/ConnectionNotFoundError.ts | 3 + src/connection/error/MissingDriverError.ts | 3 +- .../error/NamingStrategyNotFoundError.ts | 3 + .../error/NoConnectionForRepositoryError.ts | 3 + .../error/ReactiveRepositoryNotFoundError.ts | 3 + .../error/RepositoryNotFoundError.ts | 3 + .../error/RepositoryNotTreeError.ts | 3 + src/index.ts | 105 ++++- src/logger/LoggerOptions.ts | 3 + src/query-builder/alias/Alias.ts | 2 - src/repository/FindOptions.ts | 1 - src/repository/ReactiveRepository.ts | 1 - src/repository/ReactiveSpecificRepository.ts | 1 - src/repository/Repository.ts | 1 - src/repository/RepositoryFactory.ts | 2 - src/util/OrmUtils.ts | 16 + test/functional/connection/connection.ts | 6 +- 104 files changed, 589 insertions(+), 355 deletions(-) delete mode 100644 src/connection/OrmConfigConnectionOptions.ts create mode 100644 src/connection/error/CannotDetermineConnectionOptionsError.ts diff --git a/sample/sample10-mixed/entity/Category.ts b/sample/sample10-mixed/entity/Category.ts index 1620f4d2b0..fc33a572f3 100644 --- a/sample/sample10-mixed/entity/Category.ts +++ b/sample/sample10-mixed/entity/Category.ts @@ -1,6 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; -import {ManyToOne, ManyToMany} from "../../../src/index"; +import {PrimaryColumn, Column, Table, ManyToOne, ManyToMany} from "../../../src/index"; import {Post} from "./Post"; import {PostDetails} from "./PostDetails"; diff --git a/sample/sample10-mixed/entity/Chapter.ts b/sample/sample10-mixed/entity/Chapter.ts index e5911a9a11..0ee74e0852 100644 --- a/sample/sample10-mixed/entity/Chapter.ts +++ b/sample/sample10-mixed/entity/Chapter.ts @@ -1,6 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; -import {OneToMany} from "../../../src/index"; +import {PrimaryColumn, Column, Table, OneToMany} from "../../../src/index"; import {PostDetails} from "./PostDetails"; @Table("sample10_chapter") diff --git a/sample/sample10-mixed/entity/Cover.ts b/sample/sample10-mixed/entity/Cover.ts index 8125d643ae..c780294c03 100644 --- a/sample/sample10-mixed/entity/Cover.ts +++ b/sample/sample10-mixed/entity/Cover.ts @@ -1,6 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; -import {OneToMany} from "../../../src/index"; +import {PrimaryColumn, Column, Table, OneToMany} from "../../../src/index"; import {Post} from "./Post"; @Table("sample10_cover") diff --git a/sample/sample10-mixed/entity/Image.ts b/sample/sample10-mixed/entity/Image.ts index 9fa7449ec2..d890762a5b 100644 --- a/sample/sample10-mixed/entity/Image.ts +++ b/sample/sample10-mixed/entity/Image.ts @@ -1,6 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; -import {ManyToOne, OneToOne} from "../../../src/index"; +import {PrimaryColumn, Column, Table, ManyToOne, OneToOne} from "../../../src/index"; import {Post} from "./Post"; import {ImageDetails} from "./ImageDetails"; import {JoinColumn} from "../../../src/decorator/relations/JoinColumn"; diff --git a/sample/sample10-mixed/entity/ImageDetails.ts b/sample/sample10-mixed/entity/ImageDetails.ts index e021c9958f..7e7f6f735e 100644 --- a/sample/sample10-mixed/entity/ImageDetails.ts +++ b/sample/sample10-mixed/entity/ImageDetails.ts @@ -1,6 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; -import {OneToOne} from "../../../src/index"; +import {PrimaryColumn, Column, Table, OneToOne} from "../../../src/index"; import {Image} from "./Image"; @Table("sample10_image_details") diff --git a/sample/sample10-mixed/entity/Post.ts b/sample/sample10-mixed/entity/Post.ts index 28bb4182cf..c902a92b05 100644 --- a/sample/sample10-mixed/entity/Post.ts +++ b/sample/sample10-mixed/entity/Post.ts @@ -1,6 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; -import {OneToMany, ManyToOne, ManyToMany, OneToOne} from "../../../src/index"; +import {PrimaryColumn, Column, Table, OneToMany, ManyToOne, ManyToMany, OneToOne} from "../../../src/index"; import {Image} from "./Image"; import {Cover} from "./Cover"; import {Category} from "./Category"; diff --git a/sample/sample10-mixed/entity/PostDetails.ts b/sample/sample10-mixed/entity/PostDetails.ts index b5788ef7da..fa1361ea2f 100644 --- a/sample/sample10-mixed/entity/PostDetails.ts +++ b/sample/sample10-mixed/entity/PostDetails.ts @@ -1,6 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; -import {OneToOne, OneToMany, ManyToOne} from "../../../src/index"; +import {PrimaryColumn, Column, Table, OneToOne, OneToMany, ManyToOne} from "../../../src/index"; import {Post} from "./Post"; import {Chapter} from "./Chapter"; import {Category} from "./Category"; diff --git a/sample/sample11-all-types-entity/entity/EverythingEntity.ts b/sample/sample11-all-types-entity/entity/EverythingEntity.ts index a09576a37a..f345c0f2b3 100644 --- a/sample/sample11-all-types-entity/entity/EverythingEntity.ts +++ b/sample/sample11-all-types-entity/entity/EverythingEntity.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; import {CreateDateColumn} from "../../../src/decorator/columns/CreateDateColumn"; import {UpdateDateColumn} from "../../../src/decorator/columns/UpdateDateColumn"; diff --git a/sample/sample12-custom-naming-strategy/entity/Post.ts b/sample/sample12-custom-naming-strategy/entity/Post.ts index dae97dced2..1a63f3e5be 100644 --- a/sample/sample12-custom-naming-strategy/entity/Post.ts +++ b/sample/sample12-custom-naming-strategy/entity/Post.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; @Table("sample1_post") export class Post { diff --git a/sample/sample13-everywhere-abstraction/entity/Blog.ts b/sample/sample13-everywhere-abstraction/entity/Blog.ts index a3b46d2ae5..777bd31662 100644 --- a/sample/sample13-everywhere-abstraction/entity/Blog.ts +++ b/sample/sample13-everywhere-abstraction/entity/Blog.ts @@ -1,7 +1,4 @@ -import {Column} from "../../../src/index"; -import {Table} from "../../../src/index"; -import {ManyToOne} from "../../../src/decorator/relations/ManyToOne"; -import {PostAuthor} from "./PostAuthor"; +import {Column, Table} from "../../../src/index"; import {ManyToMany} from "../../../src/decorator/relations/ManyToMany"; import {PostCategory} from "./PostCategory"; import {JoinTable} from "../../../src/decorator/relations/JoinTable"; diff --git a/sample/sample13-everywhere-abstraction/entity/Post.ts b/sample/sample13-everywhere-abstraction/entity/Post.ts index 86be6dd447..b9f07bc787 100644 --- a/sample/sample13-everywhere-abstraction/entity/Post.ts +++ b/sample/sample13-everywhere-abstraction/entity/Post.ts @@ -1,9 +1,6 @@ -import {Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {Column, Table} from "../../../src/index"; import {PostCategory} from "./PostCategory"; import {ManyToMany} from "../../../src/decorator/relations/ManyToMany"; -import {PostAuthor} from "./PostAuthor"; -import {ManyToOne} from "../../../src/decorator/relations/ManyToOne"; import {JoinTable} from "../../../src/decorator/relations/JoinTable"; import {BaseObject} from "./BaseObject"; diff --git a/sample/sample13-everywhere-abstraction/entity/PostAuthor.ts b/sample/sample13-everywhere-abstraction/entity/PostAuthor.ts index 65f1c0ef5c..e985601bb9 100644 --- a/sample/sample13-everywhere-abstraction/entity/PostAuthor.ts +++ b/sample/sample13-everywhere-abstraction/entity/PostAuthor.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; import {Post} from "./Post"; import {OneToMany} from "../../../src/decorator/relations/OneToMany"; import {PostUser} from "./PostUser"; diff --git a/sample/sample13-everywhere-abstraction/entity/PostCategory.ts b/sample/sample13-everywhere-abstraction/entity/PostCategory.ts index bcf3f6f7fa..97b87a69de 100644 --- a/sample/sample13-everywhere-abstraction/entity/PostCategory.ts +++ b/sample/sample13-everywhere-abstraction/entity/PostCategory.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; import {Post} from "./Post"; import {ManyToMany} from "../../../src/decorator/relations/ManyToMany"; diff --git a/sample/sample13-everywhere-abstraction/entity/PostUser.ts b/sample/sample13-everywhere-abstraction/entity/PostUser.ts index 7faef5042a..fc68cc9598 100644 --- a/sample/sample13-everywhere-abstraction/entity/PostUser.ts +++ b/sample/sample13-everywhere-abstraction/entity/PostUser.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; @Table("sample13_post_user") export class PostUser { diff --git a/sample/sample14-errors-in-wrong-metdata/entity/Post.ts b/sample/sample14-errors-in-wrong-metdata/entity/Post.ts index f2509fe186..095d844531 100644 --- a/sample/sample14-errors-in-wrong-metdata/entity/Post.ts +++ b/sample/sample14-errors-in-wrong-metdata/entity/Post.ts @@ -1,9 +1,6 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; -import {OneToOne} from "../../../src/index"; +import {PrimaryColumn, Column, Table, OneToOne} from "../../../src/index"; import {PostAuthor} from "./PostAuthor"; import {JoinColumn} from "../../../src/decorator/relations/JoinColumn"; -import {ManyToOne} from "../../../src/decorator/relations/ManyToOne"; import {OneToMany} from "../../../src/decorator/relations/OneToMany"; import {JoinTable} from "../../../src/decorator/relations/JoinTable"; import {ManyToMany} from "../../../src/decorator/relations/ManyToMany"; diff --git a/sample/sample14-errors-in-wrong-metdata/entity/PostAuthor.ts b/sample/sample14-errors-in-wrong-metdata/entity/PostAuthor.ts index b65fd0618f..983c204c8f 100644 --- a/sample/sample14-errors-in-wrong-metdata/entity/PostAuthor.ts +++ b/sample/sample14-errors-in-wrong-metdata/entity/PostAuthor.ts @@ -1,7 +1,5 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table, OneToOne} from "../../../src/index"; import {Post} from "./Post"; -import {OneToOne} from "../../../src/index"; import {ManyToOne} from "../../../src/decorator/relations/ManyToOne"; import {ManyToMany} from "../../../src/decorator/relations/ManyToMany"; diff --git a/sample/sample15-we-are-reactive/entity/Post.ts b/sample/sample15-we-are-reactive/entity/Post.ts index 1761208c19..f062ce4dfa 100644 --- a/sample/sample15-we-are-reactive/entity/Post.ts +++ b/sample/sample15-we-are-reactive/entity/Post.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; @Table("sample15_post") export class Post { diff --git a/sample/sample17-versioning/entity/Post.ts b/sample/sample17-versioning/entity/Post.ts index 2918b7457c..960d617fe7 100644 --- a/sample/sample17-versioning/entity/Post.ts +++ b/sample/sample17-versioning/entity/Post.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; import {VersionColumn} from "../../../src/decorator/columns/VersionColumn"; @Table("sample17_post") diff --git a/sample/sample18-lazy-relations/entity/Author.ts b/sample/sample18-lazy-relations/entity/Author.ts index 64663cfa5b..46bee9a1e7 100644 --- a/sample/sample18-lazy-relations/entity/Author.ts +++ b/sample/sample18-lazy-relations/entity/Author.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; import {Post} from "./Post"; import {OneToMany} from "../../../src/decorator/relations/OneToMany"; diff --git a/sample/sample18-lazy-relations/entity/Category.ts b/sample/sample18-lazy-relations/entity/Category.ts index e573c0f5e2..83d24f78e1 100644 --- a/sample/sample18-lazy-relations/entity/Category.ts +++ b/sample/sample18-lazy-relations/entity/Category.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; import {ManyToMany} from "../../../src/decorator/relations/ManyToMany"; import {Post} from "./Post"; diff --git a/sample/sample18-lazy-relations/entity/Post.ts b/sample/sample18-lazy-relations/entity/Post.ts index db4f1f2edd..39f976be3e 100644 --- a/sample/sample18-lazy-relations/entity/Post.ts +++ b/sample/sample18-lazy-relations/entity/Post.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; import {Author} from "./Author"; import {ManyToOne} from "../../../src/decorator/relations/ManyToOne"; import {Category} from "./Category"; diff --git a/sample/sample19-one-side-relations/entity/Author.ts b/sample/sample19-one-side-relations/entity/Author.ts index a6420c18a8..8f4683e30f 100644 --- a/sample/sample19-one-side-relations/entity/Author.ts +++ b/sample/sample19-one-side-relations/entity/Author.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; @Table("sample19_author") export class Author { diff --git a/sample/sample19-one-side-relations/entity/Category.ts b/sample/sample19-one-side-relations/entity/Category.ts index db8632774e..19d0a2b108 100644 --- a/sample/sample19-one-side-relations/entity/Category.ts +++ b/sample/sample19-one-side-relations/entity/Category.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; @Table("sample19_category") export class Category { diff --git a/sample/sample19-one-side-relations/entity/Post.ts b/sample/sample19-one-side-relations/entity/Post.ts index ae050c7b7a..34814d58fa 100644 --- a/sample/sample19-one-side-relations/entity/Post.ts +++ b/sample/sample19-one-side-relations/entity/Post.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; import {Author} from "./Author"; import {ManyToOne} from "../../../src/decorator/relations/ManyToOne"; import {Category} from "./Category"; diff --git a/sample/sample19-one-side-relations/entity/PostMetadata.ts b/sample/sample19-one-side-relations/entity/PostMetadata.ts index 1d48809398..0207f38f24 100644 --- a/sample/sample19-one-side-relations/entity/PostMetadata.ts +++ b/sample/sample19-one-side-relations/entity/PostMetadata.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; @Table("sample19_post_metadata") export class PostMetadata { diff --git a/sample/sample2-one-to-one/entity/Post.ts b/sample/sample2-one-to-one/entity/Post.ts index d69d972920..a6b3521918 100644 --- a/sample/sample2-one-to-one/entity/Post.ts +++ b/sample/sample2-one-to-one/entity/Post.ts @@ -1,7 +1,5 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table, OneToOne} from "../../../src/index"; import {PostDetails} from "./PostDetails"; -import {OneToOne} from "../../../src/index"; import {PostCategory} from "./PostCategory"; import {PostAuthor} from "./PostAuthor"; import {PostInformation} from "./PostInformation"; diff --git a/sample/sample2-one-to-one/entity/PostAuthor.ts b/sample/sample2-one-to-one/entity/PostAuthor.ts index 1b33019327..5c0cf03151 100644 --- a/sample/sample2-one-to-one/entity/PostAuthor.ts +++ b/sample/sample2-one-to-one/entity/PostAuthor.ts @@ -1,7 +1,5 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table, OneToOne} from "../../../src/index"; import {Post} from "./Post"; -import {OneToOne} from "../../../src/index"; @Table("sample2_post_author") export class PostAuthor { diff --git a/sample/sample2-one-to-one/entity/PostCategory.ts b/sample/sample2-one-to-one/entity/PostCategory.ts index 9e995fc71d..ef43ab4470 100644 --- a/sample/sample2-one-to-one/entity/PostCategory.ts +++ b/sample/sample2-one-to-one/entity/PostCategory.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; @Table("sample2_post_category") export class PostCategory { diff --git a/sample/sample2-one-to-one/entity/PostDetails.ts b/sample/sample2-one-to-one/entity/PostDetails.ts index 19d1d1f365..995c86649f 100644 --- a/sample/sample2-one-to-one/entity/PostDetails.ts +++ b/sample/sample2-one-to-one/entity/PostDetails.ts @@ -1,6 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; -import {OneToOne} from "../../../src/index"; +import {PrimaryColumn, Column, Table, OneToOne} from "../../../src/index"; import {Post} from "./Post"; @Table("sample2_post_details") diff --git a/sample/sample2-one-to-one/entity/PostImage.ts b/sample/sample2-one-to-one/entity/PostImage.ts index d39b10b51f..8d060e43db 100644 --- a/sample/sample2-one-to-one/entity/PostImage.ts +++ b/sample/sample2-one-to-one/entity/PostImage.ts @@ -1,7 +1,5 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table, OneToOne} from "../../../src/index"; import {Post} from "./Post"; -import {OneToOne} from "../../../src/index"; @Table("sample2_post_image") export class PostImage { diff --git a/sample/sample2-one-to-one/entity/PostInformation.ts b/sample/sample2-one-to-one/entity/PostInformation.ts index 035952d216..ff44dc13b2 100644 --- a/sample/sample2-one-to-one/entity/PostInformation.ts +++ b/sample/sample2-one-to-one/entity/PostInformation.ts @@ -1,6 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; -import {OneToOne} from "../../../src/index"; +import {PrimaryColumn, Column, Table, OneToOne} from "../../../src/index"; import {Post} from "./Post"; @Table("sample2_post_information") diff --git a/sample/sample2-one-to-one/entity/PostMetadata.ts b/sample/sample2-one-to-one/entity/PostMetadata.ts index eb004dfa6d..edde8c236e 100644 --- a/sample/sample2-one-to-one/entity/PostMetadata.ts +++ b/sample/sample2-one-to-one/entity/PostMetadata.ts @@ -1,7 +1,5 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table, OneToOne} from "../../../src/index"; import {Post} from "./Post"; -import {OneToOne} from "../../../src/index"; @Table("sample2_post_metadata") export class PostMetadata { diff --git a/sample/sample20-join-without-relation/entity/Author.ts b/sample/sample20-join-without-relation/entity/Author.ts index ccd4b2b762..843952d73f 100644 --- a/sample/sample20-join-without-relation/entity/Author.ts +++ b/sample/sample20-join-without-relation/entity/Author.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; @Table("sample20_author") export class Author { diff --git a/sample/sample20-join-without-relation/entity/Category.ts b/sample/sample20-join-without-relation/entity/Category.ts index 6d65eab8bb..7b3db85960 100644 --- a/sample/sample20-join-without-relation/entity/Category.ts +++ b/sample/sample20-join-without-relation/entity/Category.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; @Table("sample20_category") export class Category { diff --git a/sample/sample20-join-without-relation/entity/Post.ts b/sample/sample20-join-without-relation/entity/Post.ts index 8d995aa5d1..17cd059755 100644 --- a/sample/sample20-join-without-relation/entity/Post.ts +++ b/sample/sample20-join-without-relation/entity/Post.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; import {Author} from "./Author"; import {Category} from "./Category"; import {ManyToMany} from "../../../src/decorator/relations/ManyToMany"; diff --git a/sample/sample21-custom-join-table-column/entity/Author.ts b/sample/sample21-custom-join-table-column/entity/Author.ts index 8fe45a94af..18d4d433e6 100644 --- a/sample/sample21-custom-join-table-column/entity/Author.ts +++ b/sample/sample21-custom-join-table-column/entity/Author.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; import {Post} from "./Post"; import {OneToMany} from "../../../src/decorator/relations/OneToMany"; diff --git a/sample/sample21-custom-join-table-column/entity/Category.ts b/sample/sample21-custom-join-table-column/entity/Category.ts index 8c14d1a90a..0cc9da1fe1 100644 --- a/sample/sample21-custom-join-table-column/entity/Category.ts +++ b/sample/sample21-custom-join-table-column/entity/Category.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; import {ManyToMany} from "../../../src/decorator/relations/ManyToMany"; import {Post} from "./Post"; diff --git a/sample/sample21-custom-join-table-column/entity/Post.ts b/sample/sample21-custom-join-table-column/entity/Post.ts index 71c8c23348..3851a49726 100644 --- a/sample/sample21-custom-join-table-column/entity/Post.ts +++ b/sample/sample21-custom-join-table-column/entity/Post.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; import {Author} from "./Author"; import {ManyToOne} from "../../../src/decorator/relations/ManyToOne"; import {Category} from "./Category"; diff --git a/sample/sample23-nested-joins/entity/Author.ts b/sample/sample23-nested-joins/entity/Author.ts index 736036f454..996ac10193 100644 --- a/sample/sample23-nested-joins/entity/Author.ts +++ b/sample/sample23-nested-joins/entity/Author.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; @Table("sample23_author") export class Author { diff --git a/sample/sample23-nested-joins/entity/Category.ts b/sample/sample23-nested-joins/entity/Category.ts index 2632769cc3..eaa0dadc4f 100644 --- a/sample/sample23-nested-joins/entity/Category.ts +++ b/sample/sample23-nested-joins/entity/Category.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; import {Author} from "./Author"; import {ManyToMany} from "../../../src/decorator/relations/ManyToMany"; import {JoinTable} from "../../../src/decorator/relations/JoinTable"; diff --git a/sample/sample23-nested-joins/entity/Post.ts b/sample/sample23-nested-joins/entity/Post.ts index 26ed2cfcc0..286f65eb76 100644 --- a/sample/sample23-nested-joins/entity/Post.ts +++ b/sample/sample23-nested-joins/entity/Post.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; import {Category} from "./Category"; import {Author} from "./Author"; import {ManyToMany} from "../../../src/decorator/relations/ManyToMany"; diff --git a/sample/sample25-insert-from-inverse-side/entity/Author.ts b/sample/sample25-insert-from-inverse-side/entity/Author.ts index b545c0a75d..3a919ce789 100644 --- a/sample/sample25-insert-from-inverse-side/entity/Author.ts +++ b/sample/sample25-insert-from-inverse-side/entity/Author.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; import {OneToMany} from "../../../src/decorator/relations/OneToMany"; import {Post} from "./Post"; diff --git a/sample/sample25-insert-from-inverse-side/entity/Post.ts b/sample/sample25-insert-from-inverse-side/entity/Post.ts index 08aa66992b..74f7f3e47b 100644 --- a/sample/sample25-insert-from-inverse-side/entity/Post.ts +++ b/sample/sample25-insert-from-inverse-side/entity/Post.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; import {Author} from "./Author"; import {ManyToOne} from "../../../src/decorator/relations/ManyToOne"; diff --git a/sample/sample26-embedded-tables/entity/Post.ts b/sample/sample26-embedded-tables/entity/Post.ts index e0b1280d34..560b33a072 100644 --- a/sample/sample26-embedded-tables/entity/Post.ts +++ b/sample/sample26-embedded-tables/entity/Post.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; import {Counters} from "./Counters"; import {Embedded} from "../../../src/decorator/Embedded"; diff --git a/sample/sample26-embedded-tables/entity/Question.ts b/sample/sample26-embedded-tables/entity/Question.ts index f2e0d8438a..346ebee168 100644 --- a/sample/sample26-embedded-tables/entity/Question.ts +++ b/sample/sample26-embedded-tables/entity/Question.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; import {Counters} from "./Counters"; import {Embedded} from "../../../src/decorator/Embedded"; diff --git a/sample/sample3-many-to-one/entity/Post.ts b/sample/sample3-many-to-one/entity/Post.ts index 830bea69db..4ddb7351fd 100644 --- a/sample/sample3-many-to-one/entity/Post.ts +++ b/sample/sample3-many-to-one/entity/Post.ts @@ -1,7 +1,5 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table, ManyToOne} from "../../../src/index"; import {PostDetails} from "./PostDetails"; -import {ManyToOne} from "../../../src/index"; import {PostCategory} from "./PostCategory"; import {PostAuthor} from "./PostAuthor"; import {PostInformation} from "./PostInformation"; diff --git a/sample/sample3-many-to-one/entity/PostAuthor.ts b/sample/sample3-many-to-one/entity/PostAuthor.ts index b1a21f1fe6..3590ca08d6 100644 --- a/sample/sample3-many-to-one/entity/PostAuthor.ts +++ b/sample/sample3-many-to-one/entity/PostAuthor.ts @@ -1,7 +1,5 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table, OneToMany} from "../../../src/index"; import {Post} from "./Post"; -import {OneToMany} from "../../../src/index"; @Table("sample3_post_author") export class PostAuthor { diff --git a/sample/sample3-many-to-one/entity/PostCategory.ts b/sample/sample3-many-to-one/entity/PostCategory.ts index 7a4dfe5cc6..c5f7819480 100644 --- a/sample/sample3-many-to-one/entity/PostCategory.ts +++ b/sample/sample3-many-to-one/entity/PostCategory.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; @Table("sample3_post_category") export class PostCategory { diff --git a/sample/sample3-many-to-one/entity/PostDetails.ts b/sample/sample3-many-to-one/entity/PostDetails.ts index 370e38f726..dfc433fcbc 100644 --- a/sample/sample3-many-to-one/entity/PostDetails.ts +++ b/sample/sample3-many-to-one/entity/PostDetails.ts @@ -1,6 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; -import {OneToMany} from "../../../src/index"; +import {PrimaryColumn, Column, Table, OneToMany} from "../../../src/index"; import {Post} from "./Post"; @Table("sample3_post_details") diff --git a/sample/sample3-many-to-one/entity/PostImage.ts b/sample/sample3-many-to-one/entity/PostImage.ts index eb57af3305..1db1633392 100644 --- a/sample/sample3-many-to-one/entity/PostImage.ts +++ b/sample/sample3-many-to-one/entity/PostImage.ts @@ -1,7 +1,5 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table, OneToMany} from "../../../src/index"; import {Post} from "./Post"; -import {OneToMany} from "../../../src/index"; @Table("sample3_post_image") export class PostImage { diff --git a/sample/sample3-many-to-one/entity/PostInformation.ts b/sample/sample3-many-to-one/entity/PostInformation.ts index a25ee8f20b..988c8e95ab 100644 --- a/sample/sample3-many-to-one/entity/PostInformation.ts +++ b/sample/sample3-many-to-one/entity/PostInformation.ts @@ -1,6 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; -import {OneToMany} from "../../../src/index"; +import {PrimaryColumn, Column, Table, OneToMany} from "../../../src/index"; import {Post} from "./Post"; @Table("sample3_post_information") diff --git a/sample/sample3-many-to-one/entity/PostMetadata.ts b/sample/sample3-many-to-one/entity/PostMetadata.ts index 38004b028d..765a916e93 100644 --- a/sample/sample3-many-to-one/entity/PostMetadata.ts +++ b/sample/sample3-many-to-one/entity/PostMetadata.ts @@ -1,7 +1,5 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table, OneToMany} from "../../../src/index"; import {Post} from "./Post"; -import {OneToMany} from "../../../src/index"; @Table("sample3_post_metadata") export class PostMetadata { diff --git a/sample/sample4-many-to-many/entity/Post.ts b/sample/sample4-many-to-many/entity/Post.ts index 69423cf17c..e8ad8a4e2b 100644 --- a/sample/sample4-many-to-many/entity/Post.ts +++ b/sample/sample4-many-to-many/entity/Post.ts @@ -1,7 +1,5 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table, ManyToMany} from "../../../src/index"; import {PostDetails} from "./PostDetails"; -import {ManyToMany} from "../../../src/index"; import {PostCategory} from "./PostCategory"; import {PostAuthor} from "./PostAuthor"; import {PostInformation} from "./PostInformation"; diff --git a/sample/sample4-many-to-many/entity/PostAuthor.ts b/sample/sample4-many-to-many/entity/PostAuthor.ts index 955142f9fc..40c5ee1160 100644 --- a/sample/sample4-many-to-many/entity/PostAuthor.ts +++ b/sample/sample4-many-to-many/entity/PostAuthor.ts @@ -1,7 +1,5 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table, ManyToMany} from "../../../src/index"; import {Post} from "./Post"; -import {ManyToMany} from "../../../src/index"; @Table("sample4_post_author") export class PostAuthor { diff --git a/sample/sample4-many-to-many/entity/PostCategory.ts b/sample/sample4-many-to-many/entity/PostCategory.ts index bc387fb9d4..6554b1f9e0 100644 --- a/sample/sample4-many-to-many/entity/PostCategory.ts +++ b/sample/sample4-many-to-many/entity/PostCategory.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; @Table("sample4_post_category") export class PostCategory { diff --git a/sample/sample4-many-to-many/entity/PostDetails.ts b/sample/sample4-many-to-many/entity/PostDetails.ts index d3caa967a1..daa54f54a6 100644 --- a/sample/sample4-many-to-many/entity/PostDetails.ts +++ b/sample/sample4-many-to-many/entity/PostDetails.ts @@ -1,8 +1,5 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; -import {ManyToMany} from "../../../src/index"; +import {PrimaryColumn, Column, Table, ManyToMany} from "../../../src/index"; import {Post} from "./Post"; -import {JoinTable} from "../../../src/decorator/relations/JoinTable"; @Table("sample4_post_details") export class PostDetails { diff --git a/sample/sample4-many-to-many/entity/PostImage.ts b/sample/sample4-many-to-many/entity/PostImage.ts index dcc955aa4c..5115ee9d50 100644 --- a/sample/sample4-many-to-many/entity/PostImage.ts +++ b/sample/sample4-many-to-many/entity/PostImage.ts @@ -1,7 +1,5 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table, ManyToMany} from "../../../src/index"; import {Post} from "./Post"; -import {ManyToMany} from "../../../src/index"; @Table("sample4_post_image") export class PostImage { diff --git a/sample/sample4-many-to-many/entity/PostInformation.ts b/sample/sample4-many-to-many/entity/PostInformation.ts index 0f0f58965b..cfaa80032c 100644 --- a/sample/sample4-many-to-many/entity/PostInformation.ts +++ b/sample/sample4-many-to-many/entity/PostInformation.ts @@ -1,6 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; -import {ManyToMany} from "../../../src/index"; +import {PrimaryColumn, Column, Table, ManyToMany} from "../../../src/index"; import {Post} from "./Post"; @Table("sample4_post_information") diff --git a/sample/sample4-many-to-many/entity/PostMetadata.ts b/sample/sample4-many-to-many/entity/PostMetadata.ts index 3586d8d95d..edec5a1273 100644 --- a/sample/sample4-many-to-many/entity/PostMetadata.ts +++ b/sample/sample4-many-to-many/entity/PostMetadata.ts @@ -1,7 +1,5 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table, ManyToMany} from "../../../src/index"; import {Post} from "./Post"; -import {ManyToMany} from "../../../src/index"; @Table("sample4_post_metadata") export class PostMetadata { diff --git a/sample/sample5-subscribers/entity/Post.ts b/sample/sample5-subscribers/entity/Post.ts index 10427d86e5..17a09b4304 100644 --- a/sample/sample5-subscribers/entity/Post.ts +++ b/sample/sample5-subscribers/entity/Post.ts @@ -1,9 +1,6 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; -import {ManyToMany} from "../../../src/index"; +import {PrimaryColumn, Column, Table, ManyToMany} from "../../../src/index"; import {PostCategory} from "./PostCategory"; import {PostAuthor} from "./PostAuthor"; -import {OneToMany} from "../../../src/decorator/relations/OneToMany"; import {ManyToOne} from "../../../src/decorator/relations/ManyToOne"; import {JoinTable} from "../../../src/decorator/relations/JoinTable"; diff --git a/sample/sample5-subscribers/entity/PostAuthor.ts b/sample/sample5-subscribers/entity/PostAuthor.ts index 757defb24e..f7e1e5d9fd 100644 --- a/sample/sample5-subscribers/entity/PostAuthor.ts +++ b/sample/sample5-subscribers/entity/PostAuthor.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; import {Post} from "./Post"; import {OneToMany} from "../../../src/decorator/relations/OneToMany"; diff --git a/sample/sample5-subscribers/entity/PostCategory.ts b/sample/sample5-subscribers/entity/PostCategory.ts index 807a6be812..c4233bd869 100644 --- a/sample/sample5-subscribers/entity/PostCategory.ts +++ b/sample/sample5-subscribers/entity/PostCategory.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; import {Post} from "./Post"; import {ManyToMany} from "../../../src/decorator/relations/ManyToMany"; diff --git a/sample/sample6-abstract-table/entity/Blog.ts b/sample/sample6-abstract-table/entity/Blog.ts index 29976fcd13..ff57f09cbd 100644 --- a/sample/sample6-abstract-table/entity/Blog.ts +++ b/sample/sample6-abstract-table/entity/Blog.ts @@ -1,5 +1,4 @@ -import {Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {Column, Table} from "../../../src/index"; import {BasePost} from "./BasePost"; import {ManyToOne} from "../../../src/decorator/relations/ManyToOne"; import {PostAuthor} from "./PostAuthor"; diff --git a/sample/sample6-abstract-table/entity/Post.ts b/sample/sample6-abstract-table/entity/Post.ts index bfc8ee0d58..4ab93b0c24 100644 --- a/sample/sample6-abstract-table/entity/Post.ts +++ b/sample/sample6-abstract-table/entity/Post.ts @@ -1,5 +1,4 @@ -import {Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {Column, Table} from "../../../src/index"; import {BasePost} from "./BasePost"; import {PostCategory} from "./PostCategory"; import {ManyToMany} from "../../../src/decorator/relations/ManyToMany"; diff --git a/sample/sample6-abstract-table/entity/PostAuthor.ts b/sample/sample6-abstract-table/entity/PostAuthor.ts index 1ec4b7e10c..219ef7bd98 100644 --- a/sample/sample6-abstract-table/entity/PostAuthor.ts +++ b/sample/sample6-abstract-table/entity/PostAuthor.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; import {Post} from "./Post"; import {OneToMany} from "../../../src/decorator/relations/OneToMany"; diff --git a/sample/sample6-abstract-table/entity/PostCategory.ts b/sample/sample6-abstract-table/entity/PostCategory.ts index e528fe3541..8d02a5989a 100644 --- a/sample/sample6-abstract-table/entity/PostCategory.ts +++ b/sample/sample6-abstract-table/entity/PostCategory.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; import {Post} from "./Post"; import {ManyToMany} from "../../../src/decorator/relations/ManyToMany"; diff --git a/sample/sample7-pagination/entity/Post.ts b/sample/sample7-pagination/entity/Post.ts index ac79d16650..74cd8638eb 100644 --- a/sample/sample7-pagination/entity/Post.ts +++ b/sample/sample7-pagination/entity/Post.ts @@ -1,6 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; -import {ManyToMany} from "../../../src/index"; +import {PrimaryColumn, Column, Table, ManyToMany} from "../../../src/index"; import {PostCategory} from "./PostCategory"; import {PostAuthor} from "./PostAuthor"; import {ManyToOne} from "../../../src/decorator/relations/ManyToOne"; diff --git a/sample/sample7-pagination/entity/PostAuthor.ts b/sample/sample7-pagination/entity/PostAuthor.ts index 036dd39ace..7d42bf9cc6 100644 --- a/sample/sample7-pagination/entity/PostAuthor.ts +++ b/sample/sample7-pagination/entity/PostAuthor.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; import {Post} from "./Post"; import {OneToMany} from "../../../src/decorator/relations/OneToMany"; diff --git a/sample/sample7-pagination/entity/PostCategory.ts b/sample/sample7-pagination/entity/PostCategory.ts index e495f8692c..33da9b4dda 100644 --- a/sample/sample7-pagination/entity/PostCategory.ts +++ b/sample/sample7-pagination/entity/PostCategory.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; import {Post} from "./Post"; import {ManyToMany} from "../../../src/decorator/relations/ManyToMany"; diff --git a/sample/sample8-self-referencing/entity/Category.ts b/sample/sample8-self-referencing/entity/Category.ts index 4951b9d44b..6b3e78f92c 100644 --- a/sample/sample8-self-referencing/entity/Category.ts +++ b/sample/sample8-self-referencing/entity/Category.ts @@ -1,6 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; -import {ManyToMany} from "../../../src/index"; +import {PrimaryColumn, Column, Table, ManyToMany} from "../../../src/index"; import {ManyToOne} from "../../../src/decorator/relations/ManyToOne"; import {OneToMany} from "../../../src/decorator/relations/OneToMany"; import {OneToOne} from "../../../src/decorator/relations/OneToOne"; diff --git a/sample/sample9-entity-listeners/entity/Post.ts b/sample/sample9-entity-listeners/entity/Post.ts index 806cad21b1..97b2805903 100644 --- a/sample/sample9-entity-listeners/entity/Post.ts +++ b/sample/sample9-entity-listeners/entity/Post.ts @@ -1,6 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; -import {ManyToMany} from "../../../src/index"; +import {PrimaryColumn, Column, Table, ManyToMany} from "../../../src/index"; import {PostCategory} from "./PostCategory"; import {PostAuthor} from "./PostAuthor"; import {ManyToOne} from "../../../src/decorator/relations/ManyToOne"; diff --git a/sample/sample9-entity-listeners/entity/PostAuthor.ts b/sample/sample9-entity-listeners/entity/PostAuthor.ts index fd542c2722..9889a037b4 100644 --- a/sample/sample9-entity-listeners/entity/PostAuthor.ts +++ b/sample/sample9-entity-listeners/entity/PostAuthor.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; import {Post} from "./Post"; import {OneToMany} from "../../../src/decorator/relations/OneToMany"; import {AfterRemove} from "../../../src/decorator/listeners/AfterRemove"; diff --git a/sample/sample9-entity-listeners/entity/PostCategory.ts b/sample/sample9-entity-listeners/entity/PostCategory.ts index 23b4eba07b..230ab116e6 100644 --- a/sample/sample9-entity-listeners/entity/PostCategory.ts +++ b/sample/sample9-entity-listeners/entity/PostCategory.ts @@ -1,5 +1,4 @@ -import {PrimaryColumn, Column} from "../../../src/index"; -import {Table} from "../../../src/index"; +import {PrimaryColumn, Column, Table} from "../../../src/index"; import {Post} from "./Post"; import {ManyToMany} from "../../../src/decorator/relations/ManyToMany"; import {AfterRemove} from "../../../src/decorator/listeners/AfterRemove"; diff --git a/src/commands/QueryCommand.ts b/src/commands/QueryCommand.ts index ac2712293c..8e331b8620 100644 --- a/src/commands/QueryCommand.ts +++ b/src/commands/QueryCommand.ts @@ -1,4 +1,4 @@ -import {createConnectionFromConfig} from "../index"; +import {createConnection} from "../index"; /** * Executes an sql query on the given connection. @@ -20,7 +20,7 @@ export class QueryCommand { try { process.env.SKIP_SCHEMA_CREATION = true; const connectionName = "default" || argv.connection; - const connection = await createConnectionFromConfig(connectionName); + const connection = await createConnection(connectionName); const queryRunner = await connection.driver.createQueryRunner(); const queryResult = await queryRunner.query(argv._[1]); console.log("Query executed. Result: ", queryResult); diff --git a/src/commands/SchemaDropCommand.ts b/src/commands/SchemaDropCommand.ts index a927fdea30..b35b1f5642 100644 --- a/src/commands/SchemaDropCommand.ts +++ b/src/commands/SchemaDropCommand.ts @@ -1,4 +1,4 @@ -import {createConnectionFromConfig, createConnectionsFromConfig} from "../index"; +import {createConnections, createConnection} from "../index"; /** * Drops all tables of the database from the given connection. @@ -21,11 +21,11 @@ export class SchemaDropCommand { process.env.LOGGER_CLI_SCHEMA_SYNC = true; process.env.SKIP_SCHEMA_CREATION = true; if (argv.connection) { - const connection = await createConnectionFromConfig(argv.connection); + const connection = await createConnection(argv.connection); await connection.dropDatabase(); await connection.close(); } else { - const connections = await createConnectionsFromConfig(); + const connections = await createConnections(); await Promise.all(connections.map(connection => connection.dropDatabase())); await Promise.all(connections.map(connection => connection.close())); } diff --git a/src/commands/SchemaSyncCommand.ts b/src/commands/SchemaSyncCommand.ts index 8becb55083..ab0c21625b 100644 --- a/src/commands/SchemaSyncCommand.ts +++ b/src/commands/SchemaSyncCommand.ts @@ -1,4 +1,4 @@ -import {createConnectionFromConfig, createConnectionsFromConfig} from "../index"; +import {createConnections, createConnection} from "../index"; /** * Synchronizes database schema with entities. @@ -21,11 +21,11 @@ export class SchemaSyncCommand { process.env.LOGGER_CLI_SCHEMA_SYNC = true; process.env.SKIP_SCHEMA_CREATION = true; if (argv.connection) { - const connection = await createConnectionFromConfig(argv.connection); + const connection = await createConnection(argv.connection); await connection.syncSchema(false); await connection.close(); } else { - const connections = await createConnectionsFromConfig(); + const connections = await createConnections(); await Promise.all(connections.map(connection => connection.syncSchema(false))); await Promise.all(connections.map(connection => connection.close())); } diff --git a/src/connection/ConnectionManager.ts b/src/connection/ConnectionManager.ts index 1054717012..fb8cf2b6f4 100644 --- a/src/connection/ConnectionManager.ts +++ b/src/connection/ConnectionManager.ts @@ -1,3 +1,4 @@ +import * as fs from "fs"; import {Connection} from "./Connection"; import {ConnectionNotFoundError} from "./error/ConnectionNotFoundError"; import {MysqlDriver} from "../driver/mysql/MysqlDriver"; @@ -11,16 +12,17 @@ import {Logger} from "../logger/Logger"; import {SqliteDriver} from "../driver/sqlite/SqliteDriver"; import {OracleDriver} from "../driver/oracle/OracleDriver"; import {SqlServerDriver} from "../driver/sqlserver/SqlServerDriver"; -import {OrmConfigConnectionOptions} from "./OrmConfigConnectionOptions"; +import {OrmUtils} from "../util/OrmUtils"; +import {CannotDetermineConnectionOptionsError} from "./error/CannotDetermineConnectionOptionsError"; /** - * Connection manager holds all connections made to the databases and providers helper management functions - * for all exist connections. + * Connection manager holds all connections made to the databases + * and provides functions to easily create new connections. */ export class ConnectionManager { // ------------------------------------------------------------------------- - // Properties + // Private Properties // ------------------------------------------------------------------------- /** @@ -33,49 +35,278 @@ export class ConnectionManager { // ------------------------------------------------------------------------- /** - * Creates a new connection based on the connection options from "ormconfig.json" - * and registers a new connection in the manager. - * Optionally you can specify a path to the json configuration. - * If path is not given, then ormconfig.json file will be searched near node_modules directory. + * Gets registered connection with the given name. + * If connection name is not given then it will get a default connection. + * Throws exception if connection with the given name was not found. */ - async createFromConfigAndConnectToAll(path?: string): Promise { - const optionsArray: OrmConfigConnectionOptions[] = require(path || (require("app-root-path").path + "/ormconfig.json")); - if (!optionsArray) - throw new Error(`Configuration ${path || "ormconfig.json"} was not found. Add connection configuration inside ormconfig.json file.`); + get(name: string = "default"): Connection { + const connection = this.connections.find(connection => connection.name === name); + if (!connection) + throw new ConnectionNotFoundError(name); - const promises = optionsArray - .filter(options => !options.environment || options.environment === process.env.NODE_ENV) // skip connection creation if environment is set in the options, and its not equal to the value in the NODE_ENV variable - .map(options => this.createAndConnect(options)); + return connection; + } - return Promise.all(promises); + /** + * Creates a new connection based on the given connection options and registers it in the manager. + * You need to manually call #connect method to establish connection. + * Note that dropSchemaOnConnection and autoSchemaCreate options of a ConnectionOptions will not work there - use + * createAndConnect method to use them. + */ + create(options: ConnectionOptions): Connection { + + const logger = new Logger(options.logging || {}); + const driver = this.createDriver(options.driver, logger); + const connection = this.createConnection(options.name || "default", driver, logger); + + // import entity schemas + if (options.entitySchemas) { + const [directories, classes] = this.splitStringsAndClasses(options.entitySchemas); + connection + .importEntitySchemas(classes) + .importEntitySchemaFromDirectories(directories); + } + + // import entities + if (options.entities) { + const [directories, classes] = this.splitStringsAndClasses(options.entities); + connection + .importEntities(classes) + .importEntitiesFromDirectories(directories); + } + + // import subscriber + if (options.subscribers) { + const [directories, classes] = this.splitStringsAndClasses(options.subscribers); + connection + .importSubscribers(classes) + .importSubscribersFromDirectories(directories); + } + + // import naming strategies + if (options.namingStrategies) { + const [directories, classes] = this.splitStringsAndClasses(options.namingStrategies); + connection + .importNamingStrategies(classes) + .importNamingStrategiesFromDirectories(directories); + } + + // set naming strategy to be used for this connection + if (options.usedNamingStrategy) + connection.useNamingStrategy(options.usedNamingStrategy as any); + + return connection; } /** - * Creates a new connection based on the connection options from "ormconfig.json" - * and registers a new connection in the manager. - * Optionally you can specify a path to the json configuration. - * If path is not given, then ormconfig.json file will be searched near node_modules directory. + * Creates a new connection and registers it in the manager. + * + * If connection options were not specified, then it will try to create connection automatically. + * + * First, it will try to find a "default" configuration from ormconfig.json. + * You can also specify a connection name to use from ormconfig.json, + * and you even can specify a path to custom ormconfig.json file. + * + * In the case if options were not specified, and ormconfig.json file also wasn't found, + * it will try to create connection from environment variables. + * There are several environment variables you can set: + * + * - TYPEORM_DRIVER_TYPE - driver type. Can be "mysql", "postgres", "mariadb", "sqlite", "oracle" or "mssql". + * - TYPEORM_URL - database connection url. Should be a string. + * - TYPEORM_HOST - database host. Should be a string. + * - TYPEORM_PORT - database access port. Should be a number. + * - TYPEORM_USERNAME - database username. Should be a string. + * - TYPEORM_PASSWORD - database user's password. Should be a string. + * - TYPEORM_SID - database's SID. Used only for oracle databases. Should be a string. + * - TYPEORM_STORAGE - database's storage url. Used only for sqlite databases. Should be a string. + * - TYPEORM_USE_POOL - indicates if connection pooling should be enabled. By default its enabled. Should be boolean-like value. + * - TYPEORM_DRIVER_EXTRA - extra options to be passed to the driver. Should be a serialized json string of options. + * - TYPEORM_AUTO_SCHEMA_CREATE - indicates if automatic schema synchronization will be performed on each application run. Should be boolean-like value. + * - TYPEORM_ENTITIES - list of directories containing entities to load. Should be string - directory names (can be patterns) split by a comma. + * - TYPEORM_SUBSCRIBERS - list of directories containing subscribers to load. Should be string - directory names (can be patterns) split by a comma. + * - TYPEORM_ENTITY_SCHEMAS - list of directories containing entity schemas to load. Should be string - directory names (can be patterns) split by a comma. + * - TYPEORM_NAMING_STRATEGIES - list of directories containing custom naming strategies to load. Should be string - directory names (can be patterns) split by a comma. + * - TYPEORM_LOGGING_QUERIES - indicates if each executed query must be logged. Should be boolean-like value. + * - TYPEORM_LOGGING_FAILED_QUERIES - indicates if logger should log failed query's error. Should be boolean-like value. + * - TYPEORM_LOGGING_ONLY_FAILED_QUERIES - indicates if only failed queries must be logged. Should be boolean-like value. + * + * TYPEORM_DRIVER_TYPE variable is required. Depend on the driver type some other variables may be required too. */ - async createFromConfigAndConnect(connectionName: string = "default", path?: string): Promise { - const optionsArray: OrmConfigConnectionOptions[] = require(path || (require("app-root-path").path + "/ormconfig.json")); - if (!optionsArray) - throw new Error(`Configuration ${path || "ormconfig.json"} was not found. Add connection configuration inside ormconfig.json file.`); + async createAndConnect(): Promise; - const environmentLessOptions = optionsArray.filter(options => (options.name || "default") === connectionName); - const options = environmentLessOptions.filter(options => !options.environment || options.environment === process.env.NODE_ENV); // skip connection creation if environment is set in the options, and its not equal to the value in the NODE_ENV variable + /** + * Creates connection from the given connection options and registers it in the manager. + */ + async createAndConnect(options?: ConnectionOptions): Promise; - if (!options.length) - throw new Error(`Connection "${connectionName}" ${process.env.NODE_ENV ? "for the environment " + process.env.NODE_ENV + " " : ""}was not found in the json configuration file.` + - (environmentLessOptions.length ? ` However there are such configurations for other environments: ${environmentLessOptions.map(options => options.environment).join(", ")}.` : "")); + /** + * Creates connection with the given connection name from the ormconfig.json file and registers it in the manager. + * Optionally you can specify a path to custom ormconfig.json file. + */ + async createAndConnect(connectionNameFromConfig: string, ormConfigPath?: string): Promise; + + /** + * Creates connection and and registers it in the manager. + */ + async createAndConnect(optionsOrConnectionNameFromConfig?: ConnectionOptions|string, ormConfigPath?: string): Promise { + + // if connection options are given, then create connection from them + if (optionsOrConnectionNameFromConfig && optionsOrConnectionNameFromConfig instanceof Object) + return this.createAndConnectByConnectionOptions(optionsOrConnectionNameFromConfig as ConnectionOptions); + + // if connection name is specified then explicitly try to load connection options from it + if (typeof optionsOrConnectionNameFromConfig === "string") + return this.createFromConfigAndConnect(optionsOrConnectionNameFromConfig || "default", ormConfigPath); + + // if nothing is specified then try to silently load config from ormconfig.json + if (this.hasDefaultConfigurationInConfigurationFile()) + return this.createFromConfigAndConnect("default"); + + // if driver type is set in environment variables then try to create connection from env variables + if (this.hasDefaultConfigurationInEnvironmentVariables()) + return this.createFromEnvAndConnect(); + + throw new CannotDetermineConnectionOptionsError(); + } + + /** + * Creates new connections and registers them in the manager. + * + * If array of connection options were not specified, then it will try to create them automatically + * from ormconfig.json. You can also specify path to your custom ormconfig.json file. + * + * In the case if options were not specified, and ormconfig.json file also wasn't found, + * it will try to create connection from environment variables. + * There are several environment variables you can set: + * + * - TYPEORM_DRIVER_TYPE - driver type. Can be "mysql", "postgres", "mariadb", "sqlite", "oracle" or "mssql". + * - TYPEORM_URL - database connection url. Should be a string. + * - TYPEORM_HOST - database host. Should be a string. + * - TYPEORM_PORT - database access port. Should be a number. + * - TYPEORM_USERNAME - database username. Should be a string. + * - TYPEORM_PASSWORD - database user's password. Should be a string. + * - TYPEORM_SID - database's SID. Used only for oracle databases. Should be a string. + * - TYPEORM_STORAGE - database's storage url. Used only for sqlite databases. Should be a string. + * - TYPEORM_USE_POOL - indicates if connection pooling should be enabled. By default its enabled. Should be boolean-like value. + * - TYPEORM_DRIVER_EXTRA - extra options to be passed to the driver. Should be a serialized json string of options. + * - TYPEORM_AUTO_SCHEMA_CREATE - indicates if automatic schema synchronization will be performed on each application run. Should be boolean-like value. + * - TYPEORM_ENTITIES - list of directories containing entities to load. Should be string - directory names (can be patterns) split by a comma. + * - TYPEORM_SUBSCRIBERS - list of directories containing subscribers to load. Should be string - directory names (can be patterns) split by a comma. + * - TYPEORM_ENTITY_SCHEMAS - list of directories containing entity schemas to load. Should be string - directory names (can be patterns) split by a comma. + * - TYPEORM_NAMING_STRATEGIES - list of directories containing custom naming strategies to load. Should be string - directory names (can be patterns) split by a comma. + * - TYPEORM_LOGGING_QUERIES - indicates if each executed query must be logged. Should be boolean-like value. + * - TYPEORM_LOGGING_FAILED_QUERIES - indicates if logger should log failed query's error. Should be boolean-like value. + * - TYPEORM_LOGGING_ONLY_FAILED_QUERIES - indicates if only failed queries must be logged. Should be boolean-like value. + * + * TYPEORM_DRIVER_TYPE variable is required. Depend on the driver type some other variables may be required too. + */ + async createAndConnectToAll(): Promise; + + /** + * Creates connections from the given connection options and registers them in the manager. + */ + async createAndConnectToAll(options?: ConnectionOptions[]): Promise; + + /** + * Creates connections from the ormconfig.json file. + * Optionally you can specify a path to custom ormconfig.json file. + */ + async createAndConnectToAll(ormConfigPath?: string): Promise; + + /** + * Creates connection and and registers them in the manager. + */ + async createAndConnectToAll(optionsOrOrmConfigFilePath?: ConnectionOptions[]|string): Promise { - return this.createAndConnect(options[0]); + // if connection options are given, then create connection from them + if (optionsOrOrmConfigFilePath && optionsOrOrmConfigFilePath instanceof Array) + return Promise.all(optionsOrOrmConfigFilePath.map(options => { + return this.createAndConnectByConnectionOptions(options as ConnectionOptions); + })); + + // if connection name is specified then explicitly try to load connection options from it + if (typeof optionsOrOrmConfigFilePath === "string") + return this.createFromConfigAndConnectToAll(optionsOrOrmConfigFilePath as string); + + // if nothing is specified then try to silently load config from ormconfig.json + if (this.hasOrmConfigurationFile()) + return this.createFromConfigAndConnectToAll(); + + // if driver type is set in environment variables then try to create connection from env variables + if (this.hasDefaultConfigurationInEnvironmentVariables()) + return [await this.createFromEnvAndConnect()]; + + throw new CannotDetermineConnectionOptionsError(); + } + + // ------------------------------------------------------------------------- + // Private Methods + // ------------------------------------------------------------------------- + + /** + * Checks if ormconfig.json exists. + */ + private hasOrmConfigurationFile(): boolean { + const path = require("app-root-path").path + "/ormconfig.json"; + if (!fs.existsSync(path)) + return false; + + const configuration: ConnectionOptions[]|ConnectionOptions = require(path); + if (configuration instanceof Array) { + return configuration + .filter(options => !options.environment || options.environment === process.env.NODE_ENV) + .length > 0; + + } else if (configuration instanceof Object) { + if (configuration.environment && configuration.environment !== process.env.NODE_ENV) + return false; + + return Object.keys(configuration).length > 0; + } + + return false; + } + + /** + * Checks if there is a default connection in the ormconfig.json file. + */ + private hasDefaultConfigurationInConfigurationFile(): boolean { + const path = require("app-root-path").path + "/ormconfig.json"; + if (!fs.existsSync(path)) + return false; + + const configuration: ConnectionOptions[]|ConnectionOptions = require(path); + if (configuration instanceof Array) { + return !!configuration + .filter(options => !options.environment || options.environment === process.env.NODE_ENV) + .find(config => !!config.name || config.name === "default"); + + } else if (configuration instanceof Object) { + if (!configuration.name || + configuration.name !== "default") + return false; + + if (configuration.environment && configuration.environment !== process.env.NODE_ENV) + return false; + + return true; + } + + return false; + } + + /** + * Checks if environment variables contains connection options. + */ + private hasDefaultConfigurationInEnvironmentVariables(): boolean { + return !!process.env.TYPEORM_DRIVER_TYPE; } /** * Allows to quickly create a connection based on the environment variable values. */ - async createFromEnvAndConnect(): Promise { - return this.createAndConnect({ + private async createFromEnvAndConnect(): Promise { + return this.createAndConnectByConnectionOptions({ driver: { type: process.env.TYPEORM_DRIVER_TYPE, url: process.env.TYPEORM_URL, @@ -86,110 +317,87 @@ export class ConnectionManager { database: process.env.TYPEORM_DATABASE, sid: process.env.TYPEORM_SID, storage: process.env.TYPEORM_STORAGE, + usePool: process.env.TYPEORM_USE_POOL !== undefined ? OrmUtils.toBoolean(process.env.TYPEORM_USE_POOL) : undefined, // special check for defined is required here extra: process.env.TYPEORM_DRIVER_EXTRA ? JSON.parse(process.env.TYPEORM_DRIVER_EXTRA) : undefined }, - autoSchemaCreate: process.env.TYPEORM_AUTO_SCHEMA_CREATE, + autoSchemaCreate: OrmUtils.toBoolean(process.env.TYPEORM_AUTO_SCHEMA_CREATE), entities: process.env.TYPEORM_ENTITIES ? process.env.TYPEORM_ENTITIES.split(",") : [], subscribers: process.env.TYPEORM_SUBSCRIBERS ? process.env.TYPEORM_SUBSCRIBERS.split(",") : [], entitySchemas: process.env.TYPEORM_ENTITY_SCHEMAS ? process.env.TYPEORM_ENTITY_SCHEMAS.split(",") : [], namingStrategies: process.env.TYPEORM_NAMING_STRATEGIES ? process.env.TYPEORM_NAMING_STRATEGIES.split(",") : [], usedNamingStrategy: process.env.TYPEORM_USED_NAMING_STRATEGY, logging: { - logQueries: process.env.TYPEORM_LOGGING_QUERIES, - logFailedQueryError: process.env.TYPEORM_LOGGING_FAILED_QUERIES, - logOnlyFailedQueries: process.env.TYPEORM_LOGGING_ONLY_FAILED_QUERIES, + logQueries: OrmUtils.toBoolean(process.env.TYPEORM_LOGGING_QUERIES), + logFailedQueryError: OrmUtils.toBoolean(process.env.TYPEORM_LOGGING_FAILED_QUERIES), + logOnlyFailedQueries: OrmUtils.toBoolean(process.env.TYPEORM_LOGGING_ONLY_FAILED_QUERIES), } }); } + /** - * Creates a new connection based on the given connection options and registers a new connection in the manager. + * Creates a new connection based on the connection options from "ormconfig.json" + * and registers a new connection in the manager. + * Optionally you can specify a path to the json configuration. + * If path is not given, then ormconfig.json file will be searched near node_modules directory. */ - async createAndConnect(options: ConnectionOptions): Promise { - const connection = this.create(options); - - // connect to the database - await connection.connect(); - - // if option is set - drop schema once connection is done - if (options.dropSchemaOnConnection && !process.env.SKIP_SCHEMA_CREATION) - await connection.dropDatabase(); + private async createFromConfigAndConnectToAll(path?: string): Promise { + const optionsArray: ConnectionOptions[] = require(path || (require("app-root-path").path + "/ormconfig.json")); + if (!optionsArray) + throw new Error(`Configuration ${path || "ormconfig.json"} was not found. Add connection configuration inside ormconfig.json file.`); - // if option is set - automatically synchronize a schema - if (options.autoSchemaCreate && !process.env.SKIP_SCHEMA_CREATION) - await connection.syncSchema(); + const promises = optionsArray + .filter(options => !options.environment || options.environment === process.env.NODE_ENV) // skip connection creation if environment is set in the options, and its not equal to the value in the NODE_ENV variable + .map(options => this.createAndConnectByConnectionOptions(options)); - return connection; + return Promise.all(promises); } /** - * Creates a new connection based on the given connection options and registers this connection in the manager. - * Note that dropSchemaOnConnection and autoSchemaCreate options of a ConnectionOptions are not working there - use - * createAndConnect method to use them. + * Creates a new connection based on the connection options from "ormconfig.json" + * and registers a new connection in the manager. + * Optionally you can specify a path to the json configuration. + * If path is not given, then ormconfig.json file will be searched near node_modules directory. */ - create(options: ConnectionOptions): Connection { - - const logger = new Logger(options.logging || {}); - const driver = this.createDriver(options.driver, logger); - const connection = this.createConnection(options.name || "default", driver, logger); - - if (options.entitySchemas) { - const [directories, classes] = this.splitStringsAndFunctions(options.entitySchemas); - connection - .importEntitySchemas(classes) - .importEntitySchemaFromDirectories(directories); - } - - if (options.entities) { - const [directories, classes] = this.splitStringsAndFunctions(options.entities); - connection - .importEntities(classes) - .importEntitiesFromDirectories(directories); - } - - if (options.subscribers) { - const [directories, classes] = this.splitStringsAndFunctions(options.subscribers); - connection - .importSubscribers(classes) - .importSubscribersFromDirectories(directories); - } + private async createFromConfigAndConnect(connectionName: string, path?: string): Promise { + const optionsArray: ConnectionOptions[] = require(path || (require("app-root-path").path + "/ormconfig.json")); + if (!optionsArray) + throw new Error(`Configuration ${path || "ormconfig.json"} was not found. Add connection configuration inside ormconfig.json file.`); - if (options.namingStrategies) { - const [directories, classes] = this.splitStringsAndFunctions(options.namingStrategies); - connection - .importNamingStrategies(classes) - .importNamingStrategiesFromDirectories(directories); - } + const environmentLessOptions = optionsArray.filter(options => (options.name || "default") === connectionName); + const options = environmentLessOptions.filter(options => !options.environment || options.environment === process.env.NODE_ENV); // skip connection creation if environment is set in the options, and its not equal to the value in the NODE_ENV variable - if (options.usedNamingStrategy && typeof options.usedNamingStrategy === "string") - connection.useNamingStrategy(options.usedNamingStrategy); - - if (options.usedNamingStrategy && options.usedNamingStrategy instanceof Function) - connection.useNamingStrategy(options.usedNamingStrategy); + if (!options.length) + throw new Error(`Connection "${connectionName}" ${process.env.NODE_ENV ? "for the environment " + process.env.NODE_ENV + " " : ""}was not found in the json configuration file.` + + (environmentLessOptions.length ? ` However there are such configurations for other environments: ${environmentLessOptions.map(options => options.environment).join(", ")}.` : "")); - return connection; + return this.createAndConnectByConnectionOptions(options[0]); } /** - * Gets registered connection with the given name. - * If connection name is not given then it will get a default connection. + * Creates a new connection based on the given connection options and registers a new connection in the manager. */ - get(name: string = "default"): Connection { - const connection = this.connections.find(connection => connection.name === name); - if (!connection) - throw new ConnectionNotFoundError(name); + private async createAndConnectByConnectionOptions(options: ConnectionOptions): Promise { + const connection = this.create(options); + + // connect to the database + await connection.connect(); + + // if option is set - drop schema once connection is done + if (options.dropSchemaOnConnection && !process.env.SKIP_SCHEMA_CREATION) + await connection.dropDatabase(); + + // if option is set - automatically synchronize a schema + if (options.autoSchemaCreate && !process.env.SKIP_SCHEMA_CREATION) + await connection.syncSchema(); return connection; } - // ------------------------------------------------------------------------- - // Private Methods - // ------------------------------------------------------------------------- - /** * Splits given array of mixed strings and / or functions into two separate array of string and array of functions. */ - private splitStringsAndFunctions(strAndClses: string[]|T[]): [string[], T[]] { + private splitStringsAndClasses(strAndClses: string[]|T[]): [string[], T[]] { return [ (strAndClses as string[]).filter(str => typeof str === "string"), (strAndClses as T[]).filter(cls => typeof cls !== "string"), diff --git a/src/connection/ConnectionOptions.ts b/src/connection/ConnectionOptions.ts index d7daa6b875..8c0e0a2721 100644 --- a/src/connection/ConnectionOptions.ts +++ b/src/connection/ConnectionOptions.ts @@ -23,21 +23,6 @@ export interface ConnectionOptions { */ readonly usedNamingStrategy?: string|Function; - /** - * Drops the schema each time connection is being established. - * Be careful with this option and don't use this in production - otherwise you'll loose all production data. - * This option is useful during debug and development. - */ - readonly dropSchemaOnConnection?: boolean; - - /** - * Indicates if database schema should be auto created on every application launch. - * Be careful with this option and don't use this in production - otherwise you can loose production data. - * This option is useful during debug and development. - * Alternative to it, you can use CLI and run schema:sync command. - */ - readonly autoSchemaCreate?: boolean; - /** * Entities to be loaded for the this connection. */ @@ -63,4 +48,28 @@ export interface ConnectionOptions { */ readonly logging?: LoggerOptions; + /** + * Drops the schema each time connection is being established. + * Be careful with this option and don't use this in production - otherwise you'll loose all production data. + * This option is useful during debug and development. + */ + readonly dropSchemaOnConnection?: boolean; + + /** + * Indicates if database schema should be auto created on every application launch. + * Be careful with this option and don't use this in production - otherwise you can loose production data. + * This option is useful during debug and development. + * Alternative to it, you can use CLI and run schema:sync command. + */ + readonly autoSchemaCreate?: boolean; + + /** + * Environment in which connection will run. + * Current environment is determined from the environment NODE_ENV variable's value. + * For example, if NODE_ENV is "test" and this property is set to "test", + * then this connection will be created. On any other NODE_ENV value it will be skipped. + * This option is specific to the configuration in the ormconfig.json file. + */ + readonly environment?: string; + } \ No newline at end of file diff --git a/src/connection/OrmConfigConnectionOptions.ts b/src/connection/OrmConfigConnectionOptions.ts deleted file mode 100644 index 79ce350c3b..0000000000 --- a/src/connection/OrmConfigConnectionOptions.ts +++ /dev/null @@ -1,17 +0,0 @@ -import {ConnectionOptions} from "./ConnectionOptions"; - -/** - * Adds few extra connection options to the original ConnectionOptions. - * These options are specific to the configuration in the ormconfig.json file. - */ -export interface OrmConfigConnectionOptions extends ConnectionOptions { - - /** - * Environment in which connection will run. - * Current environment is determined from the environment NODE_ENV variable's value. - * For example, if NODE_ENV is "test" and this property is set to "test", - * then this connection will be created. On any other NODE_ENV value it will be skipped. - */ - readonly environment?: string; - -} \ No newline at end of file diff --git a/src/connection/error/AlreadyHasActiveConnectionError.ts b/src/connection/error/AlreadyHasActiveConnectionError.ts index 68d41e7528..61525ee020 100644 --- a/src/connection/error/AlreadyHasActiveConnectionError.ts +++ b/src/connection/error/AlreadyHasActiveConnectionError.ts @@ -1,4 +1,6 @@ /** + * Thrown when consumer tries to recreate connection with the same name, but previous connection was not closed yet. + * * @internal */ export class AlreadyHasActiveConnectionError extends Error { @@ -6,7 +8,9 @@ export class AlreadyHasActiveConnectionError extends Error { constructor(connectionName: string) { super(); - this.message = `Cannot create a new connection named "${connectionName}", because connection with such name already exist and it now has an active connection session.`; + this.message = `Cannot create a new connection named "${connectionName}", because connection with such name ` + + `already exist and it now has an active connection session.`; + this.stack = new Error().stack; } } \ No newline at end of file diff --git a/src/connection/error/CannotCloseNotConnectedError.ts b/src/connection/error/CannotCloseNotConnectedError.ts index db8e08b0fb..aff4e1f093 100644 --- a/src/connection/error/CannotCloseNotConnectedError.ts +++ b/src/connection/error/CannotCloseNotConnectedError.ts @@ -1,4 +1,6 @@ /** + * Thrown when consumer tries close not opened connection. + * * @internal */ export class CannotCloseNotConnectedError extends Error { @@ -7,6 +9,7 @@ export class CannotCloseNotConnectedError extends Error { constructor(connectionName: string) { super(); this.message = `Cannot close "${connectionName}" connection because connection is not yet established.`; + this.stack = new Error().stack; } } \ No newline at end of file diff --git a/src/connection/error/CannotConnectAlreadyConnectedError.ts b/src/connection/error/CannotConnectAlreadyConnectedError.ts index 7f068b2770..ac90c46f2f 100644 --- a/src/connection/error/CannotConnectAlreadyConnectedError.ts +++ b/src/connection/error/CannotConnectAlreadyConnectedError.ts @@ -1,4 +1,6 @@ /** + * Thrown when consumer tries to connect when he already connected. + * * @internal */ export class CannotConnectAlreadyConnectedError extends Error { @@ -7,6 +9,7 @@ export class CannotConnectAlreadyConnectedError extends Error { constructor(connectionName: string) { super(); this.message = `Cannot create a "${connectionName}" connection because connection to the database already established.`; + this.stack = new Error().stack; } } \ No newline at end of file diff --git a/src/connection/error/CannotDetermineConnectionOptionsError.ts b/src/connection/error/CannotDetermineConnectionOptionsError.ts new file mode 100644 index 0000000000..ca091d89d6 --- /dev/null +++ b/src/connection/error/CannotDetermineConnectionOptionsError.ts @@ -0,0 +1,19 @@ +/** + * Thrown when connection is trying to be created automatically from connection options found in the ormconfig.json + * or environment variables, but failed due to missing these configurations. + * + * @internal + */ +export class CannotDetermineConnectionOptionsError extends Error { + name = "CannotDetermineConnectionOptionsError"; + + constructor() { + super(); + this.message = `Cannot create connection, because connection options are missing. ` + + `You either need to explicitly pass connection options, either create a ormconfig.json with with connection options ` + + `and "default" connection name, either to set proper environment variables. Also, if you are using environment-specific ` + + `configurations in your ormconfig.json make sure your are running under correct NODE_ENV.`; + this.stack = new Error().stack; + } + +} \ No newline at end of file diff --git a/src/connection/error/CannotGetEntityManagerNotConnectedError.ts b/src/connection/error/CannotGetEntityManagerNotConnectedError.ts index 6e14feba77..629db5a2b7 100644 --- a/src/connection/error/CannotGetEntityManagerNotConnectedError.ts +++ b/src/connection/error/CannotGetEntityManagerNotConnectedError.ts @@ -1,4 +1,6 @@ /** + * Thrown when consumer tries to access entity manager before connection is established. + * * @internal */ export class CannotGetEntityManagerNotConnectedError extends Error { @@ -7,6 +9,7 @@ export class CannotGetEntityManagerNotConnectedError extends Error { constructor(connectionName: string) { super(); this.message = `Cannot get entity manager for "${connectionName}" connection because connection is not yet established.`; + this.stack = new Error().stack; } } \ No newline at end of file diff --git a/src/connection/error/CannotImportAlreadyConnectedError.ts b/src/connection/error/CannotImportAlreadyConnectedError.ts index 7d4b36d61f..af0f6879d3 100644 --- a/src/connection/error/CannotImportAlreadyConnectedError.ts +++ b/src/connection/error/CannotImportAlreadyConnectedError.ts @@ -1,4 +1,7 @@ /** + * Thrown when consumer tries to import entities / entity schemas / subscribers / naming strategies after connection + * is established. + * * @internal */ export class CannotImportAlreadyConnectedError extends Error { @@ -7,6 +10,7 @@ export class CannotImportAlreadyConnectedError extends Error { constructor(importStuff: string, connectionName: string) { super(); this.message = `Cannot import ${importStuff} for "${connectionName}" connection because connection to the database already established.`; + this.stack = new Error().stack; } } \ No newline at end of file diff --git a/src/connection/error/CannotSyncNotConnectedError.ts b/src/connection/error/CannotSyncNotConnectedError.ts index 99dbc2e5b9..840294efab 100644 --- a/src/connection/error/CannotSyncNotConnectedError.ts +++ b/src/connection/error/CannotSyncNotConnectedError.ts @@ -1,4 +1,6 @@ /** + * Thrown when consumer tries to sync a database schema after connection is established + * * @internal */ export class CannotSyncNotConnectedError extends Error { @@ -7,6 +9,7 @@ export class CannotSyncNotConnectedError extends Error { constructor(connectionName: string) { super(); this.message = `Cannot sync schema of the "${connectionName}" connection because connection is not yet established.`; + this.stack = new Error().stack; } } \ No newline at end of file diff --git a/src/connection/error/CannotUseNamingStrategyNotConnectedError.ts b/src/connection/error/CannotUseNamingStrategyNotConnectedError.ts index 4c7e53cc55..b5aa44dc3f 100644 --- a/src/connection/error/CannotUseNamingStrategyNotConnectedError.ts +++ b/src/connection/error/CannotUseNamingStrategyNotConnectedError.ts @@ -1,4 +1,6 @@ /** + * Thrown when consumer tries to change used naming strategy after connection is established. + * * @internal */ export class CannotUseNamingStrategyNotConnectedError extends Error { @@ -7,6 +9,7 @@ export class CannotUseNamingStrategyNotConnectedError extends Error { constructor(connectionName: string) { super(); this.message = `Cannot use a given naming strategy for "${connectionName}" connection because connection to the database already established.`; + this.stack = new Error().stack; } } \ No newline at end of file diff --git a/src/connection/error/ConnectionNotFoundError.ts b/src/connection/error/ConnectionNotFoundError.ts index 07be338bc7..3f2f817e2f 100644 --- a/src/connection/error/ConnectionNotFoundError.ts +++ b/src/connection/error/ConnectionNotFoundError.ts @@ -1,4 +1,6 @@ /** + * Thrown when consumer tries to get connection that does not exist. + * * @internal */ export class ConnectionNotFoundError extends Error { @@ -7,6 +9,7 @@ export class ConnectionNotFoundError extends Error { constructor(name: string) { super(); this.message = `Connection "${name}" was not found.`; + this.stack = new Error().stack; } } \ No newline at end of file diff --git a/src/connection/error/MissingDriverError.ts b/src/connection/error/MissingDriverError.ts index 52ee908ac5..d5bac1b5b5 100644 --- a/src/connection/error/MissingDriverError.ts +++ b/src/connection/error/MissingDriverError.ts @@ -1,5 +1,5 @@ /** - * Thrown when user specified driver type that does not exist. + * Thrown when consumer specifies driver type that does not exist or supported. * * @internal */ @@ -9,6 +9,7 @@ export class MissingDriverError extends Error { constructor(driverType: string) { super(); this.message = `Wrong driver ${driverType} given. Supported drivers are: "mysql", "postgres", "mssql", "oracle", "mariadb", "sqlite".`; + this.stack = new Error().stack; } } \ No newline at end of file diff --git a/src/connection/error/NamingStrategyNotFoundError.ts b/src/connection/error/NamingStrategyNotFoundError.ts index fb4cb5229b..dc2f472d72 100644 --- a/src/connection/error/NamingStrategyNotFoundError.ts +++ b/src/connection/error/NamingStrategyNotFoundError.ts @@ -1,4 +1,6 @@ /** + * Thrown when consumer tries to use naming strategy that does not exist. + * * @internal */ export class NamingStrategyNotFoundError extends Error { @@ -9,6 +11,7 @@ export class NamingStrategyNotFoundError extends Error { const name = strategyName instanceof Function ? (strategyName as any).name : strategyName; this.message = `Naming strategy "${name}" was not found. Looks like this naming strategy does not ` + `exist or it was not registered in current "${connectionName}" connection?`; + this.stack = new Error().stack; } } \ No newline at end of file diff --git a/src/connection/error/NoConnectionForRepositoryError.ts b/src/connection/error/NoConnectionForRepositoryError.ts index 1dc677595b..ad1801d9d8 100644 --- a/src/connection/error/NoConnectionForRepositoryError.ts +++ b/src/connection/error/NoConnectionForRepositoryError.ts @@ -1,4 +1,6 @@ /** + * Thrown when consumer tries to access repository before connection is established. + * * @internal */ export class NoConnectionForRepositoryError extends Error { @@ -8,6 +10,7 @@ export class NoConnectionForRepositoryError extends Error { super(); this.message = `Cannot get a Repository for "${connectionName} connection, because connection with the database ` + `is not established yet. Call connection#connect method to establish connection.`; + this.stack = new Error().stack; } } \ No newline at end of file diff --git a/src/connection/error/ReactiveRepositoryNotFoundError.ts b/src/connection/error/ReactiveRepositoryNotFoundError.ts index 60c8d158de..5dbcf8e204 100644 --- a/src/connection/error/ReactiveRepositoryNotFoundError.ts +++ b/src/connection/error/ReactiveRepositoryNotFoundError.ts @@ -1,4 +1,6 @@ /** + * Thrown when repository for the given class is not found. + * * @internal */ export class ReactiveRepositoryNotFoundError extends Error { @@ -9,6 +11,7 @@ export class ReactiveRepositoryNotFoundError extends Error { const targetName = typeof entityClass === "function" && ( entityClass).name ? ( entityClass).name : entityClass; this.message = `No reactive repository for "${targetName}" was found. Looks like this entity is not registered in ` + `current "${connectionName}" connection?`; + this.stack = new Error().stack; } } \ No newline at end of file diff --git a/src/connection/error/RepositoryNotFoundError.ts b/src/connection/error/RepositoryNotFoundError.ts index 792aa2d81d..53a8a9a179 100644 --- a/src/connection/error/RepositoryNotFoundError.ts +++ b/src/connection/error/RepositoryNotFoundError.ts @@ -1,4 +1,6 @@ /** + * Thrown when repository for the given class is not found. + * * @internal */ export class RepositoryNotFoundError extends Error { @@ -9,6 +11,7 @@ export class RepositoryNotFoundError extends Error { const targetName = typeof entityClass === "function" && ( entityClass).name ? ( entityClass).name : entityClass; this.message = `No repository for "${targetName}" was found. Looks like this entity is not registered in ` + `current "${connectionName}" connection?`; + this.stack = new Error().stack; } } \ No newline at end of file diff --git a/src/connection/error/RepositoryNotTreeError.ts b/src/connection/error/RepositoryNotTreeError.ts index d4ed29d78d..57fb66ece9 100644 --- a/src/connection/error/RepositoryNotTreeError.ts +++ b/src/connection/error/RepositoryNotTreeError.ts @@ -1,4 +1,6 @@ /** + * Thrown when repository for the given class is not found. + * * @internal */ export class RepositoryNotTreeError extends Error { @@ -8,6 +10,7 @@ export class RepositoryNotTreeError extends Error { super(); const targetName = typeof entityClass === "function" && ( entityClass).name ? ( entityClass).name : entityClass; this.message = `Repository of the "${targetName}" class is not a TreeRepository. Try to use @ClosureTable decorator instead of @Table.`; + this.stack = new Error().stack; } } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 3ade41b63c..74fb1966a5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -90,29 +90,106 @@ export function getConnectionManager(): ConnectionManager { } /** - * Allows to quickly create a connection based on the given options. Uses ConnectionManager. + * Creates a new connection and registers it in the manager. + * + * If connection options were not specified, then it will try to create connection automatically. + * + * First, it will try to find a "default" configuration from ormconfig.json. + * You can also specify a connection name to use from ormconfig.json, + * and you even can specify a path to your custom ormconfig.json. + * + * In the case if options were not specified, and ormconfig.json file also wasn't found, + * it will try to create connection from environment variables. + * There are several environment variables you can set: + * + * - TYPEORM_DRIVER_TYPE - driver type. Can be "mysql", "postgres", "mariadb", "sqlite", "oracle" or "mssql". + * - TYPEORM_URL - database connection url. Should be a string. + * - TYPEORM_HOST - database host. Should be a string. + * - TYPEORM_PORT - database access port. Should be a number. + * - TYPEORM_USERNAME - database username. Should be a string. + * - TYPEORM_PASSWORD - database user's password. Should be a string. + * - TYPEORM_SID - database's SID. Used only for oracle databases. Should be a string. + * - TYPEORM_STORAGE - database's storage url. Used only for sqlite databases. Should be a string. + * - TYPEORM_USE_POOL - indicates if connection pooling should be enabled. By default its enabled. Should be boolean-like value. + * - TYPEORM_DRIVER_EXTRA - extra options to be passed to the driver. Should be a serialized json string of options. + * - TYPEORM_AUTO_SCHEMA_CREATE - indicates if automatic schema synchronization will be performed on each application run. Should be boolean-like value. + * - TYPEORM_ENTITIES - list of directories containing entities to load. Should be string - directory names (can be patterns) split by a comma. + * - TYPEORM_SUBSCRIBERS - list of directories containing subscribers to load. Should be string - directory names (can be patterns) split by a comma. + * - TYPEORM_ENTITY_SCHEMAS - list of directories containing entity schemas to load. Should be string - directory names (can be patterns) split by a comma. + * - TYPEORM_NAMING_STRATEGIES - list of directories containing custom naming strategies to load. Should be string - directory names (can be patterns) split by a comma. + * - TYPEORM_LOGGING_QUERIES - indicates if each executed query must be logged. Should be boolean-like value. + * - TYPEORM_LOGGING_FAILED_QUERIES - indicates if logger should log failed query's error. Should be boolean-like value. + * - TYPEORM_LOGGING_ONLY_FAILED_QUERIES - indicates if only failed queries must be logged. Should be boolean-like value. + * + * TYPEORM_DRIVER_TYPE variable is required. Depend on the driver type some other variables may be required too. */ -export function createConnection(options: ConnectionOptions): Promise { - return getConnectionManager().createAndConnect(options); -} +export function createConnection(): Promise; /** - * Allows to quickly create a connection based on the connection options in the ormconfig.json. + * Creates connection from the given connection options and registers it in the manager. */ -export function createConnectionFromConfig(connectionName: string = "default", path?: string): Promise { - return getConnectionManager().createFromConfigAndConnect(connectionName, path); -} +export function createConnection(options?: ConnectionOptions): Promise; /** - * Allows to quickly create a connections based on the connection options in the ormconfig.json. + * Creates connection with the given connection name from the ormconfig.json file and registers it in the manager. + * Optionally you can specify a path to custom ormconfig.json file. */ -export function createConnectionsFromConfig(path?: string): Promise { - return getConnectionManager().createFromConfigAndConnectToAll(path); +export function createConnection(connectionNameFromConfig: string, ormConfigPath?: string): Promise; + +/** + * Creates connection and and registers it in the manager. + */ +export function createConnection(optionsOrConnectionNameFromConfig?: ConnectionOptions|string, ormConfigPath?: string): Promise { + return getConnectionManager().createAndConnect(optionsOrConnectionNameFromConfig as any, ormConfigPath); } /** - * Allows to quickly create a connection based on the environment variable values. + * Creates new connections and registers them in the manager. + * + * If array of connection options were not specified, then it will try to create them automatically + * from ormconfig.json. You can also specify path to your custom ormconfig.json. + * + * In the case if options were not specified, and ormconfig.json file also wasn't found, + * it will try to create connection from environment variables. + * There are several environment variables you can set: + * + * - TYPEORM_DRIVER_TYPE - driver type. Can be "mysql", "postgres", "mariadb", "sqlite", "oracle" or "mssql". + * - TYPEORM_URL - database connection url. Should be a string. + * - TYPEORM_HOST - database host. Should be a string. + * - TYPEORM_PORT - database access port. Should be a number. + * - TYPEORM_USERNAME - database username. Should be a string. + * - TYPEORM_PASSWORD - database user's password. Should be a string. + * - TYPEORM_SID - database's SID. Used only for oracle databases. Should be a string. + * - TYPEORM_STORAGE - database's storage url. Used only for sqlite databases. Should be a string. + * - TYPEORM_USE_POOL - indicates if connection pooling should be enabled. By default its enabled. Should be boolean-like value. + * - TYPEORM_DRIVER_EXTRA - extra options to be passed to the driver. Should be a serialized json string of options. + * - TYPEORM_AUTO_SCHEMA_CREATE - indicates if automatic schema synchronization will be performed on each application run. Should be boolean-like value. + * - TYPEORM_ENTITIES - list of directories containing entities to load. Should be string - directory names (can be patterns) split by a comma. + * - TYPEORM_SUBSCRIBERS - list of directories containing subscribers to load. Should be string - directory names (can be patterns) split by a comma. + * - TYPEORM_ENTITY_SCHEMAS - list of directories containing entity schemas to load. Should be string - directory names (can be patterns) split by a comma. + * - TYPEORM_NAMING_STRATEGIES - list of directories containing custom naming strategies to load. Should be string - directory names (can be patterns) split by a comma. + * - TYPEORM_LOGGING_QUERIES - indicates if each executed query must be logged. Should be boolean-like value. + * - TYPEORM_LOGGING_FAILED_QUERIES - indicates if logger should log failed query's error. Should be boolean-like value. + * - TYPEORM_LOGGING_ONLY_FAILED_QUERIES - indicates if only failed queries must be logged. Should be boolean-like value. + * + * TYPEORM_DRIVER_TYPE variable is required. Depend on the driver type some other variables may be required too. + */ +export function createConnections(): Promise; + +/** + * Creates connections from the given connection options and registers them in the manager. + */ +export function createConnections(options?: ConnectionOptions[]): Promise; + +/** + * Creates connection with the given connection name from the ormconfig.json file and registers it in the manager. + * Optionally you can specify a path to custom ormconfig.json file. + */ +export function createConnections(ormConfigPath?: string): Promise; + +/** + * Creates connections and and registers them in the manager. */ -export function createConnectionFromEnv(): Promise { - return getConnectionManager().createFromEnvAndConnect(); +export function createConnections(optionsOrOrmConfigFilePath?: ConnectionOptions[]|string): Promise { + return getConnectionManager().createAndConnectToAll(optionsOrOrmConfigFilePath as any); } \ No newline at end of file diff --git a/src/logger/LoggerOptions.ts b/src/logger/LoggerOptions.ts index d1a07cba8b..e56cd0a89e 100644 --- a/src/logger/LoggerOptions.ts +++ b/src/logger/LoggerOptions.ts @@ -1,3 +1,6 @@ +/** + * Logging options. + */ export interface LoggerOptions { /** diff --git a/src/query-builder/alias/Alias.ts b/src/query-builder/alias/Alias.ts index 482ab50b1b..13a2defa35 100644 --- a/src/query-builder/alias/Alias.ts +++ b/src/query-builder/alias/Alias.ts @@ -1,5 +1,3 @@ -import {ColumnMetadata} from "../../metadata/ColumnMetadata"; - /** */ export class Alias { diff --git a/src/repository/FindOptions.ts b/src/repository/FindOptions.ts index bae6d6c5ce..41c334c8ed 100644 --- a/src/repository/FindOptions.ts +++ b/src/repository/FindOptions.ts @@ -1,5 +1,4 @@ import {QueryBuilder} from "../query-builder/QueryBuilder"; -import {DriverOptions} from "../driver/DriverOptions"; /** * Options to be passed to find methods. diff --git a/src/repository/ReactiveRepository.ts b/src/repository/ReactiveRepository.ts index 0fcca7f746..62a4b6aa40 100644 --- a/src/repository/ReactiveRepository.ts +++ b/src/repository/ReactiveRepository.ts @@ -2,7 +2,6 @@ import {QueryBuilder} from "../query-builder/QueryBuilder"; import {FindOptions} from "./FindOptions"; import {Repository} from "./Repository"; import * as Rx from "rxjs/Rx"; -import {EntityMetadata} from "../metadata/EntityMetadata"; import {ObjectLiteral} from "../common/ObjectLiteral"; /** diff --git a/src/repository/ReactiveSpecificRepository.ts b/src/repository/ReactiveSpecificRepository.ts index 00a19db636..2147c296fa 100644 --- a/src/repository/ReactiveSpecificRepository.ts +++ b/src/repository/ReactiveSpecificRepository.ts @@ -1,7 +1,6 @@ import {ObjectLiteral} from "../common/ObjectLiteral"; import {SpecificRepository} from "./SpecificRepository"; import * as Rx from "rxjs/Rx"; -import {EntityMetadata} from "../metadata/EntityMetadata"; /** * Reactive version of SpecificRepository. diff --git a/src/repository/Repository.ts b/src/repository/Repository.ts index 513f58cb00..c0bbebdeef 100644 --- a/src/repository/Repository.ts +++ b/src/repository/Repository.ts @@ -19,7 +19,6 @@ export class Repository { // Private Properties // ------------------------------------------------------------------------- - protected persistOperationExecutor: PersistOperationExecutor; protected entityPersistOperationBuilder: EntityPersistOperationBuilder; protected plainObjectToEntityTransformer: PlainObjectToNewEntityTransformer; protected plainObjectToDatabaseEntityTransformer: PlainObjectToDatabaseEntityTransformer; diff --git a/src/repository/RepositoryFactory.ts b/src/repository/RepositoryFactory.ts index 8ebd65b2e9..c4bce9a4af 100644 --- a/src/repository/RepositoryFactory.ts +++ b/src/repository/RepositoryFactory.ts @@ -1,11 +1,9 @@ import {TreeRepository} from "./TreeRepository"; import {EntityMetadata} from "../metadata/EntityMetadata"; -import {EntityMetadataCollection} from "../metadata-args/collection/EntityMetadataCollection"; import {Connection} from "../connection/Connection"; import {Repository} from "./Repository"; import {ReactiveRepository} from "./ReactiveRepository"; import {TreeReactiveRepository} from "./TreeReactiveRepository"; -import {Broadcaster} from "../subscriber/Broadcaster"; import {SpecificRepository} from "./SpecificRepository"; import {SpecificReactiveRepository} from "./ReactiveSpecificRepository"; diff --git a/src/util/OrmUtils.ts b/src/util/OrmUtils.ts index 8425fdae06..0d9c100e88 100644 --- a/src/util/OrmUtils.ts +++ b/src/util/OrmUtils.ts @@ -13,5 +13,21 @@ export class OrmUtils { return groupedArray; }, [] as Array<{ id: R, items: T[] }>); } + + /** + * Transforms given value into boolean value. + */ + static toBoolean(value: any): boolean { + if (typeof value === "boolean") + return value; + + if (typeof value === "string") + return value === "true" || value === "1"; + + if (typeof value === "number") + return value > 0; + + return false; + } } \ No newline at end of file diff --git a/test/functional/connection/connection.ts b/test/functional/connection/connection.ts index 72f46b9417..e88f0302fe 100644 --- a/test/functional/connection/connection.ts +++ b/test/functional/connection/connection.ts @@ -2,11 +2,7 @@ import "reflect-metadata"; import {expect} from "chai"; import {Post} from "./entity/Post"; import {Category} from "./entity/Category"; -import { - setupTestingConnections, - closeConnections, - createTestingConnectionOptions -} from "../../utils/test-utils"; +import {setupTestingConnections, closeConnections, createTestingConnectionOptions} from "../../utils/test-utils"; import {Connection} from "../../../src/connection/Connection"; import {CannotConnectAlreadyConnectedError} from "../../../src/connection/error/CannotConnectAlreadyConnectedError"; import {CannotCloseNotConnectedError} from "../../../src/connection/error/CannotCloseNotConnectedError";