Need Help: `ilike` Function Not Returning Expected Results in Drizzle ORM
Hello Drizzle ORM Community!
I'm currently working with Drizzle ORM in a TypeScript environment using PostgreSQL (specifically, Neon PostgreSQL) and I've encountered a small issue with querying user data using the
ilike
function for case-insensitive matching. I'm attempting to query tbl_users
based on partial user names, but I'm not getting the expected results.
Here's the snippet of my code where I implement the query:
I pass the query parameter as jack expecting to retrieve users with names like Jackson Kasi, but instead, I receive an empty array. According to the Drizzle ORM documentation, the ilike
should work for PostgreSQL like so:
However, my current implementation doesn't seem to function as expected. Does anyone have experience with this function or can spot what I might be doing wrong? Any suggestions on how to properly use ilike
with findMany
or corrections to my approach would be greatly appreciated!
Thank you in advance for your help!1 Reply
Hello Drizzle ORM Community!
I’ve managed to resolve the issue with the
ilike
function not returning the expected results when querying user data in a TypeScript environment with PostgreSQL. The problem was that I needed to include wildcard characters %
around the input string to correctly perform the case-insensitive partial search.
Here's the updated code snippet that fixed the issue:
Key Changes
1. Wildcard Usage: I added %
symbols around the input.query
to create searchQuery
. This modification tells PostgreSQL to look for any records where the full_name
contains the provided string, regardless of its position.
2. Tested Query: I tested this by passing 'jack' as the query parameter and successfully retrieved users with names like 'Jackson Kasi', confirming that the partial and case-insensitive search was working as expected.
This solution adheres to the ilike
function usage as described in the Drizzle ORM documentation but applies it within the context of the findMany
method, ensuring that it correctly interprets the partial search strings.
Thanks to everyone who took the time to look into this, and I hope this solution helps anyone else facing a similar issue!