-
Notifications
You must be signed in to change notification settings - Fork 554
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
Refactoring Query objects #62
Comments
Having a single class which handles all the query syntax would definitely look better than the current implementation. However I'm still not sure how the |
Probably via the generation of some BinExpr = namedtuple('BinExpr', 'operator,a,b')
User.id == 1 # => BinExpr('==', 'id', 1)
(User.id == 1) & (User.age >= 10) #=> BinExpr('and', BinExpr('==', 'id', 1), BinExpr('>=', 'age', 10)) Advantage over strings is once again, that it is less fragile and can lend itself well to really nested queries. Using this kind of generation may provide some base for some really nice optimisations via meta-compilation (which is essentially compiling a single function which handles the query without having to resort to multiple function calls, i.e., does the "big picture") in the future. |
That's a great idea! The big question now is whether we should continue to support the current syntax ( |
Make deprecation warnings first, then remove it in a 3.x release. Although I'd imagine that you probably need to do some serious |
👍 |
I've now finally found time to work on the new Query model. An implementation can be found in a211459. Notable changes include:
While using User = Query()
db.find(User.name == 'John Doe') What do you guys think about the implementation? |
According to the |
@eugene-eeo Can you explain in what way nodes should be generated? |
|
That's what I'm doing now. Only I'm using normal tuples instead of namedtuples. |
This is a proposal for a much simpler Query model that can be used, which essentially enables us to do the following, even without any advanced metaclass or inheritance magic:
Which is very SQLAlchemy-like and what one would expect, and I would say even more intuitive than the current style/model. The following is a simple implementation that only handles the very basic:
The advantages over the current style is perhaps that this is much more intuitive and simple. We don't need to have a new class for every special case. It is also simpler to generate the intermediate query expressions so that they can be cached, instead of the rather primitive or hacky string representations that we are having at the moment, which is error prone and needs us to worry about Unicode etc.
The text was updated successfully, but these errors were encountered: