Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Startswith Operator #47

Closed
AngellusMortis opened this issue Jun 21, 2019 · 8 comments
Closed

Add Startswith Operator #47

AngellusMortis opened this issue Jun 21, 2019 · 8 comments

Comments

@AngellusMortis
Copy link

It would be great to add support for the __startswith QuerySet feature. ~ is great, but it does an icontains which completely bypasses a index on the DB. Starts with would allow us to maintain the index on a large tables for indexed fields.

@stebunovd
Copy link
Member

hey @AngellusMortis,

thank you for the idea. Sounds interesting. I wonder if this concept should be extended to full SQL like operator support, which will handle cases like "starts with" and "ends with" and more. What do you think about the possible syntax? The very first idea off the top of my head is to add like operator for strings, and keep field ~ "value" as a shorthand for field like "%value%". It's a bit verbose, but should be familiar for those who know SQL. However, maybe there could be better ideas.

thanks,

Denis

@AngellusMortis
Copy link
Author

That sounds about right. `field like "value%" would make it verbose enough to handle this use case very well. It is certainly a lot better than anything I was thinking of.

@vigneshhari
Copy link

Django has a lookup which supports starts with natively, We can simply add a new token and get it working right?

@stebunovd
Copy link
Member

the discussion above is mostly not about the implementation, but about the query language design. Yes, we could probably add another operator for "startswith". And what's next? One more operator for "endswith"? And another one for "like"?

@vigneshhari
Copy link

@stebunovd I was referring to the original issue that is "adding support for the starts with operator" I had the exact same issue and I solved it by adding a new token which seems like an easy fix if one only requires starts with operator and yes, a general operator would be better and would solve the problem in a much more efficient way.

@MilovanovM
Copy link
Member

What if we take operators from the regular expressions language? ^ for "starts with" and $ for "ends with". BTW, CSS specs uses them https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors#syntax

@stebunovd
Copy link
Member

one more idea: add full support for regular expressions by introducing a new regex operator. Such a move will cover many use cases and AFAIK regular expressions are supported natively by all major database backends

glebofff pushed a commit to glebofff/djangoql that referenced this issue May 31, 2021
glebofff pushed a commit to glebofff/djangoql that referenced this issue May 31, 2021
resolves ivelum#47

(cherry picked from commit e394f20)
@Carnagie
Copy link

Carnagie commented Nov 5, 2021

Will this issue be merged ? I am planning to implement on my own fork.

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

No branches or pull requests

5 participants