Skip to content
Open

Joins #763

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
156 commits
Select commit Hold shift + click to select a range
13beed1
joins
fogelito Oct 11, 2024
966631b
query test
fogelito Oct 14, 2024
8004014
Add constructor params
fogelito Oct 28, 2024
c7af565
Join validator
fogelito Oct 28, 2024
a87eed3
Init V2 validators
fogelito Oct 29, 2024
93d414e
validate values
fogelito Oct 30, 2024
35f73e6
Revert Documents validator
fogelito Oct 31, 2024
fc83d9b
Limit Offset validators
fogelito Oct 31, 2024
c5c8010
Merge branch 'main' of github.com:utopia-php/database into joins2
fogelito Feb 17, 2025
f4bddd4
formatting
fogelito Feb 17, 2025
9c85f4e
formatting
fogelito Feb 17, 2025
f99eba7
Validations
fogelito Feb 17, 2025
3c6101f
Validations
fogelito Feb 17, 2025
6276e3b
Context class
fogelito Feb 18, 2025
e7a56b5
Use add context
fogelito Feb 18, 2025
558820b
Add default alias
fogelito Feb 19, 2025
778d8da
Add Join types
fogelito Feb 20, 2025
4a1c539
Init join validation
fogelito Feb 20, 2025
f200707
Use original validator offset limit cursor
fogelito Feb 23, 2025
3ca3335
validate fulltext index
fogelito Feb 23, 2025
ab49c0d
formatting
fogelito Feb 23, 2025
c44bee5
Break groupByType
fogelito Feb 23, 2025
7bc1fe9
Introduce selection query
fogelito Feb 24, 2025
608e5ec
Add Query scope test
fogelito Feb 24, 2025
a0ca81d
Get cursor queries
fogelito Feb 25, 2025
ad0c884
Add $context to Adapter.php
fogelito Feb 25, 2025
601db10
formatting
fogelito Feb 25, 2025
2de99c0
Try new signature
fogelito Feb 26, 2025
c2a4ba1
Add Query alias
fogelito Feb 26, 2025
ba65745
Test Ambiguous alias
fogelito Feb 27, 2025
6bde5ab
Alias validator
fogelito Feb 27, 2025
f41ee35
Binds on the fly
fogelito Mar 2, 2025
67f1bbb
Use generic tenant function
fogelito Mar 2, 2025
1fff442
Add quote function
fogelito Mar 3, 2025
5a21d10
getInternalKeyForAttribute function
fogelito Mar 3, 2025
0d0f591
formatting
fogelito Mar 3, 2025
e38cfcc
Fix right Attribute internals
fogelito Mar 3, 2025
71a45b1
Test relation query exist
fogelito Mar 3, 2025
8c882dc
Test permissions
fogelito Mar 4, 2025
a965c71
Remove getSQLPlaceholder method
fogelito Mar 4, 2025
026ec5e
Some cursor work
fogelito Mar 4, 2025
a7f9a2d
order / cursor
fogelito Mar 4, 2025
22c108d
move find to sql.php
fogelito Mar 5, 2025
8caa65f
Postgres tests
fogelito Mar 5, 2025
93e7265
Test order by
fogelito Mar 5, 2025
bd4387a
Test order by
fogelito Mar 5, 2025
785e0c1
Fix query nesting
fogelito Mar 6, 2025
bf293fc
Remove bindConditionValue
fogelito Mar 6, 2025
1f1ea34
Remove getSQLPlaceholder
fogelito Mar 6, 2025
ccbb984
Remove groupByType
fogelito Mar 9, 2025
f807737
add groupByType for later trace
fogelito Mar 9, 2025
651a24c
removeByType
fogelito Mar 9, 2025
7d0fe4f
remove comments
fogelito Mar 9, 2025
55e752c
Update sum N count to use convertQueries
fogelito Mar 10, 2025
1de5d05
formatting
fogelito Mar 10, 2025
345b251
formatting
fogelito Mar 11, 2025
ab07713
Unit tests
fogelito Mar 11, 2025
9421014
Unit tests
fogelito Mar 11, 2025
daa635b
remove var_dump
fogelito Mar 11, 2025
c15a69b
skipAuth
fogelito Mar 14, 2025
f5e717e
Merge branch 'main' of github.com:utopia-php/database into joins2
fogelito Apr 21, 2025
30d8f87
default alias
fogelito Apr 21, 2025
0f3e6a9
Use order fallback N update postgres
fogelito Apr 21, 2025
6649bd9
merge conflicts
fogelito Apr 21, 2025
7e837ca
Fix Authorization when disabled
fogelito Apr 21, 2025
311555c
Init selects
fogelito Apr 22, 2025
1346015
DecodeV2
fogelito Apr 23, 2025
fd05e50
Remove internal attributes not queried
fogelito Apr 23, 2025
7fea0b3
Remove internal attributes not queried
fogelito Apr 23, 2025
ce0bf8f
Remove select duplications fix $collection issue
fogelito Apr 24, 2025
0ef44d8
Fix select queries
fogelito Apr 24, 2025
40b9aae
Selects
fogelito Apr 27, 2025
3c4db4a
Remove auth set false
fogelito Apr 27, 2025
a681979
Fix deleteDocuments
fogelito Apr 27, 2025
e18746a
Fix Postgres.php
fogelito Apr 27, 2025
dfd5c3c
Fix decoding
fogelito Apr 28, 2025
2e0cd91
Joins tests
fogelito Apr 29, 2025
7d99f75
order by message
fogelito Apr 29, 2025
ffb9ea4
casting
fogelito May 4, 2025
3770ab0
Decode Casting
fogelito May 5, 2025
4586145
decode
fogelito May 8, 2025
9d91078
sync changes
fogelito May 8, 2025
31c25ab
Remove skipAuth auth
fogelito May 11, 2025
bf4219b
Merge branch 'main' of github.com:utopia-php/database into joins2
fogelito May 12, 2025
106da41
Pull main
fogelito May 12, 2025
2f2a64a
Unit tests
fogelito May 13, 2025
735e0d3
Comment ambiguous
fogelito May 15, 2025
c854fdd
Test as test
fogelito May 15, 2025
d4e85d8
As tests
fogelito May 18, 2025
0a1faa1
As tests
fogelito May 19, 2025
d2796e4
Revert lock
fogelito May 19, 2025
1cc6d6c
Change name
fogelito May 20, 2025
45d8e25
Fix permissions
fogelito May 21, 2025
b438259
Add getLimitQueries
fogelito May 21, 2025
ba58a25
getOffsetQueries
fogelito May 21, 2025
e099596
addSelect method
fogelito May 25, 2025
321e468
select internal attributes
fogelito May 25, 2025
70a4b5c
assertArrayHasKey $collection
fogelito May 26, 2025
16c822e
addHiddenAttribute
fogelito Jun 8, 2025
02d269d
addHiddenAttribute
fogelito Jun 11, 2025
f7ae73c
Update Cursor logic
fogelito Jul 6, 2025
cb814c1
Check isset
fogelito Jul 6, 2025
a9032c6
Merge branch 'main' of github.com:utopia-php/database into joins3
fogelito Sep 2, 2025
a427a45
Query tests
fogelito Sep 2, 2025
8f688ae
Special validations
fogelito Sep 3, 2025
747dce3
Sync
fogelito Sep 3, 2025
eb51766
Dbg
fogelito Sep 3, 2025
8f563d7
decode
fogelito Sep 3, 2025
953afd3
Fix decode
fogelito Sep 4, 2025
4c39033
Attr tests check perms
fogelito Sep 4, 2025
4d4caf6
Change $internalid
fogelito Sep 4, 2025
32aa3f9
perms
fogelito Sep 4, 2025
22f92e3
perms
fogelito Sep 4, 2025
dcb4263
$permissions
fogelito Sep 7, 2025
c418511
Fix convert queries
fogelito Sep 7, 2025
f51ca0f
tests
fogelito Sep 7, 2025
f42c411
tests
fogelito Sep 7, 2025
dd15243
processRelationshipQueries
fogelito Sep 7, 2025
d0d0e10
dbg
fogelito Sep 7, 2025
679c278
process Relationship Queries
fogelito Sep 8, 2025
7085327
RelationshipTests
fogelito Sep 8, 2025
39d6689
Spatial
fogelito Sep 9, 2025
2ba2962
Spatial
fogelito Sep 9, 2025
ea48ad9
Merge branch 'main' of github.com:utopia-php/database into joins4
fogelito Sep 28, 2025
cad5e4d
Fix Documents tests
fogelito Sep 28, 2025
229905c
Fix tests
fogelito Sep 28, 2025
e2464b2
Merge branch 'main' of github.com:utopia-php/database into joins5
fogelito Sep 30, 2025
93fab9c
Spatials validations
fogelito Sep 30, 2025
c7220b1
Spatials tests
fogelito Oct 12, 2025
0c3377d
Merge branch 'main' of github.com:utopia-php/database into joins6
fogelito Oct 12, 2025
162b349
Pull main
fogelito Oct 12, 2025
b931486
$queriesOrNull
fogelito Oct 12, 2025
97ea8e0
DocumentTests
fogelito Oct 12, 2025
926a9bc
fix parse queries
fogelito Nov 9, 2025
98481c4
Merge branch 'main' of github.com:utopia-php/database into joins7
fogelito Nov 9, 2025
480ee8e
Fix syntax
fogelito Nov 9, 2025
f3948c3
Cast after
fogelito Nov 9, 2025
9e452e0
Fixe Tests
fogelito Nov 12, 2025
ae290f7
Fix tests
fogelito Nov 16, 2025
3382681
Fix tests Mongo
fogelito Nov 16, 2025
8882ab9
formatting
fogelito Nov 16, 2025
5469b7a
formatting
fogelito Nov 16, 2025
be4ee60
Mongo tests
fogelito Nov 17, 2025
1a24c9b
Update Message
fogelito Nov 17, 2025
6ef75b3
Merge branch 'main' of github.com:utopia-php/database into joins8
fogelito Nov 19, 2025
79eb87c
Fix tests
fogelito Nov 20, 2025
19656f9
Fix tests
fogelito Nov 20, 2025
9dcd729
Validate getDocument only selects
fogelito Nov 20, 2025
77d7d86
Remove dbg
fogelito Nov 20, 2025
ccb62c0
php stan
fogelito Nov 20, 2025
214f113
Filter tests
fogelito Nov 20, 2025
acfca83
Fix unit tests
fogelito Nov 23, 2025
e0e68ef
Unit tests
fogelito Nov 23, 2025
f6511fe
Serverless
fogelito Nov 23, 2025
18aceea
coderabbit
fogelito Nov 23, 2025
f6247b5
formatting
fogelito Nov 23, 2025
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
30 changes: 17 additions & 13 deletions composer.lock

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

4 changes: 2 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<phpunit
<phpunit
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
Expand All @@ -7,7 +7,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
stopOnFailure="true"
>
<testsuites>
<testsuite name="unit">
Expand Down
55 changes: 22 additions & 33 deletions src/Database/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -812,18 +812,33 @@ abstract public function deleteDocuments(string $collection, array $sequences, a
*
* Find data sets using chosen queries
*
* @param Document $collection
* @param array<Query> $queries
* @param QueryContext $context
* @param int|null $limit
* @param int|null $offset
* @param array<string> $orderAttributes
* @param array<string> $orderTypes
* @param array<string, mixed> $cursor
* @param string $cursorDirection
* @param string $forPermission
* @param array<Query> $selects
* @param array<Query> $filters
* @param array<Query> $joins
* @param array<Query> $vectors
* @param array<Query> $orderQueries
*
* @return array<Document>
*/
abstract public function find(Document $collection, array $queries = [], ?int $limit = 25, ?int $offset = null, array $orderAttributes = [], array $orderTypes = [], array $cursor = [], string $cursorDirection = Database::CURSOR_AFTER, string $forPermission = Database::PERMISSION_READ): array;
abstract public function find(
QueryContext $context,
?int $limit = 25,
?int $offset = null,
array $cursor = [],
string $cursorDirection = Database::CURSOR_AFTER,
string $forPermission = Database::PERMISSION_READ,
array $selects = [],
array $filters = [],
array $joins = [],
array $vectors = [],
array $orderQueries = []
): array;

/**
* Sum an attribute
Expand Down Expand Up @@ -1229,36 +1244,10 @@ abstract public function getAttributeWidth(Document $collection): int;
abstract public function getKeywords(): array;

/**
* Get an attribute projection given a list of selected attributes
*
* @param array<string> $selections
* @param string $prefix
* @param array<Query> $selects
* @return mixed
*/
abstract protected function getAttributeProjection(array $selections, string $prefix): mixed;

/**
* Get all selected attributes from queries
*
* @param Query[] $queries
* @return string[]
*/
protected function getAttributeSelections(array $queries): array
{
$selections = [];

foreach ($queries as $query) {
switch ($query->getMethod()) {
case Query::TYPE_SELECT:
foreach ($query->getValues() as $value) {
$selections[] = $value;
}
break;
}
}

return $selections;
}
abstract protected function getAttributeProjection(array $selects): mixed;

/**
* Filter Keys
Expand Down
11 changes: 10 additions & 1 deletion src/Database/Adapter/MariaDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -1545,11 +1545,14 @@ protected function handleSpatialQueries(Query $query, array &$binds, string $att
protected function getSQLCondition(Query $query, array &$binds): string
{
$query->setAttribute($this->getInternalKeyForAttribute($query->getAttribute()));
$query->setAttributeRight($this->getInternalKeyForAttribute($query->getAttributeRight()));

$attribute = $query->getAttribute();
$attribute = $this->filter($attribute);
$attribute = $this->quote($attribute);
$alias = $this->quote(Query::DEFAULT_ALIAS);
$alias = $query->getAlias();
$alias = $this->filter($alias);
$alias = $this->quote($alias);
$placeholder = ID::unique();

if ($query->isSpatialAttribute()) {
Expand Down Expand Up @@ -1591,6 +1594,12 @@ protected function getSQLCondition(Query $query, array &$binds): string

return "{$alias}.{$attribute} NOT BETWEEN :{$placeholder}_0 AND :{$placeholder}_1";

case Query::TYPE_RELATION_EQUAL:
$attributeRight = $this->quote($this->filter($query->getAttributeRight()));
$aliasRight = $this->quote($this->filter($query->getRightAlias()));

return "{$alias}.{$attribute}={$aliasRight}.{$attributeRight}";

case Query::TYPE_IS_NULL:
case Query::TYPE_IS_NOT_NULL:

Expand Down
Loading