typeorm 0.3.6 -DB连接每个请求
我从0.2。我不确定如何使用新数据源处理多租户连接。 我以前的实现是基于ConnectionManager,它看起来像这样:
{
const connectionManager = getConnectionManager();
// Check if tenant connection exists
if (connectionManager.has(tenant.name)) {
const connection = connectionManager.get(tenant.name);
return Promise.resolve(
connection.isConnected ? connection : connection.connect()
);
}
// Create new tenant connection
return createConnection({
type: 'postgres',
name: tenant.name,
host: tenant.host,
port: tenant.port,
username: tenant.username,
password: tenant.password,
database: tenant.database,
entities: [...TenantModule.entities],
});
}
现在已贬低了连接Manger。保持自己的连接阵列对我来说听起来不正确。 关于如何正确处理的任何想法?
I’m migrating from 0.2.* to 0.3.6 version of typeorm. I’m not sure how to handle multi-tenant connections with new DataSource.
My previous implementations was based on connectionManager and it looked something like this:
{
const connectionManager = getConnectionManager();
// Check if tenant connection exists
if (connectionManager.has(tenant.name)) {
const connection = connectionManager.get(tenant.name);
return Promise.resolve(
connection.isConnected ? connection : connection.connect()
);
}
// Create new tenant connection
return createConnection({
type: 'postgres',
name: tenant.name,
host: tenant.host,
port: tenant.port,
username: tenant.username,
password: tenant.password,
database: tenant.database,
entities: [...TenantModule.entities],
});
}
Connection manger is now deprecated. Maintaining my own array of connections doesn’t sound right to me.
Any ideas on how this should be handled the correct way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
typeorm:0.3.6
getConnection
,createConnection
等等。您可以在这里创建新连接的新连接,您将必须使用
dataSource
如下:其中
new DataSource
等于new Connection
和dataSource
是相等的到getConnection
。要检查您是否与数据库连接,您将使用
AppDatasource
:with
typeorm: 0.3.6
getConnection
,createConnection
among others are deprecated. You can find migration guide in hereto create a new connection, you will have to use
DataSource
as follows:where
new DataSource
is equivalent tonew Connection
anddataSource
is equal togetConnection
.To check if you are connection to database, you will have utilize
AppDataSource
: