typeorm 是否支持 SQL IN 子句
Does typeorm support SQL IN clauses
typeorm 是否支持 SQL IN 子句?我正在尝试查询一个存储库,其中一个字段与多个值中的一个匹配。
myRepository.find({
where: {
SomeID: // IN [1, 2, 3, 4]
}
});
您可以为此目的使用 QueryBuilder:
const users = await userRepository.createQueryBuilder("user")
.where("user.id IN (:...ids)", { ids: [1, 2, 3, 4] })
.getMany();
您现在可以执行此操作(来自文档):
import {In} from "typeorm";
const loadedPosts = await connection.getRepository(Post).find({
title: In(["About #2", "About #3"])
});
将执行以下查询:
SELECT * FROM "post" WHERE "title" IN ('About #2','About #3')
我只想建议另一种方法。
const user = await this.usersRepository
.findOne(
{
where: { id: In([1, 2, 3]) }
});
typeorm 是否支持 SQL IN 子句?我正在尝试查询一个存储库,其中一个字段与多个值中的一个匹配。
myRepository.find({
where: {
SomeID: // IN [1, 2, 3, 4]
}
});
您可以为此目的使用 QueryBuilder:
const users = await userRepository.createQueryBuilder("user")
.where("user.id IN (:...ids)", { ids: [1, 2, 3, 4] })
.getMany();
您现在可以执行此操作(来自文档):
import {In} from "typeorm";
const loadedPosts = await connection.getRepository(Post).find({
title: In(["About #2", "About #3"])
});
将执行以下查询:
SELECT * FROM "post" WHERE "title" IN ('About #2','About #3')
我只想建议另一种方法。
const user = await this.usersRepository
.findOne(
{
where: { id: In([1, 2, 3]) }
});