Skip to content

Add like and ilike#146

Merged
ocharles merged 6 commits intomasterfrom
like
Jan 31, 2022
Merged

Add like and ilike#146
ocharles merged 6 commits intomasterfrom
like

Conversation

@ocharles
Copy link
Copy Markdown
Contributor

@ocharles ocharles commented Dec 8, 2021

I couldn't quite decide the right home for these operators, but have gone for Rel8.Expr.Text in the end. As they are standard SQL operators, I've also re-exported like and ilike from Rel8.

Fixes #144.

@ocharles
Copy link
Copy Markdown
Contributor Author

We discussed this and agreed to flip the order of arguments. I'll do that, and add a comment explaining why (it's better for currying)

@bitc
Copy link
Copy Markdown

bitc commented Jan 6, 2022

Something that always bothers me about every ORM I've used is that LIKE/ILIKE take the pattern as type Text.

This always ends up with code that looks like:

productDescription `ilike` ("%" <> searchRequest <> "%")

This is incorrect, because when a user searches for "100% Natural" they now get weird unexpected results. You could almost call this a form of SQL injection!

I think the better approach is to introduce a type called TextPattern or something, that allows safe construction of LIKE/ILIKE patterns (doing proper escaping behind the scenes).

Then the user code would look something like this:

productDescription `ilike` (wildCardMulti <> textFragment searchRequest <> wildCardMulti)

Figuring out how to make this work with dynamic "searchRequest" strings (from the database) might be tricky, but I think is possible

@ocharles ocharles enabled auto-merge (squash) January 31, 2022 11:50
@ocharles ocharles merged commit 5064673 into master Jan 31, 2022
@ocharles ocharles deleted the like branch January 31, 2022 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LIKE and ILIKE

3 participants