本文整理汇总了TypeScript中typeorm.createConnection函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createConnection函数的具体用法?TypeScript createConnection怎么用?TypeScript createConnection使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createConnection函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: default
export default () =>
createConnection({
type: "sqlite",
database: dbPath,
entities: [__dirname + "/../models/*.js"],
synchronize: true,
}).then(conn => {
connection = conn;
});
示例2: connect
export function connect(driver: DriverOptions): Promise<Connection> {
return createConnection({
driver: Object.assign(driver),
entities: [
Phone,
],
autoSchemaSync: false,
});
}
示例3: main
function main() {
createConnection(getPostgresConfig())
.then(() => {
console.log('database connection successful.');
startServer();
startToolServer();
})
.catch(error => console.log(error));
}
示例4: async
useFactory: async () => await createConnection({
type: 'mssql',
host: 'localhost',
port: 1433,
username: 'sa',
password: 'Aa123456',
database: 'IronManNest',
entities: [
__dirname + '/Users/*.entity{.ts,.js}'
]
})
示例5: async
useFactory: async (configService: ConfigService) =>
await createConnection({
type: "postgres",
host: configService.getString("DB_HOST"),
port: configService.getNumber("DB_PORT"),
username: configService.getString("DB_USER"),
password: configService.getString("DB_PWD"),
database: configService.getString("DB_NAME"),
entities: [__dirname + "/../../**/*.entity{.ts,.js}"],
synchronize: true
}),
示例6: async
useFactory: async () => await createConnection({
type: 'mysql',
host: 'localhost',
port: 3306,
username: 'root',
password: 'root',
database: 'test',
entities: [
__dirname + '/../**/**.entity.ts',
],
autoSchemaSync: true,
}),
示例7: async
return async () => {
if(connection == null) {
connection = await createConnection({
type: 'sqlite',
database: 'my.db',
entities: [
Todo
],
synchronize: true
});
}
return connection;
}
示例8: async
const newConnection = async () => {
const con = await createConnection({
host: 'localhost',
type: 'mysql',
username: 'root',
password: 'root',
database: 'typeorm_test',
entities,
synchronize: true,
logging: ['error', 'query'],
})
return con
}
示例9: createConnection
(async () => {
try{
let connection = await createConnection(dbOptions);
console.log("connection.isConnected = " + connection.isConnected);
await connection.getRepository(FooEntity).find(); // this will throw ECONNREFUSED
console.log("Mysql connection ok");
}
catch(e){
console.error("Mysql connection error : " + e );
}
})();
示例10: createConnections
private createConnections() {
let promises: Promise<any>[] = [];
if (this.configuration.connection)
promises.push(createConnection(this.normalizeConnectionOptions(this.configuration.connection)));
if (this.configuration.connections)
this.configuration
.connections
.map(connectionOptions => createConnection(this.normalizeConnectionOptions(connectionOptions)))
.forEach(closePromise => promises.push(closePromise));
return Promise.all(promises);
}