fixed errors with internal modules

This commit is contained in:
Umed Khudoiberdiev 2016-04-25 15:04:42 +05:00
parent ac5bb23955
commit 5a0d054d77
20 changed files with 17 additions and 78 deletions

View File

@ -50,7 +50,7 @@ export class Connection {
/**
* All entity metadatas that are registered for this connection.
*/
readonly entityMetadatas: EntityMetadata[] = [];
private readonly entityMetadatas: EntityMetadata[] = [];
/**
* All entity listener metadatas that are registered for this connection.
@ -93,15 +93,22 @@ export class Connection {
* Performs connection to the database.
*/
connect(): Promise<void> {
const schemaCreator = new SchemaCreator(this);
return this.driver.connect().then(() => {
if (this.options.autoSchemaCreate === true)
return schemaCreator.create();
return this.createSchema();
return undefined;
});
}
/**
* Creates database schema for all entities registered in this connection.
*/
createSchema() {
const schemaCreator = new SchemaCreator(this, this.entityMetadatas);
return schemaCreator.create();
}
/**
* Closes this connection.
*/
@ -122,17 +129,6 @@ export class Connection {
return repoMeta.repository;
}
/**
* Gets the entity metadata for the given entity class.
*/
getEntityMetadata(entityClass: Function): EntityMetadata {
const metadata = this.entityMetadatas.find(metadata => metadata.target === entityClass);
if (!metadata)
throw new MetadataNotFoundError(entityClass);
return metadata;
}
/**
* Registers entity metadatas for the current connection.
*/

View File

@ -1,30 +0,0 @@
import {ConnectionManager} from "../connection/ConnectionManager";
// todo: should this decorator be outside of this module?
// todo: also create "inject" version of this to allow to inject to properties
/**
* Allows to inject a Repository using typedi's Container.
* @deprecated
* */
export function OrmRepository(cls: Function, connectionName?: string): Function {
return function(target: Function, key: string, index: number) {
let container: any;
try {
container = require("typedi/Container").Container;
} catch (err) {
throw new Error("OrmRepository cannot be used because typedi extension is not installed.");
}
container.registerParamHandler({
type: target,
index: index,
getValue: () => {
const connectionManager: ConnectionManager = container.get(ConnectionManager);
const connection = connectionManager.getConnection(connectionName);
return connection.getRepository(<any> cls);
}
});
};
}

View File

@ -2,7 +2,6 @@ import {ConnectionOptions} from "../connection/ConnectionOptions";
/**
* Provides base functionality for all driver implementations.
* @internal
*/
export abstract class BaseDriver {

View File

@ -5,8 +5,6 @@ import {ColumnType} from "../types/ColumnTypes";
/**
* Constructor arguments for ColumnMetadata class.
*
* @internal
*/
export interface ColumnMetadataArgs {
@ -53,8 +51,6 @@ export interface ColumnMetadataArgs {
/**
* This metadata contains all information about class's column.
*
* @internal
*/
export class ColumnMetadata extends PropertyMetadata {

View File

@ -1,7 +1,5 @@
/**
* This metadata interface contains all information about table's compound index.
*
* @internal
*/
export class CompoundIndexMetadata {

View File

@ -3,8 +3,6 @@ import {EventListenerType} from "../types/EventListenerTypes";
/**
* This metadata interface contains all information about some index on a field.
*
* @internal
*/
export class EntityListenerMetadata extends PropertyMetadata {

View File

@ -8,8 +8,6 @@ import {ForeignKeyMetadata} from "./ForeignKeyMetadata";
/**
* Contains all entity metadata.
*
* @internal
*/
export class EntityMetadata {

View File

@ -1,7 +1,5 @@
/**
* Contains metadata information about ORM event subscribers.
*
* @internal
*/
export class EventSubscriberMetadata {

View File

@ -5,8 +5,6 @@ export type OnDeleteType = "RESTRICT"|"CASCADE"|"SET NULL";
/**
* This metadata interface contains all information foreign keys.
*
* @internal
*/
export class ForeignKeyMetadata {

View File

@ -2,8 +2,6 @@ import {PropertyMetadata} from "./PropertyMetadata";
/**
* This metadata interface contains all information about some index on a field.
*
* @internal
*/
export class IndexMetadata extends PropertyMetadata {

View File

@ -2,8 +2,6 @@ import {TableMetadata} from "./TableMetadata";
/**
* This metadata interface contains all information about junction table.
*
* @internal
*/
export class JunctionTableMetadata extends TableMetadata {

View File

@ -1,7 +1,5 @@
/**
* This represents metadata of some object's property.
*
* @internal
*/
export abstract class PropertyMetadata {

View File

@ -17,8 +17,6 @@ export type PropertyTypeInFunction<T> = string|((t: T) => string|any);
/**
* Relation metadata constructor arguments.
*
* @internal
*/
export interface RelationMetadataArgs {
@ -61,8 +59,6 @@ export interface RelationMetadataArgs {
/**
* This metadata interface contains all information about some document's relation.
*
* @internal
*/
export class RelationMetadata extends PropertyMetadata {

View File

@ -2,8 +2,6 @@ import {NamingStrategy} from "../../naming-strategy/NamingStrategy";
/**
* This metadata interface contains all information about specific table.
*
* @internal
*/
export class TableMetadata {

View File

@ -46,7 +46,7 @@ export class QueryBuilder<Entity> {
constructor(private connection: Connection,
private entityMetadatas: EntityMetadata[]) {
this.aliasMap = new AliasMap(connection.entityMetadatas);
this.aliasMap = new AliasMap(entityMetadatas);
this.broadcaster = new Broadcaster(connection, this.entityMetadatas);
}

View File

@ -23,7 +23,7 @@ export class SchemaCreator {
// Constructor
// -------------------------------------------------------------------------
constructor(connection: Connection) {
constructor(connection: Connection, private entityMetadatas: EntityMetadata[]) {
this.connection = connection;
this.schemaBuilder = connection.driver.createSchemaBuilder();
}
@ -36,7 +36,7 @@ export class SchemaCreator {
* Creates complete schemas for the given entity metadatas.
*/
create(): Promise<void> {
const metadatas = this.connection.entityMetadatas;
const metadatas = this.entityMetadatas;
return Promise.resolve()
.then(_ => this.dropForeignKeysForAll(metadatas))
.then(_ => this.createTablesForAll(metadatas))

View File

@ -42,7 +42,7 @@ describe("insertion", function() {
function reloadDatabase() {
return connection.driver
.clearDatabase()
.then(() => new SchemaCreator(connection).create())
.then(() => connection.createSchema())
.catch(e => console.log("Error during schema re-creation: ", e));
}

View File

@ -51,7 +51,7 @@ describe("one-to-one", function() {
function reloadDatabase() {
return connection.driver
.clearDatabase()
.then(() => new SchemaCreator(connection).create());
.then(() => connection.createSchema());
}
let postRepository: Repository<Post>,

View File

@ -48,7 +48,7 @@ describe("many-to-one", function() {
function reloadDatabase() {
return connection.driver
.clearDatabase()
.then(() => new SchemaCreator(connection).create());
.then(() => connection.createSchema());
}
let postRepository: Repository<Post>,

View File

@ -51,7 +51,7 @@ describe("many-to-many", function() {
function reloadDatabase() {
return connection.driver
.clearDatabase()
.then(() => new SchemaCreator(connection).create());
.then(() => connection.createSchema());
}
let postRepository: Repository<Post>,