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

Feat: Query gen 2(.1) #157

Merged
merged 25 commits into from
Aug 14, 2022
Merged

Feat: Query gen 2(.1) #157

merged 25 commits into from
Aug 14, 2022

Conversation

Meldiron
Copy link
Contributor

@Meldiron Meldiron commented Jul 22, 2022

Previous PR: #153

TODO after this PR:

  • Remove parameters from find() (such as limit, offset, order, cursor, ...) and get it from $queries instead
  • Upgrade Appwrite to new method signatures
  • Implement new queries into Appwrite Database service
  • Update Appwrite list endpoints so they all allow queries

src/Database/QueryV1.php Outdated Show resolved Hide resolved
src/Database/QueryV1.php Outdated Show resolved Hide resolved
src/Database/QueryV1.php Outdated Show resolved Hide resolved
*/
public function __construct(string $attribute, string $operator, array $values)
public function __construct(string $method, array $params)
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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;

Copy link
Contributor Author

@Meldiron Meldiron Jul 24, 2022

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)

Copy link
Member

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.

Copy link
Contributor

@TorstenDittmann TorstenDittmann Jul 25, 2022

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.

tests/Database/Benchmark/QueryBench.php Outdated Show resolved Hide resolved
src/Database/Query.php Outdated Show resolved Hide resolved
src/Database/Query.php Outdated Show resolved Hide resolved
Copy link
Contributor

@stnguyen90 stnguyen90 left a comment

Choose a reason for hiding this comment

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

query parsing LGTM

This was referenced Aug 8, 2022
@eldadfux eldadfux merged commit 34e492b into main Aug 14, 2022
@abnegate abnegate deleted the feat-query-gen-2.1 branch November 23, 2023 01:50
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.

4 participants