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

Parsing nested #366

Merged
merged 61 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
b3e5b0e
or operator
fogelito Feb 6, 2023
f5416e4
Merge branch 'between' of github.com:utopia-php/database into test-or
fogelito Feb 6, 2023
50a6a0e
bind param error
fogelito Feb 6, 2023
c309434
Nested conditions
fogelito Feb 7, 2023
2d3e8ea
remove nesting entry
fogelito Feb 7, 2023
95b6e53
Merge branch 'main' of github.com:utopia-php/database into test-or
fogelito Feb 8, 2023
111c30d
Merge branch 'main' of github.com:utopia-php/database into test-or
fogelito Oct 15, 2023
58fe422
Query OR
fogelito Oct 15, 2023
fe25d3c
Query OR
fogelito Oct 17, 2023
252321d
Some changes
fogelito Oct 23, 2023
2829975
cleanFilters tests
fogelito Oct 24, 2023
110da1f
mongo blocker
fogelito Oct 24, 2023
b818706
Second try
fogelito Oct 24, 2023
0da0dce
Fix Mongo tests
fogelito Oct 29, 2023
46b252a
Merge branch 'main' of github.com:utopia-php/database into query-or
fogelito Oct 29, 2023
c13cba0
Merge main
fogelito Oct 29, 2023
800cf82
Remove first check
fogelito Oct 29, 2023
5f9cb97
Remove comments
fogelito Oct 29, 2023
71f7950
implode $conditions
fogelito Oct 29, 2023
2948863
Format
fogelito Oct 30, 2023
88b5f48
composer check
fogelito Oct 30, 2023
af7c5c3
remove line
fogelito Oct 30, 2023
b90da4e
Parsing Tests
fogelito Oct 30, 2023
fc3369c
Mongo mount
fogelito Oct 30, 2023
cb86bbb
Mongo mount
fogelito Oct 30, 2023
9eabf48
revert or parse
fogelito Dec 4, 2023
36c07bf
allow test
fogelito Dec 4, 2023
80ca44e
Merge branch 'main' of github.com:utopia-php/database into query-or
fogelito Dec 5, 2023
458bcf7
composer.lock
fogelito Dec 5, 2023
f64fec2
and Nested operator
fogelito Dec 5, 2023
df713f7
Formatting
fogelito Dec 5, 2023
7c27898
check formatting
fogelito Dec 5, 2023
716cc25
Support JSON query syntax
abnegate Dec 5, 2023
648376d
Format
abnegate Dec 5, 2023
19715d9
check formatting
fogelito Dec 5, 2023
a5bb36f
Remove commented test
fogelito Dec 5, 2023
f17eaac
Merge branch 'feat-json-queries' of github.com:utopia-php/database in…
fogelito Dec 5, 2023
4521313
testNested
fogelito Dec 5, 2023
7862848
LOGICAL_TYPES
fogelito Dec 6, 2023
bdd651c
getValues getValue
fogelito Dec 6, 2023
3879c4f
Merge branch 'query-or' of github.com:utopia-php/database into parsin…
fogelito Dec 6, 2023
d25040b
Fix queries
abnegate Dec 6, 2023
2d21089
Merge branch 'feat-json-queries' of github.com:utopia-php/database in…
fogelito Dec 6, 2023
a1bf3a5
Remove test
fogelito Dec 6, 2023
9e66f84
Formatting
fogelito Dec 6, 2023
22175c2
addressing comments
fogelito Dec 6, 2023
f3ec6f0
composer.lock
fogelito Dec 6, 2023
17fc376
isNested
fogelito Dec 6, 2023
e0629ad
Or query parsing
fogelito Dec 7, 2023
45bfcc8
parse as a sting
fogelito Dec 7, 2023
7e3de8e
Query test changes
fogelito Dec 7, 2023
dde90b4
Update src/Database/Adapter/SQL.php
fogelito Dec 13, 2023
4838d56
Update src/Database/Validator/Query/Filter.php
fogelito Dec 13, 2023
8099784
Address comments
fogelito Dec 13, 2023
3fd8253
Merge remote-tracking branch 'origin/parsing-nested' into parsing-nested
fogelito Dec 13, 2023
769487f
Merge branch 'main' of github.com:utopia-php/database into parsing-ne…
fogelito Dec 13, 2023
966194a
Fix more test
fogelito Dec 13, 2023
8f2a52a
Fix toArray + tests
fogelito Dec 14, 2023
10b1071
Fix toArray + tests
fogelito Dec 14, 2023
96b3eae
unit
fogelito Dec 14, 2023
1f10807
Only allow strings for search queries
abnegate Dec 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 36 additions & 36 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 19 additions & 11 deletions src/Database/Adapter/MariaDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -1580,14 +1580,11 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
}
}

foreach ($queries as $query) {
if ($query->getMethod() === Query::TYPE_SELECT) {
continue;
}
$where[] = $this->getSQLCondition($query);
$conditions = $this->getSQLConditions($queries);
if(!empty($conditions)) {
$where[] = $conditions;
}


if (Authorization::$status) {
$where[] = $this->getSQLPermissionsCondition($name, $roles);
}
Expand Down Expand Up @@ -1709,8 +1706,9 @@ public function count(string $collection, array $queries = [], ?int $max = null)
$where = [];
$limit = \is_null($max) ? '' : 'LIMIT :max';

foreach ($queries as $query) {
$where[] = $this->getSQLCondition($query);
$conditions = $this->getSQLConditions($queries);
if(!empty($conditions)) {
$where[] = $conditions;
}

if (Authorization::$status) {
Expand Down Expand Up @@ -1880,7 +1878,7 @@ protected function getAttributeProjection(array $selections, string $prefix = ''
return \implode(', ', $selections);
}

/*
/**
* Get SQL Condition
*
* @param Query $query
Expand All @@ -1902,6 +1900,17 @@ protected function getSQLCondition(Query $query): string
$placeholder = $this->getSQLPlaceholder($query);

switch ($query->getMethod()) {
case Query::TYPE_OR:
case Query::TYPE_AND:
$conditions = [];
/* @var $q Query */
foreach ($query->getValue() as $q) {
$conditions[] = $this->getSQLCondition($q);
}

$method = strtoupper($query->getMethod());
return empty($conditions) ? '' : ' '. $method .' (' . implode(' AND ', $conditions) . ')';

case Query::TYPE_SEARCH:
return "MATCH(table_main.{$attribute}) AGAINST (:{$placeholder}_0 IN BOOLEAN MODE)";

Expand All @@ -1917,8 +1926,7 @@ protected function getSQLCondition(Query $query): string
foreach ($query->getValues() as $key => $value) {
$conditions[] = $attribute . ' ' . $this->getSQLOperator($query->getMethod()) . ' :' . $placeholder . '_' . $key;
}
$condition = implode(' OR ', $conditions);
return empty($condition) ? '' : '(' . $condition . ')';
return empty($conditions) ? '' : '(' . implode(' OR ', $conditions) . ')';
}
}

Expand Down
Loading