Skip to content

Commit 3e2b50b

Browse files
authored
Merge pull request #591 from ArnabChatterjee20k/dat-388-rename-internalid
updaetd $internalid to $sequence
2 parents e97cc6b + 335ae83 commit 3e2b50b

15 files changed

Lines changed: 77 additions & 77 deletions

File tree

src/Database/Adapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,12 +747,12 @@ abstract public function deleteDocument(string $collection, string $id): bool;
747747
* Delete Documents
748748
*
749749
* @param string $collection
750-
* @param array<string> $internalIds
750+
* @param array<string> $sequences
751751
* @param array<string> $permissionIds
752752
*
753753
* @return int
754754
*/
755-
abstract public function deleteDocuments(string $collection, array $internalIds, array $permissionIds): int;
755+
abstract public function deleteDocuments(string $collection, array $sequences, array $permissionIds): int;
756756

757757
/**
758758
* Find Documents

src/Database/Adapter/MariaDB.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -905,10 +905,10 @@ public function createDocument(string $collection, Document $document): Document
905905

906906
$stmt->execute();
907907

908-
$document['$internalId'] = $this->pdo->lastInsertId();
908+
$document['$sequence'] = $this->pdo->lastInsertId();
909909

910-
if (empty($document['$internalId'])) {
911-
throw new DatabaseException('Error creating document empty "$internalId"');
910+
if (empty($document['$sequence'])) {
911+
throw new DatabaseException('Error creating document empty "$sequence"');
912912
}
913913

914914
if (isset($stmtPermissions)) {
@@ -1051,15 +1051,15 @@ public function createDocuments(string $collection, array $documents): array
10511051
$stmtPermissions?->execute();
10521052
}
10531053

1054-
$internalIds = $this->getInternalIds(
1054+
$sequences = $this->getInternalIds(
10551055
$collection,
10561056
$documentIds,
10571057
$documentTenants
10581058
);
10591059

10601060
foreach ($documents as $document) {
1061-
if (isset($internalIds[$document->getId()])) {
1062-
$document['$internalId'] = $internalIds[$document->getId()];
1061+
if (isset($sequences[$document->getId()])) {
1062+
$document['$sequence'] = $sequences[$document->getId()];
10631063
}
10641064
}
10651065
} catch (PDOException $e) {
@@ -1495,15 +1495,15 @@ public function createOrUpdateDocuments(
14951495
$stmtAddPermissions->execute();
14961496
}
14971497

1498-
$internalIds = $this->getInternalIds(
1498+
$sequences = $this->getInternalIds(
14991499
$collection,
15001500
$documentIds,
15011501
$documentTenants
15021502
);
15031503

15041504
foreach ($changes as $change) {
1505-
if (isset($internalIds[$change->getNew()->getId()])) {
1506-
$change->getNew()->setAttribute('$internalId', $internalIds[$change->getNew()->getId()]);
1505+
if (isset($sequences[$change->getNew()->getId()])) {
1506+
$change->getNew()->setAttribute('$sequence', $sequences[$change->getNew()->getId()]);
15071507
}
15081508
}
15091509
} catch (PDOException $e) {
@@ -1686,7 +1686,7 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
16861686
OR (
16871687
{$this->quote($alias)}.{$this->quote($attribute)} = :cursor
16881688
AND
1689-
{$this->quote($alias)}._id {$this->getSQLOperator($orderMethodInternalId)} {$cursor['$internalId']}
1689+
{$this->quote($alias)}._id {$this->getSQLOperator($orderMethodInternalId)} {$cursor['$sequence']}
16901690
)
16911691
)";
16921692
} elseif ($cursorDirection === Database::CURSOR_BEFORE) {
@@ -1710,7 +1710,7 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
17101710
: Query::TYPE_LESSER;
17111711
}
17121712

1713-
$where[] = "({$this->quote($alias)}._id {$this->getSQLOperator($orderMethod)} {$cursor['$internalId']})";
1713+
$where[] = "({$this->quote($alias)}._id {$this->getSQLOperator($orderMethod)} {$cursor['$sequence']})";
17141714
}
17151715

17161716
// Allow order type without any order attribute, fallback to the natural order (_id)
@@ -1788,7 +1788,7 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
17881788
unset($results[$index]['_uid']);
17891789
}
17901790
if (\array_key_exists('_id', $document)) {
1791-
$results[$index]['$internalId'] = $document['_id'];
1791+
$results[$index]['$sequence'] = $document['_id'];
17921792
unset($results[$index]['_id']);
17931793
}
17941794
if (\array_key_exists('_tenant', $document)) {

src/Database/Adapter/Pool.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public function deleteDocument(string $collection, string $id): bool
255255
return $this->delegate(__FUNCTION__, \func_get_args());
256256
}
257257

258-
public function deleteDocuments(string $collection, array $internalIds, array $permissionIds): int
258+
public function deleteDocuments(string $collection, array $sequences, array $permissionIds): int
259259
{
260260
return $this->delegate(__FUNCTION__, \func_get_args());
261261
}

src/Database/Adapter/Postgres.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ public function createDocument(string $collection, Document $document): Document
10301030
$this->execute($stmt);
10311031
$lastInsertedId = $this->getPDO()->lastInsertId();
10321032
// internalId can be manually as well
1033-
$document['$internalId'] ??= $lastInsertedId;
1033+
$document['$sequence'] ??= $lastInsertedId;
10341034

10351035
if (isset($stmtPermissions)) {
10361036
$this->execute($stmtPermissions);
@@ -1085,7 +1085,7 @@ public function createDocuments(string $collection, array $documents): array
10851085
}
10861086
$columns = '(' . \implode(', ', $columns) . ')';
10871087

1088-
$internalIds = [];
1088+
$sequences = [];
10891089

10901090
$bindIndex = 0;
10911091
$batchKeys = [];
@@ -1100,7 +1100,7 @@ public function createDocuments(string $collection, array $documents): array
11001100
$attributes['_permissions'] = \json_encode($document->getPermissions());
11011101

11021102
if (!empty($document->getInternalId())) {
1103-
$internalIds[$document->getId()] = true;
1103+
$sequences[$document->getId()] = true;
11041104
$attributes['_id'] = $document->getInternalId();
11051105
$attributeKeys[] = '_id';
11061106
}
@@ -1172,11 +1172,11 @@ public function createDocuments(string $collection, array $documents): array
11721172
}
11731173

11741174
foreach ($documents as $document) {
1175-
if (!isset($internalIds[$document->getId()])) {
1176-
$document['$internalId'] = $this->getDocument(
1175+
if (!isset($sequences[$document->getId()])) {
1176+
$document['$sequence'] = $this->getDocument(
11771177
$collection,
11781178
$document->getId(),
1179-
[Query::select(['$internalId'])]
1179+
[Query::select(['$sequence'])]
11801180
)->getInternalId();
11811181
}
11821182
}
@@ -1578,7 +1578,7 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
15781578
OR (
15791579
{$this->quote($alias)}.{$this->quote($attribute)} = :cursor
15801580
AND
1581-
{$this->quote($alias)}._id {$this->getSQLOperator($orderMethodInternalId)} {$cursor['$internalId']}
1581+
{$this->quote($alias)}._id {$this->getSQLOperator($orderMethodInternalId)} {$cursor['$sequence']}
15821582
)
15831583
)";
15841584
} elseif ($cursorDirection === Database::CURSOR_BEFORE) {
@@ -1602,7 +1602,7 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
16021602
: Query::TYPE_LESSER;
16031603
}
16041604

1605-
$where[] = "({$this->quote($alias)}._id {$this->getSQLOperator($orderMethod)} {$cursor['$internalId']})";
1605+
$where[] = "({$this->quote($alias)}._id {$this->getSQLOperator($orderMethod)} {$cursor['$sequence']})";
16061606
}
16071607

16081608
// Allow order type without any order attribute, fallback to the natural order (_id)
@@ -1683,7 +1683,7 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
16831683
unset($results[$index]['_uid']);
16841684
}
16851685
if (\array_key_exists('_id', $document)) {
1686-
$results[$index]['$internalId'] = $document['_id'];
1686+
$results[$index]['$sequence'] = $document['_id'];
16871687
unset($results[$index]['_id']);
16881688
}
16891689
if (\array_key_exists('_tenant', $document)) {

src/Database/Adapter/SQL.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ public function getDocument(string $collection, string $id, array $queries = [],
367367
$document = $document[0];
368368

369369
if (\array_key_exists('_id', $document)) {
370-
$document['$internalId'] = $document['_id'];
370+
$document['$sequence'] = $document['_id'];
371371
unset($document['_id']);
372372
}
373373
if (\array_key_exists('_uid', $document)) {
@@ -441,12 +441,12 @@ public function updateDocuments(string $collection, Document $updates, array $do
441441
}
442442

443443
$name = $this->filter($collection);
444-
$internalIds = \array_map(fn ($document) => $document->getInternalId(), $documents);
444+
$sequences = \array_map(fn ($document) => $document->getInternalId(), $documents);
445445

446446
$sql = "
447447
UPDATE {$this->getSQLTable($name)}
448448
SET {$columns}
449-
WHERE _id IN (" . \implode(', ', \array_map(fn ($index) => ":_id_{$index}", \array_keys($internalIds))) . ")
449+
WHERE _id IN (" . \implode(', ', \array_map(fn ($index) => ":_id_{$index}", \array_keys($sequences))) . ")
450450
{$this->getTenantQuery($collection)}
451451
";
452452

@@ -457,7 +457,7 @@ public function updateDocuments(string $collection, Document $updates, array $do
457457
$stmt->bindValue(':_tenant', $this->tenant);
458458
}
459459

460-
foreach ($internalIds as $id => $value) {
460+
foreach ($sequences as $id => $value) {
461461
$stmt->bindValue(":_id_{$id}", $value);
462462
}
463463

@@ -640,15 +640,15 @@ public function updateDocuments(string $collection, Document $updates, array $do
640640
* Delete Documents
641641
*
642642
* @param string $collection
643-
* @param array<string> $internalIds
643+
* @param array<string> $sequences
644644
* @param array<string> $permissionIds
645645
*
646646
* @return int
647647
* @throws DatabaseException
648648
*/
649-
public function deleteDocuments(string $collection, array $internalIds, array $permissionIds): int
649+
public function deleteDocuments(string $collection, array $sequences, array $permissionIds): int
650650
{
651-
if (empty($internalIds)) {
651+
if (empty($sequences)) {
652652
return 0;
653653
}
654654

@@ -657,15 +657,15 @@ public function deleteDocuments(string $collection, array $internalIds, array $p
657657

658658
$sql = "
659659
DELETE FROM {$this->getSQLTable($name)}
660-
WHERE _id IN (" . \implode(', ', \array_map(fn ($index) => ":_id_{$index}", \array_keys($internalIds))) . ")
660+
WHERE _id IN (" . \implode(', ', \array_map(fn ($index) => ":_id_{$index}", \array_keys($sequences))) . ")
661661
{$this->getTenantQuery($collection)}
662662
";
663663

664664
$sql = $this->trigger(Database::EVENT_DOCUMENTS_DELETE, $sql);
665665

666666
$stmt = $this->getPDO()->prepare($sql);
667667

668-
foreach ($internalIds as $id => $value) {
668+
foreach ($sequences as $id => $value) {
669669
$stmt->bindValue(":_id_{$id}", $value);
670670
}
671671

@@ -718,7 +718,7 @@ public function deleteDocuments(string $collection, array $internalIds, array $p
718718
*/
719719
protected function getInternalIds(string $collection, array $documentIds, array $documentTenants = []): array
720720
{
721-
$internalIds = [];
721+
$sequences = [];
722722

723723
/**
724724
* UID, _tenant bottleneck is ~ 5000 rows since we use _uid IN query
@@ -747,10 +747,10 @@ protected function getInternalIds(string $collection, array $documentIds, array
747747
$results = $stmt->fetchAll(\PDO::FETCH_KEY_PAIR); // Fetch as [documentId => internalId]
748748
$stmt->closeCursor();
749749

750-
$internalIds = [...$internalIds, ...$results];
750+
$sequences = [...$sequences, ...$results];
751751
}
752752

753-
return $internalIds;
753+
return $sequences;
754754
}
755755

756756
/**
@@ -1692,7 +1692,7 @@ protected function getAttributeProjection(array $selections, string $prefix = ''
16921692

16931693
$internalKeys = [
16941694
'$id',
1695-
'$internalId',
1695+
'$sequence',
16961696
'$permissions',
16971697
'$createdAt',
16981698
'$updatedAt',
@@ -1721,7 +1721,7 @@ protected function getInternalKeyForAttribute(string $attribute): string
17211721
{
17221722
return match ($attribute) {
17231723
'$id' => '_uid',
1724-
'$internalId' => '_id',
1724+
'$sequence' => '_id',
17251725
'$collection' => '_collection',
17261726
'$tenant' => '_tenant',
17271727
'$createdAt' => '_createdAt',

src/Database/Adapter/SQLite.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ public function createDocument(string $collection, Document $document): Document
609609
$statment->execute();
610610
$last = $statment->fetch();
611611

612-
$document['$internalId'] = $last['id'];
612+
$document['$sequence'] = $last['id'];
613613

614614
if (isset($stmtPermissions)) {
615615
$stmtPermissions->execute();

src/Database/Database.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class Database
163163
'filters' => [],
164164
],
165165
[
166-
'$id' => '$internalId',
166+
'$id' => '$sequence',
167167
'type' => self::VAR_STRING,
168168
'size' => Database::LENGTH_KEY,
169169
'required' => true,
@@ -5788,10 +5788,10 @@ public function deleteDocuments(
57885788
break;
57895789
}
57905790

5791-
$internalIds = [];
5791+
$sequences = [];
57925792
$permissionIds = [];
57935793
foreach ($batch as $document) {
5794-
$internalIds[] = $document->getInternalId();
5794+
$sequences[] = $document->getInternalId();
57955795
if (!empty($document->getPermissions())) {
57965796
$permissionIds[] = $document->getId();
57975797
}
@@ -5815,10 +5815,10 @@ public function deleteDocuments(
58155815
}
58165816
}
58175817

5818-
$this->withTransaction(function () use ($collection, $internalIds, $permissionIds) {
5818+
$this->withTransaction(function () use ($collection, $sequences, $permissionIds) {
58195819
$this->adapter->deleteDocuments(
58205820
$collection->getId(),
5821-
$internalIds,
5821+
$sequences,
58225822
$permissionIds
58235823
);
58245824
});
@@ -6539,7 +6539,7 @@ private function validateSelections(Document $collection, array $queries): array
65396539
$selections = \array_merge($selections, $relationshipSelections);
65406540

65416541
$selections[] = '$id';
6542-
$selections[] = '$internalId';
6542+
$selections[] = '$sequence';
65436543
$selections[] = '$collection';
65446544
$selections[] = '$createdAt';
65456545
$selections[] = '$updatedAt';

src/Database/Document.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function getId(): string
6666
*/
6767
public function getInternalId(): string
6868
{
69-
return $this->getAttribute('$internalId', '');
69+
return $this->getAttribute('$sequence', '');
7070
}
7171

7272
/**

src/Database/Query.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class Query
8989
public function __construct(string $method, string $attribute = '', array $values = [])
9090
{
9191
if ($attribute === '' && \in_array($method, [Query::TYPE_ORDER_ASC, Query::TYPE_ORDER_DESC])) {
92-
$attribute = '$internalId';
92+
$attribute = '$sequence';
9393
}
9494

9595
$this->method = $method;

src/Database/Validator/Queries/Documents.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public function __construct(
3636
'array' => false,
3737
]);
3838
$attributes[] = new Document([
39-
'$id' => '$internalId',
40-
'key' => '$internalId',
39+
'$id' => '$sequence',
40+
'key' => '$sequence',
4141
'type' => Database::VAR_STRING,
4242
'array' => false,
4343
]);

0 commit comments

Comments
 (0)