mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
fixed tests; fixed issue with column name in joins in query builder; refactored connection and driver options
This commit is contained in:
parent
139d1d662a
commit
8ee51c9fa8
@ -3,8 +3,8 @@ import {createConnection, ConnectionOptions} from "../../src/index";
|
||||
import {Post} from "./entity/Post";
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
|
||||
@ -7,8 +7,8 @@ import {Cover} from "./entity/Cover";
|
||||
import {Category} from "./entity/Category";
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
|
||||
@ -3,8 +3,8 @@ import {createConnection, ConnectionOptions} from "../../src/index";
|
||||
import {EverythingEntity} from "./entity/EverythingEntity";
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
|
||||
@ -4,8 +4,8 @@ import {Post} from "./entity/Post";
|
||||
import {CustomNamingStrategy} from "./naming-strategy/CustomNamingStrategy";
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
|
||||
@ -6,8 +6,8 @@ import {PostAuthor} from "./entity/PostAuthor";
|
||||
import {Blog} from "./entity/Blog";
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
|
||||
@ -4,8 +4,8 @@ import {Post} from "./entity/Post";
|
||||
import {PostAuthor} from "./entity/PostAuthor";
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
|
||||
@ -3,8 +3,8 @@ import {createConnection, ConnectionOptions} from "../../src/index";
|
||||
import {Post} from "./entity/Post";
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
|
||||
@ -3,8 +3,8 @@ import {createConnection, ConnectionOptions} from "../../src/index";
|
||||
import {Post} from "./entity/Post";
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
|
||||
@ -3,8 +3,8 @@ import {createConnection, ConnectionOptions} from "../../src/index";
|
||||
import {Post} from "./entity/Post";
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
|
||||
@ -5,8 +5,8 @@ import {Author} from "./entity/Author";
|
||||
import {Category} from "./entity/Category";
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
|
||||
@ -6,8 +6,8 @@ import {Category} from "./entity/Category";
|
||||
import {PostMetadata} from "./entity/PostMetadata";
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
|
||||
@ -9,8 +9,8 @@ import {PostInformation} from "./entity/PostInformation";
|
||||
import {PostAuthor} from "./entity/PostAuthor";
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
|
||||
@ -5,8 +5,8 @@ import {Author} from "./entity/Author";
|
||||
import {Category} from "./entity/Category";
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
|
||||
@ -5,8 +5,8 @@ import {Author} from "./entity/Author";
|
||||
import {Category} from "./entity/Category";
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
|
||||
@ -3,8 +3,8 @@ import {createConnection, ConnectionOptions} from "../../src/index";
|
||||
import {Category} from "./entity/Category";
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
|
||||
@ -5,8 +5,8 @@ import {Author} from "./entity/Author";
|
||||
import {Category} from "./entity/Category";
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
|
||||
@ -5,8 +5,8 @@ import {Post} from "./entity/Post";
|
||||
// NOTE: this example is not working yet, only concepts of how this feature must work described here
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
|
||||
@ -4,8 +4,8 @@ import {Post} from "./entity/Post";
|
||||
import {Author} from "./entity/Author";
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
|
||||
@ -5,8 +5,8 @@ import {Question} from "./entity/Question";
|
||||
import {Counters} from "./entity/Counters";
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
|
||||
@ -9,8 +9,8 @@ import {PostInformation} from "./entity/PostInformation";
|
||||
import {PostAuthor} from "./entity/PostAuthor";
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
|
||||
@ -4,8 +4,8 @@ import {Post} from "./entity/Post";
|
||||
import {PostDetails} from "./entity/PostDetails";
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
|
||||
@ -7,8 +7,8 @@ import {EverythingSubscriber} from "./subscriber/EverythingSubscriber";
|
||||
|
||||
// first create a connection
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
|
||||
@ -6,8 +6,8 @@ import {PostAuthor} from "./entity/PostAuthor";
|
||||
import {Blog} from "./entity/Blog";
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
|
||||
@ -5,8 +5,8 @@ import {PostCategory} from "./entity/PostCategory";
|
||||
import {PostAuthor} from "./entity/PostAuthor";
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
|
||||
@ -3,8 +3,8 @@ import {createConnection, ConnectionOptions} from "../../src/index";
|
||||
import {Category} from "./entity/Category";
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
|
||||
@ -5,8 +5,8 @@ import {PostCategory} from "./entity/PostCategory";
|
||||
import {PostAuthor} from "./entity/PostAuthor";
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
|
||||
@ -51,7 +51,7 @@ export class ConnectionManager {
|
||||
* Creates a new connection based on the given connection options and registers this connection in the manager.
|
||||
*/
|
||||
create(options: ConnectionOptions): Connection {
|
||||
const driver = this.createDriver(options.driver, options.driverOptions);
|
||||
const driver = this.createDriver(options.driver);
|
||||
const connection = this.createConnection(options.connectionName || "default", driver);
|
||||
|
||||
if (options.entitySchemaDirectories && options.entitySchemaDirectories.length > 0)
|
||||
@ -106,14 +106,14 @@ export class ConnectionManager {
|
||||
/**
|
||||
* Creates a new driver based on the given driver type and options.
|
||||
*/
|
||||
private createDriver(driverType: "mysql"|"postgres", options: DriverOptions): Driver {
|
||||
switch (driverType) {
|
||||
private createDriver(options: DriverOptions): Driver {
|
||||
switch (options.type) {
|
||||
case "mysql":
|
||||
return new MysqlDriver(options);
|
||||
case "postgres":
|
||||
return new PostgresDriver(options);
|
||||
default:
|
||||
throw new MissingDriverError(driverType);
|
||||
throw new MissingDriverError(options.type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -6,23 +6,19 @@ import {EntitySchema} from "../metadata/entity-schema/EntitySchema";
|
||||
*/
|
||||
export interface ConnectionOptions {
|
||||
|
||||
/**
|
||||
* Driver type. Mysql and postgres are the only drivers supported at this moment.
|
||||
*/
|
||||
driver: "mysql"|"postgres";
|
||||
|
||||
/**
|
||||
* Database connection options.
|
||||
*/
|
||||
driverOptions: DriverOptions;
|
||||
driver: DriverOptions;
|
||||
|
||||
/**
|
||||
* Connection name. By default its called "default". Different connections must have different names.
|
||||
* Connection name. If connection name is not given then it will be called "default".
|
||||
* Different connections must have different names.
|
||||
*/
|
||||
connectionName?: string;
|
||||
|
||||
/**
|
||||
* Name of the naming strategy or target class of the naming strategy to be used on this connection.
|
||||
* Name of the naming strategy or target class of the naming strategy to be used for this connection.
|
||||
*/
|
||||
usedNamingStrategy?: string|Function;
|
||||
|
||||
@ -34,47 +30,52 @@ export interface ConnectionOptions {
|
||||
dropSchemaOnConnection?: boolean;
|
||||
|
||||
/**
|
||||
* Indicates if database schema should be auto created every time application launch.
|
||||
* Indicates if database schema should be auto created on every application launch.
|
||||
*/
|
||||
autoSchemaCreate?: boolean;
|
||||
|
||||
/**
|
||||
* Entities to be loaded for the new connection.
|
||||
* Entities to be loaded for the this connection.
|
||||
*/
|
||||
entities?: Function[];
|
||||
|
||||
/**
|
||||
* Subscribers to be loaded for the new connection.
|
||||
* Subscribers to be loaded for the this connection.
|
||||
*/
|
||||
subscribers?: Function[];
|
||||
|
||||
/**
|
||||
* Naming strategies to be loaded.
|
||||
* Naming strategies to be loaded for the this connection.
|
||||
*/
|
||||
namingStrategies?: Function[];
|
||||
|
||||
/**
|
||||
* Entity schemas to be loaded for the new connection.
|
||||
* Entity schemas to be loaded for the this connection.
|
||||
*/
|
||||
entitySchemas?: EntitySchema[];
|
||||
|
||||
/**
|
||||
* List of directories from where entities will be loaded.
|
||||
* List of files with entities from where they will be loaded.
|
||||
* Glob patterns are supported.
|
||||
*/
|
||||
entityDirectories?: string[];
|
||||
|
||||
/**
|
||||
* List of directories from where subscribers will be loaded.
|
||||
* List of files with subscribers from where they will be loaded.
|
||||
* Glob patterns are supported.
|
||||
*/
|
||||
subscriberDirectories?: string[];
|
||||
|
||||
/**
|
||||
* List of directories from where naming strategies will be loaded.
|
||||
* List of files with naming strategies from where they will be loaded.
|
||||
* Glob patterns are supported.
|
||||
*/
|
||||
namingStrategyDirectories?: string[];
|
||||
|
||||
/**
|
||||
* List of directories from where entity schemas will be loaded.
|
||||
* List of files with entity schemas from where they will be loaded.
|
||||
* Glob patterns are supported.
|
||||
*/
|
||||
entitySchemaDirectories?: string[];
|
||||
|
||||
}
|
||||
@ -3,6 +3,11 @@
|
||||
*/
|
||||
export interface DriverOptions {
|
||||
|
||||
/**
|
||||
* Database type. Mysql and postgres are the only drivers supported at this moment.
|
||||
*/
|
||||
type: "mysql"|"postgres";
|
||||
|
||||
/**
|
||||
* Url to where perform connection.
|
||||
*/
|
||||
@ -44,17 +49,17 @@ export interface DriverOptions {
|
||||
logger?: (message: any, level: string) => void;
|
||||
|
||||
/**
|
||||
* Used if you want to log every executed query.
|
||||
* Set to true if you want to log every executed query.
|
||||
*/
|
||||
logQueries?: boolean;
|
||||
|
||||
/**
|
||||
* Used if you want to log only failed query.
|
||||
* Set to true if you want to log only failed query.
|
||||
*/
|
||||
logOnlyFailedQueries?: boolean;
|
||||
|
||||
/**
|
||||
* Used if you want to log error of the failed query.
|
||||
* Set to true if you want to log error of the failed query.
|
||||
*/
|
||||
logFailedQueryError?: boolean;
|
||||
|
||||
|
||||
@ -759,7 +759,7 @@ export class QueryBuilder<Entity> {
|
||||
const joinMetadata = this.aliasMap.getEntityMetadataByAlias(join.alias);
|
||||
if (joinMetadata) {
|
||||
joinMetadata.columns.forEach(column => {
|
||||
allSelects.push(join.alias.name + "." + column.name + " AS " + join.alias.name + "_" + column.propertyName);
|
||||
allSelects.push(join.alias.name + "." + column.name + " AS " + join.alias.name + "_" + column.name);
|
||||
});
|
||||
} else {
|
||||
allSelects.push(join.alias.name);
|
||||
|
||||
@ -13,8 +13,7 @@ describe("ConnectionManager", () => {
|
||||
|
||||
it("should create a mysql connection when mysql driver is specified", () => {
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: createTestingConnectionOptions("mysql")
|
||||
driver: createTestingConnectionOptions("mysql")
|
||||
};
|
||||
const connectionManager = new ConnectionManager();
|
||||
const connection = connectionManager.create(options);
|
||||
@ -23,9 +22,8 @@ describe("ConnectionManager", () => {
|
||||
|
||||
it("should create a postgres connection when mysql driver is specified", () => {
|
||||
const options: ConnectionOptions = {
|
||||
driver: "postgres",
|
||||
connectionName: "myPostgresConnection",
|
||||
driverOptions: createTestingConnectionOptions("postgres")
|
||||
driver: createTestingConnectionOptions("postgres")
|
||||
};
|
||||
const connectionManager = new ConnectionManager();
|
||||
const connection = connectionManager.create(options);
|
||||
@ -59,9 +57,8 @@ describe("ConnectionManager", () => {
|
||||
|
||||
it("should give connection with a requested name", () => {
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
connectionName: "myMysqlConnection",
|
||||
driverOptions: createTestingConnectionOptions("mysql")
|
||||
driver: createTestingConnectionOptions("mysql")
|
||||
};
|
||||
const connectionManager = new ConnectionManager();
|
||||
const connection = connectionManager.create(options);
|
||||
@ -71,9 +68,8 @@ describe("ConnectionManager", () => {
|
||||
|
||||
it("should throw an error if connection with the given name was not found", () => {
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
connectionName: "myMysqlConnection",
|
||||
driverOptions: createTestingConnectionOptions("mysql")
|
||||
driver: createTestingConnectionOptions("mysql")
|
||||
};
|
||||
const connectionManager = new ConnectionManager();
|
||||
const connection = connectionManager.create(options);
|
||||
|
||||
@ -41,8 +41,7 @@ describe("Connection", () => {
|
||||
let connection: Connection;
|
||||
before(async () => {
|
||||
const options: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: createTestingConnectionOptions("mysql"),
|
||||
driver: createTestingConnectionOptions("mysql"),
|
||||
entities: []
|
||||
};
|
||||
connection = await getConnectionManager().create(options);
|
||||
@ -226,12 +225,12 @@ describe("Connection", () => {
|
||||
let firstConnection: Connection, secondConnection: Connection;
|
||||
beforeEach(async () => {
|
||||
firstConnection = await getConnectionManager().create({
|
||||
driver: "mysql",
|
||||
driverOptions: createTestingConnectionOptions("mysql")
|
||||
driver: createTestingConnectionOptions("mysql"),
|
||||
connectionName: "firstConnection"
|
||||
});
|
||||
secondConnection = await getConnectionManager().create({
|
||||
driver: "mysql",
|
||||
driverOptions: createTestingConnectionOptions("mysql")
|
||||
driver: createTestingConnectionOptions("mysql"),
|
||||
connectionName: "secondConnection"
|
||||
});
|
||||
});
|
||||
|
||||
@ -241,7 +240,7 @@ describe("Connection", () => {
|
||||
firstConnection.getRepository(Post).should.be.instanceOf(Repository);
|
||||
firstConnection.getRepository(Post).target.should.be.equal(Post);
|
||||
expect(() => firstConnection.getRepository(Category)).to.throw(RepositoryNotFoundError);
|
||||
firstConnection.close();
|
||||
await firstConnection.close();
|
||||
});
|
||||
|
||||
it("should import second connection's entities only", async () => {
|
||||
@ -250,7 +249,7 @@ describe("Connection", () => {
|
||||
secondConnection.getRepository(Category).should.be.instanceOf(Repository);
|
||||
secondConnection.getRepository(Category).target.should.be.equal(Category);
|
||||
expect(() => secondConnection.getRepository(Post)).to.throw(RepositoryNotFoundError);
|
||||
secondConnection.close();
|
||||
await secondConnection.close();
|
||||
});
|
||||
|
||||
it("should import first connection's entity schemas only", async () => {
|
||||
@ -259,7 +258,7 @@ describe("Connection", () => {
|
||||
firstConnection.getRepository("User").should.be.instanceOf(Repository);
|
||||
firstConnection.getRepository("User").target.should.be.equal("User");
|
||||
expect(() => firstConnection.getRepository("Photo")).to.throw(RepositoryNotFoundError);
|
||||
firstConnection.close();
|
||||
await firstConnection.close();
|
||||
});
|
||||
|
||||
it("should import second connection's entity schemas only", async () => {
|
||||
@ -268,7 +267,7 @@ describe("Connection", () => {
|
||||
secondConnection.getRepository("Photo").should.be.instanceOf(Repository);
|
||||
secondConnection.getRepository("Photo").target.should.be.equal("Photo");
|
||||
expect(() => secondConnection.getRepository("User")).to.throw(RepositoryNotFoundError);
|
||||
secondConnection.close();
|
||||
await secondConnection.close();
|
||||
});
|
||||
|
||||
});
|
||||
@ -278,8 +277,7 @@ describe("Connection", () => {
|
||||
let connection: Connection;
|
||||
beforeEach(async () => {
|
||||
connection = await getConnectionManager().create({
|
||||
driver: "mysql",
|
||||
driverOptions: createTestingConnectionOptions("mysql")
|
||||
driver: createTestingConnectionOptions("mysql")
|
||||
});
|
||||
});
|
||||
afterEach(() => connection.isConnected ? connection.close() : {});
|
||||
@ -326,8 +324,7 @@ describe("Connection", () => {
|
||||
let connection: Connection;
|
||||
beforeEach(async () => {
|
||||
connection = await getConnectionManager().create({
|
||||
driver: "mysql",
|
||||
driverOptions: createTestingConnectionOptions("mysql")
|
||||
driver: createTestingConnectionOptions("mysql")
|
||||
});
|
||||
});
|
||||
afterEach(() => connection.isConnected ? connection.close() : {});
|
||||
|
||||
@ -15,8 +15,8 @@ describe("persistence > many-to-many", function() {
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
const parameters: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
@ -40,9 +40,7 @@ describe("persistence > many-to-many", function() {
|
||||
});
|
||||
});
|
||||
|
||||
after(function() {
|
||||
connection.close();
|
||||
});
|
||||
after(() => connection.close());
|
||||
|
||||
// clean up database before each test
|
||||
function reloadDatabase() {
|
||||
|
||||
@ -14,8 +14,8 @@ describe("repository > removeById and removeByIds methods", function() {
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
const parameters: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
@ -40,7 +40,7 @@ describe("repository > removeById and removeByIds methods", function() {
|
||||
});
|
||||
|
||||
after(function() {
|
||||
connection.close();
|
||||
return connection.close();
|
||||
});
|
||||
|
||||
// clean up database before each test
|
||||
|
||||
@ -15,8 +15,8 @@ describe("repository > set/add/remove relation methods", function() {
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
const parameters: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
@ -42,7 +42,7 @@ describe("repository > set/add/remove relation methods", function() {
|
||||
});
|
||||
|
||||
after(function() {
|
||||
connection.close();
|
||||
return connection.close();
|
||||
});
|
||||
|
||||
// clean up database before each test
|
||||
|
||||
@ -19,8 +19,7 @@ describe("one-to-one", function() {
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "postgres",
|
||||
driverOptions: createTestingConnectionOptions("postgres"),
|
||||
driver: createTestingConnectionOptions("postgres"),
|
||||
entities: [Post, PostDetails, PostCategory, PostMetadata, PostImage, PostInformation, PostAuthor]
|
||||
};
|
||||
|
||||
@ -32,9 +31,7 @@ describe("one-to-one", function() {
|
||||
.catch(e => console.log("Error during connection to db: " + e, e.stack));
|
||||
});
|
||||
|
||||
after(function() {
|
||||
connection.close();
|
||||
});
|
||||
after(() => connection.close());
|
||||
|
||||
// clean up database before each test
|
||||
function reloadDatabase() {
|
||||
|
||||
@ -19,8 +19,7 @@ describe("many-to-one", function() {
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "postgres",
|
||||
driverOptions: createTestingConnectionOptions("postgres"),
|
||||
driver: createTestingConnectionOptions("postgres"),
|
||||
entities: [Post, PostDetails, PostCategory, PostMetadata, PostImage, PostInformation, PostAuthor]
|
||||
};
|
||||
|
||||
@ -31,10 +30,8 @@ describe("many-to-one", function() {
|
||||
.then(con => connection = con)
|
||||
.catch(e => console.log("Error during connection to db: " + e, e.stack));
|
||||
});
|
||||
|
||||
after(function() {
|
||||
connection.close();
|
||||
});
|
||||
|
||||
after(() => connection.close());
|
||||
|
||||
// clean up database before each test
|
||||
function reloadDatabase() {
|
||||
|
||||
@ -17,8 +17,7 @@ describe("many-to-many", function() {
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: "postgres",
|
||||
driverOptions: createTestingConnectionOptions("postgres"),
|
||||
driver: createTestingConnectionOptions("postgres"),
|
||||
entityDirectories: [__dirname + "/../../sample/sample4-many-to-many/entity/*"]
|
||||
};
|
||||
|
||||
@ -30,10 +29,7 @@ describe("many-to-many", function() {
|
||||
.catch(e => console.log("Error during connection to db: " + e, e.stack));
|
||||
});
|
||||
|
||||
|
||||
after(function() {
|
||||
connection.close();
|
||||
});
|
||||
after(() => connection.close());
|
||||
|
||||
// clean up database before each test
|
||||
function reloadDatabase() {
|
||||
|
||||
@ -19,7 +19,9 @@ export function createTestingConnectionOptions(type: "mysql"|"mysqlSecondary"|"p
|
||||
const parameters = require(__dirname + "/../../../../config/parameters.json"); // path is relative to compile directory
|
||||
// const parameters = require(__dirname + "/../../config/parameters.json");
|
||||
|
||||
const driverType: "mysql"|"postgres" = type === "mysql" || type === "mysqlSecondary" ? "mysql" : "postgres";
|
||||
return {
|
||||
type: driverType,
|
||||
host: parameters.connections[type].host,
|
||||
port: parameters.connections[type].port,
|
||||
username: parameters.connections[type].username,
|
||||
@ -36,9 +38,8 @@ export function createTestingConnectionOptions(type: "mysql"|"mysqlSecondary"|"p
|
||||
export async function setupTestingConnections(options?: TestingConnectionOptions): Promise<Connection[]> {
|
||||
|
||||
const mysqlParameters: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
connectionName: "mysqlPrimaryConnection",
|
||||
driverOptions: createTestingConnectionOptions("mysql"),
|
||||
driver: createTestingConnectionOptions("mysql"),
|
||||
autoSchemaCreate: true,
|
||||
entities: options && options.entities ? options.entities : [],
|
||||
entitySchemas: options && options.entitySchemas ? options.entitySchemas : [],
|
||||
@ -46,27 +47,24 @@ export async function setupTestingConnections(options?: TestingConnectionOptions
|
||||
};
|
||||
|
||||
const mysqlSecondaryParameters: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
connectionName: "mysqlSecondaryConnection",
|
||||
driverOptions: createTestingConnectionOptions("mysqlSecondary"),
|
||||
driver: createTestingConnectionOptions("mysqlSecondary"),
|
||||
entities: options && options.entities ? options.entities : [],
|
||||
entitySchemas: options && options.entitySchemas ? options.entitySchemas : [],
|
||||
entityDirectories: options && options.entityDirectories ? options.entityDirectories : [],
|
||||
};
|
||||
|
||||
const postgresParameters: ConnectionOptions = {
|
||||
driver: "postgres",
|
||||
connectionName: "postgresPrimaryConnection",
|
||||
driverOptions: createTestingConnectionOptions("postgres"),
|
||||
driver: createTestingConnectionOptions("postgres"),
|
||||
entities: options && options.entities ? options.entities : [],
|
||||
entitySchemas: options && options.entitySchemas ? options.entitySchemas : [],
|
||||
entityDirectories: options && options.entityDirectories ? options.entityDirectories : [],
|
||||
};
|
||||
|
||||
const postgresSecondaryParameters: ConnectionOptions = {
|
||||
driver: "postgres",
|
||||
connectionName: "postgresSecondaryConnection",
|
||||
driverOptions: createTestingConnectionOptions("postgresSecondary"),
|
||||
driver: createTestingConnectionOptions("postgresSecondary"),
|
||||
entities: options && options.entities ? options.entities : [],
|
||||
entitySchemas: options && options.entitySchemas ? options.entitySchemas : [],
|
||||
entityDirectories: options && options.entityDirectories ? options.entityDirectories : [],
|
||||
@ -94,8 +92,8 @@ export async function setupTestingConnections(options?: TestingConnectionOptions
|
||||
export function setupConnection(callback: (connection: Connection) => any, entities: Function[]) {
|
||||
|
||||
const parameters: ConnectionOptions = {
|
||||
driver: "mysql",
|
||||
driverOptions: {
|
||||
driver: {
|
||||
type: "mysql",
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user