-
Notifications
You must be signed in to change notification settings - Fork 48
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
Feat: Query gen 2(.1) #157
Conversation
…at-query-gen-2.1
Feat: Improved performance
*/ | ||
public function __construct(string $attribute, string $operator, array $values) | ||
public function __construct(string $method, array $params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new signature API for the class feels a bit like a patch, why did we move away from the original signature? I think we could have improved it, but this is a step back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We removed operator
. In equals('name', 'Matej')
all is good, but in a query like limit(5)
we don't have an operator.
attribute
was also removed, since that is also not present in limit(5)
.
We added method
which replaced attribute
in the placement of the query. A method is for example equals
, limit
, or offset
.
I can see what you mean with a step back. I was thinking about implementing separate interfaces(classes?) for each method. That would give you more high-level of building a query. Would that make sense?
*/ | ||
public function getQuery(): array | ||
public function setFirstParam(string $value): self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The API of the class feels very oriented towards the technical implementation instead of telling the story of the use case for this class and method. I think, getAttribute
, getMethod
, and getValues
would make much more sense and be more intuitive when reading the code.
We could have also introduce static builder methods for this class that would make the API closer to what we have in our Appwrite SDK (not meaning they should be coupled, but they just feel more convenient). For example:
Query::equal(string $attribute, array $values):self;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to avoid calling it getMethod
since you can still call it on limit(5)
and there you would get 5
as method. Tho, I am opened for suggestions. Should I rename them to original methods?
We can introduce it, yes. That's what I though about in this comment: #157 (comment)
I can see what you mean with a step back. I was thinking about implementing separate interfaces(classes?) for each method. That would give you more high-level of building a query. Would that make sense?
If you give me green, I can go ahead and implement it as static method. (as you suggested in this comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that with the builder/factory static methods in place we could just set attribute to null, and have proper access methods in place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to have multiple Query Classes, since they are really hard to mix in combination with Validators.
- The Equal query has stuff like attribute and values (any data type)
- The Limit query has only a single value which is int
- The Offset query has only a single value which is int
- The Order Query has only a single values which are string (maybe even multiple values if we don't want the user to pass multiple orders in the same Query)
- ...
I am not sure if we can get an interface that makes sense for all. So what about a Base class, extending it for necessary Queries. Otherwise we will have so many conditions for validating everything scattered around the one class for Query and Validator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
query parsing LGTM
Previous PR: #153
TODO after this PR:
find()
(such as limit, offset, order, cursor, ...) and get it from $queries insteadlist
endpoints so they all allow queries