我正在使用 Express+TypeORM 构建一个 API。这是我的 ormconfig.json:
{
"type": "postgres",
"host": "localhost",
"port": "5432",
"username": "mdsp9070",
"password": "mdsp9070",
"database": "mesha",
"entities": ["./src/entities/*.ts"],
"migrations": ["./src/shared/infra/typeorm/migrations/*.ts"],
"cli": {
"migrationsDir": "./src/shared/infra/typeorm/migrations"
}
}
我的实体定义为:
import {
Entity,
Column,
PrimaryGeneratedColumn,
} from "typeorm";
@Entity("users")
export class User {
@PrimaryGeneratedColumn("uuid")
id: string;
@Column()
name: string;
@Column()
email: string;
@Column()
birthYear: string;
@Column()
phoneNumber: string;
@Column()
photo: string;
}
在我的 CreateUserUseCase 中,我将此存储库称为:
...
private usersRepository: IUsersRepository;
// receives ormRepository, that's users repository
constructor() {
this.usersRepository = getCustomRepository(UsersRepository);
}
...
但我收到此错误:[ERROR] 13:08:39 ConnectionNotFoundError: Connection "default" was not found.
不,当我在服务器索引上调用文件时,在 getCustomRepository 之后不会调用连接。
完整的 github 仓库:https://github.com/Mdsp9070/mesha https://github.com/Mdsp9070/mesha