How to check if is not null

Hello,
await db.query.users.findFirst({where: (users, { eq }) => eq(users.name, 'test')});
await db.query.users.findFirst({where: (users, { eq }) => eq(users.name, 'test')});
i want to find all users where name is not null. How to do in this situation?
3 Replies
Alex.dev
Alex.dev2y ago
If I'm not mistaken there is special helper function for that. Check this out: https://orm.drizzle.team/docs/operators#isnotnull
Vonyc
VonycOP2y ago
im trying it,
await db.query.users.findFirst({where: (users, { eq }) => and(eq(users.name, 'test'), isNotNull(users.name)});
await db.query.users.findFirst({where: (users, { eq }) => and(eq(users.name, 'test'), isNotNull(users.name)});
but it still return users without name :/ may be bug?
hisam
hisam2y ago
You can try to directly pass the SQL part:
await db.query.users.findFirst({ where: and(eq(users.name, 'test'), isNotNull(users.name)) });
await db.query.users.findFirst({ where: and(eq(users.name, 'test'), isNotNull(users.name)) });
Note: I am not sure why you want to check the users.name = 'test' while also checking if the users.name is not null. The first query should be enough (since test != null)
await db.query.users.findFirst({ where: eq(users.name, "test") });
await db.query.users.findFirst({ where: eq(users.name, "test") });
Want results from more Discord servers?
Add your server