refactored connection stuff; optimized all imports

This commit is contained in:
Umed Khudoiberdiev 2016-09-18 22:55:59 +05:00
parent 8f5ac0c9fb
commit 2a59f621ee
104 changed files with 590 additions and 356 deletions

View File

@ -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";

View File

@ -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")

View File

@ -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")

View File

@ -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";

View File

@ -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")

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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 {

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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 {

View File

@ -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";

View File

@ -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";

View File

@ -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 {

View File

@ -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")

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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 {

View File

@ -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 {

View File

@ -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";

View File

@ -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 {

View File

@ -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";

View File

@ -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 {

View File

@ -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 {

View File

@ -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")

View File

@ -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 {

View File

@ -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")

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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 {

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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 {

View File

@ -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 {

View File

@ -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")

View File

@ -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 {

View File

@ -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")

View File

@ -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 {

View File

@ -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";

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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")

View File

@ -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 {

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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);

View File

@ -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()));
}

View File

@ -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()));
}

View File

@ -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<Connection[]> {
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 Promise.all(promises);
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 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.
*/
async createFromConfigAndConnect(connectionName: string = "default", path?: string): Promise<Connection> {
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.`);
create(options: ConnectionOptions): Connection {
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
const logger = new Logger(options.logging || {});
const driver = this.createDriver(options.driver, logger);
const connection = this.createConnection(options.name || "default", driver, logger);
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(", ")}.` : ""));
// import entity schemas
if (options.entitySchemas) {
const [directories, classes] = this.splitStringsAndClasses(options.entitySchemas);
connection
.importEntitySchemas(classes)
.importEntitySchemaFromDirectories(directories);
}
return this.createAndConnect(options[0]);
// 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 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 createAndConnect(): Promise<Connection>;
/**
* Creates connection from the given connection options and registers it in the manager.
*/
async createAndConnect(options?: ConnectionOptions): Promise<Connection>;
/**
* 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<Connection>;
/**
* Creates connection and and registers it in the manager.
*/
async createAndConnect(optionsOrConnectionNameFromConfig?: ConnectionOptions|string, ormConfigPath?: string): Promise<Connection> {
// 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<Connection[]>;
/**
* Creates connections from the given connection options and registers them in the manager.
*/
async createAndConnectToAll(options?: ConnectionOptions[]): Promise<Connection[]>;
/**
* Creates connections from the ormconfig.json file.
* Optionally you can specify a path to custom ormconfig.json file.
*/
async createAndConnectToAll(ormConfigPath?: string): Promise<Connection[]>;
/**
* Creates connection and and registers them in the manager.
*/
async createAndConnectToAll(optionsOrOrmConfigFilePath?: ConnectionOptions[]|string): Promise<Connection[]> {
// 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<Connection> {
return this.createAndConnect({
private async createFromEnvAndConnect(): Promise<Connection> {
return this.createAndConnectByConnectionOptions({
driver: {
type: process.env.TYPEORM_DRIVER_TYPE,
url: process.env.TYPEORM_URL,
@ -86,26 +317,67 @@ 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 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.
*/
private async createFromConfigAndConnectToAll(path?: string): Promise<Connection[]> {
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.`);
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 Promise.all(promises);
}
/**
* 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.
*/
private async createFromConfigAndConnect(connectionName: string, path?: string): Promise<Connection> {
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.`);
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.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 this.createAndConnectByConnectionOptions(options[0]);
}
/**
* Creates a new connection based on the given connection options and registers a new connection in the manager.
*/
async createAndConnect(options: ConnectionOptions): Promise<Connection> {
private async createAndConnectByConnectionOptions(options: ConnectionOptions): Promise<Connection> {
const connection = this.create(options);
// connect to the database
@ -122,74 +394,10 @@ export class ConnectionManager {
return connection;
}
/**
* 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.
*/
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);
}
if (options.namingStrategies) {
const [directories, classes] = this.splitStringsAndFunctions(options.namingStrategies);
connection
.importNamingStrategies(classes)
.importNamingStrategiesFromDirectories(directories);
}
if (options.usedNamingStrategy && typeof options.usedNamingStrategy === "string")
connection.useNamingStrategy(options.usedNamingStrategy);
if (options.usedNamingStrategy && options.usedNamingStrategy instanceof Function)
connection.useNamingStrategy(options.usedNamingStrategy);
return connection;
}
/**
* Gets registered connection with the given name.
* If connection name is not given then it will get a default connection.
*/
get(name: string = "default"): Connection {
const connection = this.connections.find(connection => connection.name === name);
if (!connection)
throw new ConnectionNotFoundError(name);
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<T>(strAndClses: string[]|T[]): [string[], T[]] {
private splitStringsAndClasses<T>(strAndClses: string[]|T[]): [string[], T[]] {
return [
(strAndClses as string[]).filter(str => typeof str === "string"),
(strAndClses as T[]).filter(cls => typeof cls !== "string"),

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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" && (<any> entityClass).name ? (<any> 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;
}
}

View File

@ -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" && (<any> entityClass).name ? (<any> 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;
}
}

View File

@ -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" && (<any> entityClass).name ? (<any> 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;
}
}

View File

@ -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<Connection> {
return getConnectionManager().createAndConnect(options);
export function createConnection(): Promise<Connection>;
/**
* Creates connection from the given connection options and registers it in the manager.
*/
export function createConnection(options?: ConnectionOptions): Promise<Connection>;
/**
* 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 createConnection(connectionNameFromConfig: string, ormConfigPath?: string): Promise<Connection>;
/**
* Creates connection and and registers it in the manager.
*/
export function createConnection(optionsOrConnectionNameFromConfig?: ConnectionOptions|string, ormConfigPath?: string): Promise<Connection> {
return getConnectionManager().createAndConnect(optionsOrConnectionNameFromConfig as any, ormConfigPath);
}
/**
* Allows to quickly create a connection based on the connection options in the ormconfig.json.
* 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 createConnectionFromConfig(connectionName: string = "default", path?: string): Promise<Connection> {
return getConnectionManager().createFromConfigAndConnect(connectionName, path);
}
export function createConnections(): Promise<Connection[]>;
/**
* Allows to quickly create a connections based on the connection options in the ormconfig.json.
* Creates connections from the given connection options and registers them in the manager.
*/
export function createConnectionsFromConfig(path?: string): Promise<Connection[]> {
return getConnectionManager().createFromConfigAndConnectToAll(path);
}
export function createConnections(options?: ConnectionOptions[]): Promise<Connection[]>;
/**
* Allows to quickly create a connection based on the environment variable values.
* 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 createConnectionFromEnv(): Promise<Connection> {
return getConnectionManager().createFromEnvAndConnect();
export function createConnections(ormConfigPath?: string): Promise<Connection[]>;
/**
* Creates connections and and registers them in the manager.
*/
export function createConnections(optionsOrOrmConfigFilePath?: ConnectionOptions[]|string): Promise<Connection[]> {
return getConnectionManager().createAndConnectToAll(optionsOrOrmConfigFilePath as any);
}

View File

@ -1,3 +1,6 @@
/**
* Logging options.
*/
export interface LoggerOptions {
/**

View File

@ -1,5 +1,3 @@
import {ColumnMetadata} from "../../metadata/ColumnMetadata";
/**
*/
export class Alias {

View File

@ -1,5 +1,4 @@
import {QueryBuilder} from "../query-builder/QueryBuilder";
import {DriverOptions} from "../driver/DriverOptions";
/**
* Options to be passed to find methods.

View File

@ -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";
/**

View File

@ -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.

Some files were not shown because too many files have changed in this diff Show More