【发布时间】:2019-07-10 07:09:39
【问题描述】:
我使用 node.js 、 TS 和 typeorm 做后端项目。
我需要根据我发送的参数连接到中间件中不同的数据库。 我必须将查询发送到数据库。
ormconfig
[
{
"name": "default",
"type": "postgres",
"host": "localhost",
"port": 5432,
"username": "postgres",
"password": "12345",
"database": "dbOne"
},
{
"name": "second-connection",
"type": "postgres",
"host": "localhost",
"port": 5432,
"username": "postgres",
"password": "12345",
"database": "dbTwo"
}
]
这是我的连接设置。 完成此操作后,我正在尝试连接到中间件。
const connectionOptions = await getConnectionOptions("second-connection");
const conTwo = await createConnection(connectionOptions);
const managerTwo = getManager("second-connection");
const resultTwo = await managerTwo
.createQueryBuilder(SysCompany, "company")
.getOne();
console.log(resultTwo);
我想我可以连接到数据库,但是我在存储库时遇到了问题。
错误
EntityMetadataNotFound:找不到“SysCompany”的元数据。
@Entity()
export class SysCompany extends CoreEntityWithTimestamp {
@Column({ length: 100 })
name: string;
// FK
// SysPersonnel
@OneToMany(type => SysPersonnel, personnel => personnel.sysCompany)
sysPersonnels: SysPersonnel[];
}
【问题讨论】:
-
您确定 SysCompany 表已创建吗?
标签: node.js postgresql typescript typeorm koa2