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

Adding regex support for (sub)commands #116

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

david-kn
Copy link

Hi, I just quickly drafted a possible solution for regex matching in (sub)commands which could address issue #115 .

I'm not that familiar with django + their queries and as well this might not be the best possible approach but the logic and sense is incorporated to kick this off ...

Any opinions or comments are welcomed :-)

Comment on lines +24 to +30
results = []
for row in records:
if row.subcommand == "*": # skip as it is not a valid regex expression and would raise exception
continue
if re.match(row.subcommand, value):
results.append(row.subcommand)
return results
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm definitely a bit concerned about potential performance impact of this design. It should be possible to do this as an actual DB query, rather than querying for all() and then iterating through the results, though from some quick Googling it looks like custom SQL might be needed to make that possible...

Copy link
Author

@david-kn david-kn Feb 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HI Matthew, thanks for your response and I understand this concern and agree with it.

I'm not familiar with with your code base and didn't want to dig to deep to explore (and reinvent the wheel) the best possible way to interconnect your Django with queries / SQL queries. I rather wanted to kick off this initiative and show that however this might be not that elegant, the update wouldn't have to be extensive to add this neat feature.

Probably some .raw() method to run directly SQL query could help with this (?) as I don't think that django libs would allow such a query. On the other hand, don't you mind writing and mixing SQL queries into your otherwise python code?

On the other hand, amount of these records should be always very limited so the performance should have not been really impacted? But I totally understand and agree that this (performance) aspect as well as conceptual perspective should be always considered and questioned.

I'd leave the final approach to you as your team is in owner/maintainer role :-)

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.

2 participants