In my queries I'm using TypeORM find
option.
How can I have IS NULL
condition in the where
clause?
Another way is you can use IsNull()
function, for example:
import { IsNull } from "typeorm";
return await getRepository(User).findOne({
where: {
username: IsNull()
}
});
If someone is looking for NOT NULL, it would be like this:
import { IsNull, Not } from "typeorm";
return await getRepository(User).findOne({
where: {
username: Not(IsNull())
}
});
You can use QueryBuilder for this purpose:
const users = await userRepository.createQueryBuilder("user")
.where("user.name IS NULL")
.getMany();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With