Is there a smarter way to use optional query values

let newParentFolderId: string | undefined = getValue();

return db.query.imageFiles
.findFirst({
where: newParentFolderId ? eq(imageFiles.parentFolderId, newParentFolderId) : isNull(imageFiles.parentFolderId)
})
.execute();
let newParentFolderId: string | undefined = getValue();

return db.query.imageFiles
.findFirst({
where: newParentFolderId ? eq(imageFiles.parentFolderId, newParentFolderId) : isNull(imageFiles.parentFolderId)
})
.execute();
is there a cleaner way to not have to do things this way?
4 Replies
jakeleventhal
jakeleventhalOP12mo ago
bump
nk
nk12mo ago
@jakeleventhal Just replace isNull with "undefined" ? Oh, nvm, I don't think there's a better way to do it
Angelelz
Angelelz12mo ago
That looks good to me, not sure what you by smarter
jakeleventhal
jakeleventhalOP12mo ago
i guess it would be nicer to have an eq operator that accepts stirng | null
Want results from more Discord servers?
Add your server