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.3 #163

Merged
merged 31 commits into from
Aug 14, 2022
Merged

Feat query gen 2.3 #163

merged 31 commits into from
Aug 14, 2022

Conversation

stnguyen90
Copy link
Contributor

@stnguyen90 stnguyen90 commented Aug 9, 2022

Based on previous feedback:

This PR updates the Query class to be used like:

// signature of constructor is (string $method, string $attribute = '', array $values = [])
$query = new Query('equal', 'actors', ['Brad Pitt', 'Johnny Depp']);

$this->assertEquals('equal', $query->getMethod());
$this->assertEquals('actors', $query->getAttribute());
$this->assertEquals('Brad Pitt', $query->getValues()[0]);

// other examples
$query = new Query('lessThan', 'score', [10]);
$query = new Query('orderDesc', 'score');
$query = new Query('limit', values: [10]);

// static helper methods
$query = Query::equal('title', ['Iron Man']); // accepts array
$query = Query::greaterThan('score', 10); // value is not array
$query = Query::search('search', 'John Doe'); // also not array
$query = Query::orderAsc('score');
$query = Query::orderDesc(''); // empty string to sort on natural order
$query = Query::limit(10);
$query = Query::cursorAfter($cursorDocument); // takes a Document
$query = Query::contains('arrayAttribute', [1, 2, 3]); // accepts array

Update parsing of queries to be like:

$query = Query::parse('equal("actors", ["Brad Pitt", "Johnny Depp"])');

$this->assertEquals('equal', $query->getMethod());
$this->assertEquals('actors', $query->getAttribute());
$this->assertEquals("Brad Pitt", $query->getValues()[0]);
$this->assertEquals("Johnny Depp", $query->getValues()[1]);

$query = Query::parse('equal("actors", "Brad Pitt")');

$this->assertEquals('equal', $query->getMethod());
$this->assertEquals('actors', $query->getAttribute());
$this->assertEquals("Brad Pitt", $query->getValues()[0]);

In addition, this PR updates the Database find methods to only use queries (the Adapter's find method remains the same).

Finally, this PR also updates the Queries Validator to validate limit, offset, cursor, and order queries.

@stnguyen90 stnguyen90 self-assigned this Aug 9, 2022
@stnguyen90 stnguyen90 marked this pull request as draft August 9, 2022 23:16
@stnguyen90 stnguyen90 marked this pull request as ready for review August 11, 2022 04:36
@stnguyen90 stnguyen90 requested a review from fogelito August 11, 2022 12:43
src/Database/Database.php Outdated Show resolved Hide resolved
src/Database/Validator/Queries.php Outdated Show resolved Hide resolved
src/Database/Validator/QueryValidator.php Outdated Show resolved Hide resolved
src/Database/Validator/QueryValidator.php Outdated Show resolved Hide resolved
@stnguyen90 stnguyen90 requested a review from eldadfux August 11, 2022 19:17
@stnguyen90 stnguyen90 requested a review from fogelito August 11, 2022 20:51
@stnguyen90 stnguyen90 force-pushed the feat-query-gen-2.3 branch 2 times, most recently from ab84f65 to 6dd00dd Compare August 12, 2022 21:12
Copy link
Member

@eldadfux eldadfux left a comment

Choose a reason for hiding this comment

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

Added a few comments, I think we should be close to a merge :)

src/Database/Validator/Queries.php Outdated Show resolved Hide resolved
src/Database/Database.php Outdated Show resolved Hide resolved
src/Database/Validator/Queries.php Outdated Show resolved Hide resolved
src/Database/Validator/Query.php Outdated Show resolved Hide resolved
src/Database/Validator/Queries.php Outdated Show resolved Hide resolved
src/Database/Validator/Queries.php Show resolved Hide resolved
src/Database/Validator/Query.php Outdated Show resolved Hide resolved
@stnguyen90 stnguyen90 requested a review from eldadfux August 13, 2022 22:28
src/Database/Validator/Queries.php Show resolved Hide resolved
src/Database/Validator/Queries.php Outdated Show resolved Hide resolved
Query matches the naming convention of the other validators. We can use aliasing
whenever any conflict arises with Utopia\Database\Query.
@stnguyen90 stnguyen90 requested a review from eldadfux August 14, 2022 08:07
@eldadfux eldadfux merged commit 5aa3513 into main Aug 14, 2022
@stnguyen90 stnguyen90 deleted the feat-query-gen-2.3 branch August 15, 2022 02:15
@stnguyen90 stnguyen90 restored the feat-query-gen-2.3 branch August 15, 2022 02:20
@stnguyen90 stnguyen90 mentioned this pull request Sep 22, 2022
5 tasks
@stnguyen90 stnguyen90 deleted the feat-query-gen-2.3 branch March 23, 2023 23:54
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.

6 participants