mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
fixed all tests and compiler/tslint errors
This commit is contained in:
parent
e8f53d759f
commit
8dd12834fb
@ -47,7 +47,8 @@ export class MyNamingStrategy implements NamingStrategy {
|
||||
We also need to specify our new naming strategy on connection manager creation:
|
||||
|
||||
```typescript
|
||||
let connectionManager = new ConnectionManager(new MyNamingStrategy());
|
||||
let connectionManager = new ConnectionManager();
|
||||
connectionManager.namingStrategy = new MyNamingStrategy();
|
||||
```
|
||||
|
||||
Now try to run and generate your database schema. New naming strategy should be used.
|
||||
16
package.json
16
package.json
@ -25,27 +25,27 @@
|
||||
],
|
||||
"devDependencies": {
|
||||
"chai": "^3.4.1",
|
||||
"chai-as-promised": "^5.2.0",
|
||||
"chai-as-promised": "^5.3.0",
|
||||
"del": "^2.2.0",
|
||||
"gulp": "^3.9.0",
|
||||
"gulp": "^3.9.1",
|
||||
"gulp-mocha": "^2.2.0",
|
||||
"gulp-replace": "^0.5.4",
|
||||
"gulp-shell": "^0.5.1",
|
||||
"gulp-tslint": "^4.3.1",
|
||||
"gulp-tslint": "^4.3.5",
|
||||
"gulpclass": "0.1.0",
|
||||
"mocha": "^2.3.2",
|
||||
"sinon": "^1.17.2",
|
||||
"sinon-chai": "^2.8.0",
|
||||
"tslint": "^3.3.0",
|
||||
"tslint": "^3.7.4",
|
||||
"tslint-stylish": "^2.1.0-beta",
|
||||
"typescript": "^1.8.0",
|
||||
"typings": "^0.6.6"
|
||||
"typescript": "^1.8.10",
|
||||
"typings": "^0.7.12"
|
||||
},
|
||||
"dependencies": {
|
||||
"fs": "^0.0.2",
|
||||
"lodash": "^4.5.0",
|
||||
"lodash": "^4.11.1",
|
||||
"mysql": "^2.10.2",
|
||||
"path": "^0.11.14",
|
||||
"path": "^0.12.7",
|
||||
"reflect-metadata": "^0.1.3",
|
||||
"require-all": "^2.0.0",
|
||||
"sha1": "^1.1.1",
|
||||
|
||||
@ -7,45 +7,47 @@ import {EntityMetadataBuilder} from "../metadata-builder/EntityMetadataBuilder";
|
||||
import {importClassesFromDirectories} from "../util/DirectoryExportedClassesLoader";
|
||||
import {ConnectionOptions} from "tls";
|
||||
import {NamingStrategy} from "../naming-strategy/NamingStrategy";
|
||||
import {CannotSetNamingStrategyError} from "./error/CannotSetNamingStrategyError";
|
||||
|
||||
/**
|
||||
* Connection manager holds all connections made to the databases and providers helper management functions
|
||||
* for all exist connections.
|
||||
*/
|
||||
export class ConnectionManager {
|
||||
|
||||
// todo: inject naming strategy, make it configurable
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Properties
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
private connections: Connection[] = [];
|
||||
private entityMetadataBuilder: EntityMetadataBuilder;
|
||||
private _entityMetadataBuilder: EntityMetadataBuilder;
|
||||
private _namingStrategy: NamingStrategy;
|
||||
private _container: { get(someClass: any): any };
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Constructor
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
constructor(namingStrategy?: NamingStrategy) {
|
||||
if (!namingStrategy)
|
||||
namingStrategy = new DefaultNamingStrategy();
|
||||
|
||||
this.entityMetadataBuilder = new EntityMetadataBuilder(defaultMetadataStorage, namingStrategy);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Accessors
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Sets a container that can be used in custom user subscribers. This allows to inject services in user classes.
|
||||
* Sets a container that can be used in custom user subscribers. This allows to inject services in subscribers.
|
||||
*/
|
||||
set container(container: { get(someClass: Function): any }) {
|
||||
this._container = container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the naming strategy to be used instead of DefaultNamingStrategy.
|
||||
*/
|
||||
set namingStrategy(namingStrategy: NamingStrategy) {
|
||||
|
||||
// if entity metadata builder already initialized then strategy already is used there, and setting a new naming
|
||||
// strategy is pointless
|
||||
if (this._entityMetadataBuilder)
|
||||
throw new CannotSetNamingStrategyError();
|
||||
|
||||
this._namingStrategy = namingStrategy;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Public Methods
|
||||
// -------------------------------------------------------------------------
|
||||
@ -163,6 +165,21 @@ export class ConnectionManager {
|
||||
// Private Methods
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* We need to lazily initialize EntityMetadataBuilder because naming strategy can be set before we use entityMetadataBuilder.
|
||||
*/
|
||||
private get entityMetadataBuilder() {
|
||||
if (!this._entityMetadataBuilder) {
|
||||
const namingStrategy = this._namingStrategy ? this._namingStrategy : new DefaultNamingStrategy();
|
||||
this._entityMetadataBuilder = new EntityMetadataBuilder(defaultMetadataStorage, namingStrategy);
|
||||
}
|
||||
|
||||
return this._entityMetadataBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of the given constructor.
|
||||
*/
|
||||
private createContainerInstance(constructor: Function) {
|
||||
return this._container ? this._container.get(constructor) : new (<any> constructor)();
|
||||
}
|
||||
|
||||
4
src/connection/error/CannotSetNamingStrategyError.ts
Normal file
4
src/connection/error/CannotSetNamingStrategyError.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export class CannotSetNamingStrategyError extends Error {
|
||||
name = "CannotSetNamingStrategyError";
|
||||
message = "Cannot set naming strategy. Naming strategy must be set right after ConnectionManager is created, and before any entity importing is done.";
|
||||
}
|
||||
@ -77,14 +77,14 @@ export class ForeignKeyMetadata {
|
||||
* Array of column names.
|
||||
*/
|
||||
get columnNames(): string[] {
|
||||
return this.columns.map(column => column.name)
|
||||
return this.columns.map(column => column.name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Array of referenced column names.
|
||||
*/
|
||||
get referencedColumnNames(): string[] {
|
||||
return this.referencedColumns.map(column => column.name)
|
||||
return this.referencedColumns.map(column => column.name);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -93,7 +93,7 @@ export class ForeignKeyMetadata {
|
||||
get name() {
|
||||
const key = `${this.table.name}_${this.columnNames.join("_")}` +
|
||||
`_${this.referencedTable.name}_${this.referencedColumnNames.join("_")}`;
|
||||
return "fk_" + require('sha1')(key); // todo: use crypto instead?
|
||||
return "fk_" + require("sha1")(key); // todo: use crypto instead?
|
||||
}
|
||||
|
||||
}
|
||||
@ -7,12 +7,12 @@ import {EntityMetadata} from "./EntityMetadata";
|
||||
/**
|
||||
* Function that returns a type of the field. Returned value must be a class used on the relation.
|
||||
*/
|
||||
type RelationTypeInFunction = ((type?: any) => Function);
|
||||
export type RelationTypeInFunction = ((type?: any) => Function);
|
||||
|
||||
/**
|
||||
* Contains the name of the property of the object, or the function that returns this name.
|
||||
*/
|
||||
type PropertyTypeInFunction<T> = string|((t: T) => string|any);
|
||||
export type PropertyTypeInFunction<T> = string|((t: T) => string|any);
|
||||
|
||||
/**
|
||||
* Relation metadata constructor arguments.
|
||||
|
||||
@ -60,8 +60,8 @@ export class EntityPersistOperationBuilder {
|
||||
dbEntities: EntityWithId[],
|
||||
allPersistedEntities: EntityWithId[]): PersistOperation {
|
||||
|
||||
//const dbEntities = this.extractObjectsById(dbEntity, metadata);
|
||||
//const allPersistedEntities = this.extractObjectsById(persistedEntity, metadata);
|
||||
// const dbEntities = this.extractObjectsById(dbEntity, metadata);
|
||||
// const allPersistedEntities = this.extractObjectsById(persistedEntity, metadata);
|
||||
|
||||
const persistOperation = new PersistOperation();
|
||||
persistOperation.dbEntity = dbEntity;
|
||||
|
||||
@ -4,7 +4,7 @@ import {EntityMetadata} from "../../metadata-builder/metadata/EntityMetadata";
|
||||
export class RemoveOperation {
|
||||
constructor(public entity: any,
|
||||
public entityId: any,
|
||||
public fromMetadata: EntityMetadata, //todo: use relation.metadata instead?
|
||||
public fromMetadata: EntityMetadata, // todo: use relation.metadata instead?
|
||||
public relation: RelationMetadata,
|
||||
public fromEntityId: any) {
|
||||
}
|
||||
|
||||
@ -403,7 +403,7 @@ export class QueryBuilder<Entity> {
|
||||
});
|
||||
|
||||
this.orderBys.forEach(orderBy => qb.addOrderBy(orderBy.sort, orderBy.order));
|
||||
Object.keys(this.parameters).forEach(key => qb.setParameter(key, this.parameters[key]))
|
||||
Object.keys(this.parameters).forEach(key => qb.setParameter(key, this.parameters[key]));
|
||||
|
||||
qb.setLimit(this.limit)
|
||||
.setOffset(this.offset)
|
||||
|
||||
@ -126,7 +126,7 @@ export class Repository<Entity> {
|
||||
find(conditions: Object): Promise<Entity[]>;
|
||||
|
||||
/**
|
||||
* Finds entities with options applied.
|
||||
* Finds entities with .
|
||||
*/
|
||||
find(options: FindOptions): Promise<Entity[]>;
|
||||
|
||||
@ -275,14 +275,14 @@ export class Repository<Entity> {
|
||||
return repository.findById(entityWithId.id).then(loadedEntity => {
|
||||
if (!loadedEntity) return undefined;
|
||||
|
||||
return {
|
||||
return <EntityWithId> {
|
||||
id: (<any> loadedEntity)[metadata.primaryColumn.name],
|
||||
entity: loadedEntity
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
return Promise.all(missingDbEntitiesLoad).then(missingDbEntities => {
|
||||
return Promise.all<EntityWithId>(missingDbEntitiesLoad).then(missingDbEntities => {
|
||||
return dbEntities.concat(missingDbEntities.filter(dbEntity => !!dbEntity));
|
||||
});
|
||||
}
|
||||
|
||||
@ -294,7 +294,7 @@ describe("one-to-one", function() {
|
||||
.leftJoinAndSelect("post.details", "details")
|
||||
.where("post.id=:id")
|
||||
.setParameter("id", updatedPost.id)
|
||||
.getSingleResult()
|
||||
.getSingleResult();
|
||||
}).then(updatedPostReloaded => {
|
||||
updatedPostReloaded.details.comment.should.be.equal("this is post");
|
||||
});
|
||||
@ -331,7 +331,7 @@ describe("one-to-one", function() {
|
||||
.leftJoinAndSelect("post.details", "details")
|
||||
.where("post.id=:id")
|
||||
.setParameter("id", updatedPost.id)
|
||||
.getSingleResult()
|
||||
.getSingleResult();
|
||||
}).then(updatedPostReloaded => {
|
||||
updatedPostReloaded.details.comment.should.be.equal("this is post");
|
||||
});
|
||||
|
||||
@ -296,7 +296,7 @@ describe("many-to-one", function() {
|
||||
.leftJoinAndSelect("post.details", "details")
|
||||
.where("post.id=:id")
|
||||
.setParameter("id", updatedPost.id)
|
||||
.getSingleResult()
|
||||
.getSingleResult();
|
||||
}).then(updatedPostReloaded => {
|
||||
updatedPostReloaded.details.comment.should.be.equal("this is post");
|
||||
});
|
||||
|
||||
@ -268,7 +268,6 @@ describe("many-to-many", function() {
|
||||
});
|
||||
|
||||
it("should remove category from post ", function() {
|
||||
//const qb =
|
||||
return postRepository
|
||||
.createQueryBuilder("p")
|
||||
.leftJoinAndSelect("p.categories", "categories")
|
||||
|
||||
@ -9,7 +9,6 @@
|
||||
"sinon": "github:DefinitelyTyped/DefinitelyTyped/sinon/sinon.d.ts#7a3ca1f0b8a0960af9fc1838f3234cc9d6ce0645"
|
||||
},
|
||||
"ambientDependencies": {
|
||||
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#6697d6f7dadbf5773cb40ecda35a76027e0783b2",
|
||||
"lodash": "github:DefinitelyTyped/DefinitelyTyped/lodash/lodash.d.ts#7b7aa2027a8fb6219a8bcf1b6bb12bcd0ff9539d",
|
||||
"node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#cf7f980ba6cf09f75aaa9b5e53010db3c00b9aaf"
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user