本文整理匯總了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);
}