我正在尝试base repository
在 Mikro-orm 和我的服务之间建立一个类,以便拥有一个简单的接口并在技术堆栈需要时将实现交换为另一个框架。但是,FilterQuery
似乎不接受{_id: ObjectId}
作为论点:
abstract class MyBaseEntity {
@PrimaryKey()
_id: ObjectId;
@SerializedPrimaryKey()
id!: string; // won't be saved in the database
[PrimaryKeyType]: [ObjectId, string]; // i've set this up in the hope it would pick it up in the type check
}
class BaseRepositoryImpl<Entity extends MyBaseEntity> {
private collection: EntityRepository<Entity>;
constructor(
private repository: EntityRepository<Entity>
) {
this.collection = repository;
}
async findOne(id: ObjectId): Promise<Entity | null> {
const result = this.collection.findOne({_id: id}); //'{ _id: ObjectId; }' is not assignable to parameter of type 'FilterQuery<Entity>
// and '_id' does not exist in type '{ [PrimaryKeyType]?: any; }
return result;
}
}