mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
removed deprecated createMysqlConnection method
This commit is contained in:
parent
c2b73f0811
commit
c353401e96
@ -1,18 +1,20 @@
|
||||
import {createMysqlConnection} from "../../src/typeorm";
|
||||
import {createConnection, CreateConnectionParameters} from "../../src/typeorm";
|
||||
import {Post} from "./entity/Post";
|
||||
import {ConnectionOptions} from "../../src/connection/ConnectionOptions";
|
||||
|
||||
// first create a connection
|
||||
let options: ConnectionOptions = {
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
password: "admin",
|
||||
database: "test",
|
||||
autoSchemaCreate: true
|
||||
const options: CreateConnectionParameters = {
|
||||
driver: "mysql",
|
||||
connectionOptions: {
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
password: "admin",
|
||||
database: "test",
|
||||
autoSchemaCreate: true
|
||||
},
|
||||
entities: [Post]
|
||||
};
|
||||
|
||||
createMysqlConnection(options, [Post]).then(connection => {
|
||||
createConnection(options).then(connection => {
|
||||
|
||||
let post = new Post();
|
||||
post.text = "Hello how are you?";
|
||||
|
||||
@ -1,24 +1,24 @@
|
||||
import {createMysqlConnection} from "../../src/typeorm";
|
||||
import {createConnection, CreateConnectionParameters} from "../../src/typeorm";
|
||||
import {Post} from "./entity/Post";
|
||||
import {PostDetails} from "./entity/PostDetails";
|
||||
import {Image} from "./entity/Image";
|
||||
import {ImageDetails} from "./entity/ImageDetails";
|
||||
import {Cover} from "./entity/Cover";
|
||||
import {Category} from "./entity/Category";
|
||||
import {Chapter} from "./entity/Chapter";
|
||||
|
||||
// first create a connection
|
||||
let options = {
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "test",
|
||||
password: "test",
|
||||
database: "test",
|
||||
autoSchemaCreate: true
|
||||
const options: CreateConnectionParameters = {
|
||||
driver: "mysql",
|
||||
connectionOptions: {
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
password: "admin",
|
||||
database: "test",
|
||||
autoSchemaCreate: true
|
||||
},
|
||||
entityDirectories: [__dirname + "/entity"]
|
||||
};
|
||||
|
||||
createMysqlConnection(options, [Post, PostDetails, Image, ImageDetails, Cover, Category, Chapter]).then(connection => {
|
||||
|
||||
createConnection(options).then(connection => {
|
||||
let postRepository = connection.getRepository<Post>(Post);
|
||||
|
||||
let postCover = new Cover();
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import {createMysqlConnection} from "../../src/typeorm";
|
||||
import {CreateConnectionParameters, createConnection} from "../../src/typeorm";
|
||||
import {Post} from "./entity/Post";
|
||||
import {ConnectionOptions} from "../../src/connection/ConnectionOptions";
|
||||
import {PostDetails} from "./entity/PostDetails";
|
||||
import {PostCategory} from "./entity/PostCategory";
|
||||
import {PostMetadata} from "./entity/PostMetadata";
|
||||
@ -8,17 +7,20 @@ import {PostImage} from "./entity/PostImage";
|
||||
import {PostInformation} from "./entity/PostInformation";
|
||||
import {PostAuthor} from "./entity/PostAuthor";
|
||||
|
||||
// first create a connection
|
||||
let options: ConnectionOptions = {
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
password: "admin",
|
||||
database: "test",
|
||||
autoSchemaCreate: true
|
||||
const options: CreateConnectionParameters = {
|
||||
driver: "mysql",
|
||||
connectionOptions: {
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
password: "admin",
|
||||
database: "test",
|
||||
autoSchemaCreate: true
|
||||
},
|
||||
entities: [Post, PostDetails, PostCategory, PostMetadata, PostImage, PostInformation, PostAuthor]
|
||||
};
|
||||
|
||||
createMysqlConnection(options, [Post, PostDetails, PostCategory, PostMetadata, PostImage, PostInformation, PostAuthor]).then(connection => {
|
||||
createConnection(options).then(connection => {
|
||||
|
||||
let details = new PostDetails();
|
||||
details.authorName = "Umed";
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import {createMysqlConnection} from "../../src/typeorm";
|
||||
import {CreateConnectionParameters, createConnection} from "../../src/typeorm";
|
||||
import {Post} from "./entity/Post";
|
||||
import {PostDetails} from "./entity/PostDetails";
|
||||
import {PostCategory} from "./entity/PostCategory";
|
||||
@ -7,18 +7,20 @@ import {PostImage} from "./entity/PostImage";
|
||||
import {PostInformation} from "./entity/PostInformation";
|
||||
import {PostAuthor} from "./entity/PostAuthor";
|
||||
|
||||
// first create a connection
|
||||
let options = {
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
password: "admin",
|
||||
database: "test",
|
||||
autoSchemaCreate: true
|
||||
const options: CreateConnectionParameters = {
|
||||
driver: "mysql",
|
||||
connectionOptions: {
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
password: "admin",
|
||||
database: "test",
|
||||
autoSchemaCreate: true
|
||||
},
|
||||
entities: [Post, PostDetails, PostCategory, PostMetadata, PostImage, PostInformation, PostAuthor]
|
||||
};
|
||||
|
||||
createMysqlConnection(options, [Post, PostDetails, PostCategory, PostMetadata, PostImage, PostInformation, PostAuthor]).then(connection => {
|
||||
|
||||
createConnection(options).then(connection => {
|
||||
let details = new PostDetails();
|
||||
details.authorName = "Umed";
|
||||
details.comment = "about post";
|
||||
|
||||
@ -1,19 +1,21 @@
|
||||
import {createMysqlConnection} from "../../src/typeorm";
|
||||
import {CreateConnectionParameters, createConnection} from "../../src/typeorm";
|
||||
import {Post} from "./entity/Post";
|
||||
import {PostDetails} from "./entity/PostDetails";
|
||||
|
||||
// first create a connection
|
||||
let options = {
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
password: "admin",
|
||||
database: "test",
|
||||
autoSchemaCreate: true
|
||||
const options: CreateConnectionParameters = {
|
||||
driver: "mysql",
|
||||
connectionOptions: {
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
password: "admin",
|
||||
database: "test",
|
||||
autoSchemaCreate: true
|
||||
},
|
||||
entityDirectories: [__dirname + "/entity"]
|
||||
};
|
||||
|
||||
createMysqlConnection(options, [__dirname + "/entity"]).then(connection => {
|
||||
|
||||
createConnection(options).then(connection => {
|
||||
let details1 = new PostDetails();
|
||||
details1.comment = "People";
|
||||
|
||||
|
||||
@ -1,19 +1,25 @@
|
||||
import {createMysqlConnection} from "../../src/typeorm";
|
||||
import {createConnection, CreateConnectionParameters} from "../../src/typeorm";
|
||||
import {Post} from "./entity/Post";
|
||||
import {PostCategory} from "./entity/PostCategory";
|
||||
import {PostAuthor} from "./entity/PostAuthor";
|
||||
import {EverythingSubscriber} from "./subscriber/EverythingSubscriber";
|
||||
|
||||
// first create a connection
|
||||
let options = {
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
password: "admin",
|
||||
database: "test",
|
||||
autoSchemaCreate: true
|
||||
const options: CreateConnectionParameters = {
|
||||
driver: "mysql",
|
||||
connectionOptions: {
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
password: "admin",
|
||||
database: "test",
|
||||
autoSchemaCreate: true
|
||||
},
|
||||
entities: [Post, PostAuthor, PostCategory],
|
||||
subscribers: [EverythingSubscriber]
|
||||
};
|
||||
|
||||
createMysqlConnection(options, [__dirname + "/entity"], [__dirname + "/subscriber"]).then(connection => {
|
||||
createConnection(options).then(connection => {
|
||||
|
||||
let category1 = new PostCategory();
|
||||
category1.name = "post category #1";
|
||||
|
||||
@ -1,20 +1,23 @@
|
||||
import {createMysqlConnection} from "../../src/typeorm";
|
||||
import {createConnection, CreateConnectionParameters} from "../../src/typeorm";
|
||||
import {Post} from "./entity/Post";
|
||||
import {PostCategory} from "./entity/PostCategory";
|
||||
import {PostAuthor} from "./entity/PostAuthor";
|
||||
import {Blog} from "./entity/Blog";
|
||||
|
||||
// first create a connection
|
||||
let options = {
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
password: "admin",
|
||||
database: "test",
|
||||
autoSchemaCreate: true
|
||||
const options: CreateConnectionParameters = {
|
||||
driver: "mysql",
|
||||
connectionOptions: {
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
password: "admin",
|
||||
database: "test",
|
||||
autoSchemaCreate: true
|
||||
},
|
||||
entityDirectories: [__dirname + "/entity"]
|
||||
};
|
||||
|
||||
createMysqlConnection(options, [__dirname + "/entity"]).then(connection => {
|
||||
createConnection(options).then(connection => {
|
||||
|
||||
let category1 = new PostCategory();
|
||||
category1.name = "post category #1";
|
||||
|
||||
@ -1,19 +1,22 @@
|
||||
import {createMysqlConnection} from "../../src/typeorm";
|
||||
import {createConnection, CreateConnectionParameters} from "../../src/typeorm";
|
||||
import {Post} from "./entity/Post";
|
||||
import {PostCategory} from "./entity/PostCategory";
|
||||
import {PostAuthor} from "./entity/PostAuthor";
|
||||
|
||||
// first create a connection
|
||||
let options = {
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
password: "admin",
|
||||
database: "test",
|
||||
autoSchemaCreate: true
|
||||
const options: CreateConnectionParameters = {
|
||||
driver: "mysql",
|
||||
connectionOptions: {
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
password: "admin",
|
||||
database: "test",
|
||||
autoSchemaCreate: true
|
||||
},
|
||||
entityDirectories: [__dirname + "/entity"]
|
||||
};
|
||||
|
||||
createMysqlConnection(options, [__dirname + "/entity"]).then(connection => {
|
||||
createConnection(options).then(connection => {
|
||||
|
||||
let postRepository = connection.getRepository(Post);
|
||||
const posts: Post[] = [];
|
||||
|
||||
@ -1,18 +1,20 @@
|
||||
import {createMysqlConnection} from "../../src/typeorm";
|
||||
import {createConnection, CreateConnectionParameters} from "../../src/typeorm";
|
||||
import {Category} from "./entity/Category";
|
||||
|
||||
// first create a connection
|
||||
let options = {
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
password: "admin",
|
||||
database: "test",
|
||||
autoSchemaCreate: true
|
||||
const options: CreateConnectionParameters = {
|
||||
driver: "mysql",
|
||||
connectionOptions: {
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
password: "admin",
|
||||
database: "test",
|
||||
autoSchemaCreate: true
|
||||
},
|
||||
entityDirectories: [__dirname + "/entity"]
|
||||
};
|
||||
|
||||
createMysqlConnection(options, [Category]).then(connection => {
|
||||
|
||||
createConnection(options).then(connection => {
|
||||
let categoryRepository = connection.getRepository(Category);
|
||||
|
||||
let category1 = new Category();
|
||||
|
||||
@ -1,20 +1,23 @@
|
||||
import {createMysqlConnection} from "../../src/typeorm";
|
||||
import {CreateConnectionParameters, createConnection} from "../../src/typeorm";
|
||||
import {Post} from "./entity/Post";
|
||||
import {PostCategory} from "./entity/PostCategory";
|
||||
import {PostAuthor} from "./entity/PostAuthor";
|
||||
|
||||
// first create a connection
|
||||
let options = {
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
password: "admin",
|
||||
database: "test",
|
||||
autoSchemaCreate: true
|
||||
const options: CreateConnectionParameters = {
|
||||
driver: "mysql",
|
||||
connectionOptions: {
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
password: "admin",
|
||||
database: "test",
|
||||
autoSchemaCreate: true
|
||||
},
|
||||
entityDirectories: [__dirname + "/entity"],
|
||||
subscriberDirectories: [__dirname + "/subscriber"]
|
||||
};
|
||||
|
||||
createMysqlConnection(options, [__dirname + "/entity"], [__dirname + "/subscriber"]).then(connection => {
|
||||
|
||||
createConnection(options).then(connection => {
|
||||
let category1 = new PostCategory();
|
||||
category1.name = "post category #1";
|
||||
|
||||
|
||||
@ -57,6 +57,10 @@ export class ConnectionManager {
|
||||
if (!name) {
|
||||
name = "default";
|
||||
}
|
||||
const existConnection = this.connections.find(connection => connection.name === name);
|
||||
if (existConnection)
|
||||
this.connections.splice(this.connections.indexOf(existConnection), 1);
|
||||
|
||||
const connection = new Connection(<string> name, driver);
|
||||
this.connections.push(connection);
|
||||
return connection;
|
||||
@ -107,12 +111,7 @@ export class ConnectionManager {
|
||||
paths = <string[]> connectionNameOrPaths;
|
||||
}
|
||||
|
||||
const allSubscriberClasses = importClassesFromDirectories(paths);
|
||||
const subscribers = defaultMetadataStorage
|
||||
.findOrmEventSubscribersForClasses(allSubscriberClasses)
|
||||
.map(metadata => this.createContainerInstance(metadata.target));
|
||||
|
||||
this.getConnection(connectionName).addSubscribers(subscribers);
|
||||
this.importSubscribers(connectionName, importClassesFromDirectories(paths));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -127,7 +126,6 @@ export class ConnectionManager {
|
||||
} else {
|
||||
entities = <Function[]> connectionNameOrEntities;
|
||||
}
|
||||
|
||||
const entityMetadatas = this.entityMetadataBuilder.build(entities);
|
||||
const entityListenerMetadatas = defaultMetadataStorage.findEntityListenersForClasses(entities);
|
||||
|
||||
@ -135,6 +133,26 @@ export class ConnectionManager {
|
||||
this.getConnection(connectionName).addEntityListenerMetadatas(entityListenerMetadatas);
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports entities for the given connection. If connection name is not given then default connection is used.
|
||||
*/
|
||||
importSubscribers(subscriberClasses: Function[]): void;
|
||||
importSubscribers(connectionName: string, subscriberClasses: Function[]): void;
|
||||
importSubscribers(connectionNameOrSubscriberClasses: string|Function[], subscriberClasses?: Function[]): void {
|
||||
let connectionName = "default";
|
||||
if (subscriberClasses) {
|
||||
connectionName = <string> connectionNameOrSubscriberClasses;
|
||||
} else {
|
||||
subscriberClasses = <Function[]> connectionNameOrSubscriberClasses;
|
||||
}
|
||||
|
||||
const subscribers = defaultMetadataStorage
|
||||
.findOrmEventSubscribersForClasses(subscriberClasses)
|
||||
.map(metadata => this.createContainerInstance(metadata.target));
|
||||
|
||||
this.getConnection(connectionName).addSubscribers(subscribers);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Private Methods
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@ -10,16 +10,50 @@ let mysql = require("mysql");
|
||||
*/
|
||||
export const connectionManager = new ConnectionManager();
|
||||
|
||||
/**
|
||||
* All options to help to create a new connection.
|
||||
*/
|
||||
export interface CreateConnectionParameters {
|
||||
|
||||
/**
|
||||
* Driver type. Mysql is the only driver supported at this moment.
|
||||
*/
|
||||
driver: "mysql";
|
||||
|
||||
/**
|
||||
* Database connection options.
|
||||
*/
|
||||
connectionOptions: ConnectionOptions;
|
||||
|
||||
/**
|
||||
* Connection name. By default its called "default". Different connections must have different names.
|
||||
*/
|
||||
connectionName?: string;
|
||||
connectionOptions?: ConnectionOptions;
|
||||
|
||||
/**
|
||||
* Entities to be loaded for the new connection.
|
||||
*/
|
||||
entities?: Function[];
|
||||
|
||||
/**
|
||||
* Subscribers to be loaded for the new connection.
|
||||
*/
|
||||
subscribers?: Function[];
|
||||
|
||||
/**
|
||||
* List of directories from where entities will be loaded.
|
||||
*/
|
||||
entityDirectories?: string[];
|
||||
|
||||
/**
|
||||
* List of directories from where subscribers will be loaded.
|
||||
*/
|
||||
subscriberDirectories?: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new connection with the database.
|
||||
*/
|
||||
export function createConnection(parameters: CreateConnectionParameters): Promise<Connection> {
|
||||
|
||||
let connection: Connection;
|
||||
@ -34,46 +68,16 @@ export function createConnection(parameters: CreateConnectionParameters): Promis
|
||||
if (parameters.entityDirectories && parameters.entityDirectories.length > 0)
|
||||
connectionManager.importEntitiesFromDirectories(parameters.connectionName, parameters.entityDirectories);
|
||||
|
||||
if (parameters.entities) {
|
||||
if (parameters.entities)
|
||||
connectionManager.importEntities(parameters.connectionName, parameters.entities);
|
||||
}
|
||||
|
||||
if (parameters.subscriberDirectories && parameters.subscriberDirectories.length > 0)
|
||||
connectionManager.importSubscribersFromDirectories(parameters.connectionName, parameters.subscriberDirectories);
|
||||
|
||||
// if (parameters.subscribers)
|
||||
// connectionManager.importSubscribers(parameters.subscribers);
|
||||
if (parameters.subscribers)
|
||||
connectionManager.importSubscribers(parameters.subscribers);
|
||||
|
||||
return connection
|
||||
.connect(parameters.connectionOptions)
|
||||
.then(() => connection);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new connection to mysql. Imports documents and subscribers from the given directories.
|
||||
* @deprecated
|
||||
*/
|
||||
export function createMysqlConnection(options: string, documentDirectories: string[]|Function[], subscriberDirectories?: string[]): Promise<Connection>;
|
||||
export function createMysqlConnection(options: ConnectionOptions, documentDirectories: string[]|Function[], subscriberDirectories?: string[]): Promise<Connection>;
|
||||
export function createMysqlConnection(configuration: string|ConnectionOptions, documentDirectories: string[]|Function[], subscriberDirectories?: string[]): Promise<Connection> {
|
||||
if (typeof configuration === "string") {
|
||||
configuration = { url: <string> configuration };
|
||||
}
|
||||
|
||||
connectionManager.createConnection(new MysqlDriver(mysql));
|
||||
|
||||
if (documentDirectories && documentDirectories.length > 0) {
|
||||
if (typeof documentDirectories[0] === "string") {
|
||||
connectionManager.importEntitiesFromDirectories(<string[]> documentDirectories);
|
||||
} else {
|
||||
connectionManager.importEntities(<Function[]> documentDirectories);
|
||||
}
|
||||
}
|
||||
|
||||
if (subscriberDirectories && subscriberDirectories.length > 0)
|
||||
connectionManager.importSubscribersFromDirectories(subscriberDirectories);
|
||||
|
||||
const connection = connectionManager.getConnection();
|
||||
return connection.connect(<ConnectionOptions> configuration).then(() => connection);
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,7 @@
|
||||
import * as chai from "chai";
|
||||
import {expect} from "chai";
|
||||
import {Connection} from "../../src/connection/Connection";
|
||||
import {createMysqlConnection} from "../../src/typeorm";
|
||||
import {ConnectionOptions} from "../../src/connection/ConnectionOptions";
|
||||
import {createConnection, CreateConnectionParameters} from "../../src/typeorm";
|
||||
import {Repository} from "../../src/repository/Repository";
|
||||
import {SchemaCreator} from "../../src/schema-creator/SchemaCreator";
|
||||
import {PostDetails} from "../../sample/sample2-one-to-one/entity/PostDetails";
|
||||
@ -20,21 +19,25 @@ describe("one-to-one", function() {
|
||||
// Configuration
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
let options: ConnectionOptions = {
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
password: "admin",
|
||||
database: "test",
|
||||
autoSchemaCreate: true
|
||||
const options: CreateConnectionParameters = {
|
||||
driver: "mysql",
|
||||
connectionOptions: {
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
password: "admin",
|
||||
database: "test",
|
||||
autoSchemaCreate: true
|
||||
},
|
||||
entities: [Post, PostDetails, PostCategory, PostMetadata, PostImage, PostInformation, PostAuthor]
|
||||
};
|
||||
|
||||
|
||||
// connect to db
|
||||
let connection: Connection;
|
||||
before(function() {
|
||||
return createMysqlConnection(options, [Post, PostDetails, PostCategory, PostMetadata, PostImage, PostInformation, PostAuthor]).then(conn => {
|
||||
connection = conn;
|
||||
}).catch(e => console.log("Error during connection to db: " + e));
|
||||
return createConnection(options)
|
||||
.then(con => connection = con)
|
||||
.catch(e => console.log("Error during connection to db: " + e));
|
||||
});
|
||||
|
||||
after(function() {
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
import * as chai from "chai";
|
||||
import {expect} from "chai";
|
||||
import {Connection} from "../../src/connection/Connection";
|
||||
import {createMysqlConnection} from "../../src/typeorm";
|
||||
import {ConnectionOptions} from "../../src/connection/ConnectionOptions";
|
||||
import {createConnection, CreateConnectionParameters} from "../../src/typeorm";
|
||||
import {Repository} from "../../src/repository/Repository";
|
||||
import {SchemaCreator} from "../../src/schema-creator/SchemaCreator";
|
||||
import {PostDetails} from "../../sample/sample3-many-to-one/entity/PostDetails";
|
||||
@ -20,23 +19,27 @@ describe("many-to-one", function() {
|
||||
// Configuration
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
let options: ConnectionOptions = {
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
password: "admin",
|
||||
database: "test",
|
||||
autoSchemaCreate: true
|
||||
const options: CreateConnectionParameters = {
|
||||
driver: "mysql",
|
||||
connectionOptions: {
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
password: "admin",
|
||||
database: "test",
|
||||
autoSchemaCreate: true
|
||||
},
|
||||
entities: [Post, PostDetails, PostCategory, PostMetadata, PostImage, PostInformation, PostAuthor]
|
||||
};
|
||||
|
||||
|
||||
// connect to db
|
||||
let connection: Connection;
|
||||
before(function() {
|
||||
return createMysqlConnection(options, [Post, PostDetails, PostCategory, PostMetadata, PostImage, PostInformation, PostAuthor]).then(conn => {
|
||||
connection = conn;
|
||||
}).catch(e => console.log("Error during connection to db: " + e));
|
||||
return createConnection(options)
|
||||
.then(con => connection = con)
|
||||
.catch(e => console.log("Error during connection to db: " + e));
|
||||
});
|
||||
|
||||
|
||||
after(function() {
|
||||
connection.close();
|
||||
});
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
import * as chai from "chai";
|
||||
import {expect} from "chai";
|
||||
import {Connection} from "../../src/connection/Connection";
|
||||
import {createMysqlConnection} from "../../src/typeorm";
|
||||
import {ConnectionOptions} from "../../src/connection/ConnectionOptions";
|
||||
import {CreateConnectionParameters, createConnection} from "../../src/typeorm";
|
||||
import {Repository} from "../../src/repository/Repository";
|
||||
import {SchemaCreator} from "../../src/schema-creator/SchemaCreator";
|
||||
import {PostDetails} from "../../sample/sample4-many-to-many/entity/PostDetails";
|
||||
@ -18,27 +17,32 @@ describe("many-to-many", function() {
|
||||
// Configuration
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
let options: ConnectionOptions = {
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
password: "admin",
|
||||
database: "test",
|
||||
autoSchemaCreate: true,
|
||||
logging: {
|
||||
logOnlyFailedQueries: true,
|
||||
logFailedQueryError: true
|
||||
}
|
||||
const options: CreateConnectionParameters = {
|
||||
driver: "mysql",
|
||||
connectionOptions: {
|
||||
host: "192.168.99.100",
|
||||
port: 3306,
|
||||
username: "root",
|
||||
password: "admin",
|
||||
database: "test",
|
||||
autoSchemaCreate: true,
|
||||
logging: {
|
||||
logOnlyFailedQueries: true,
|
||||
logFailedQueryError: true
|
||||
}
|
||||
},
|
||||
entityDirectories: [__dirname + "/../../sample/sample4-many-to-many/entity"]
|
||||
};
|
||||
|
||||
|
||||
// connect to db
|
||||
let connection: Connection;
|
||||
before(function() {
|
||||
return createMysqlConnection(options, [__dirname + "/../../sample/sample4-many-to-many/entity"]).then(conn => {
|
||||
connection = conn;
|
||||
}).catch(e => console.log("Error during connection to db: " + e));
|
||||
return createConnection(options)
|
||||
.then(con => connection = con)
|
||||
.catch(e => console.log("Error during connection to db: " + e));
|
||||
});
|
||||
|
||||
|
||||
after(function() {
|
||||
connection.close();
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user