@@ -710,7 +710,7 @@ public function updateRelationship(
710710 $ collection = $ this ->getDocument (Database::METADATA , $ collection );
711711 $ relatedCollection = $ this ->getDocument (Database::METADATA , $ relatedCollection );
712712
713- $ junction = $ this ->getSQLTable ('_ ' . $ collection ->getInternalId () . '_ ' . $ relatedCollection ->getInternalId ());
713+ $ junction = $ this ->getSQLTable ('_ ' . $ collection ->getSequence () . '_ ' . $ relatedCollection ->getSequence ());
714714
715715 if (!\is_null ($ newKey )) {
716716 $ sql = "ALTER TABLE {$ junction } RENAME COLUMN \"{$ key }\" TO \"{$ newKey }\"; " ;
@@ -795,12 +795,12 @@ public function deleteRelationship(
795795 $ relatedCollection = $ this ->getDocument (Database::METADATA , $ relatedCollection );
796796
797797 $ junction = $ side === Database::RELATION_SIDE_PARENT
798- ? $ this ->getSQLTable ('_ ' . $ collection ->getInternalId () . '_ ' . $ relatedCollection ->getInternalId ())
799- : $ this ->getSQLTable ('_ ' . $ relatedCollection ->getInternalId () . '_ ' . $ collection ->getInternalId ());
798+ ? $ this ->getSQLTable ('_ ' . $ collection ->getSequence () . '_ ' . $ relatedCollection ->getSequence ())
799+ : $ this ->getSQLTable ('_ ' . $ relatedCollection ->getSequence () . '_ ' . $ collection ->getSequence ());
800800
801801 $ perms = $ side === Database::RELATION_SIDE_PARENT
802- ? $ this ->getSQLTable ('_ ' . $ collection ->getInternalId () . '_ ' . $ relatedCollection ->getInternalId () . '_perms ' )
803- : $ this ->getSQLTable ('_ ' . $ relatedCollection ->getInternalId () . '_ ' . $ collection ->getInternalId () . '_perms ' );
802+ ? $ this ->getSQLTable ('_ ' . $ collection ->getSequence () . '_ ' . $ relatedCollection ->getSequence () . '_perms ' )
803+ : $ this ->getSQLTable ('_ ' . $ relatedCollection ->getSequence () . '_ ' . $ collection ->getSequence () . '_perms ' );
804804
805805 $ sql = "DROP TABLE {$ junction }; DROP TABLE {$ perms }" ;
806806 break ;
@@ -957,7 +957,7 @@ public function createDocument(string $collection, Document $document): Document
957957 $ columnNames = '' ;
958958
959959 // Insert internal id if set
960- if (!empty ($ document ->getInternalId ())) {
960+ if (!empty ($ document ->getSequence ())) {
961961 $ bindKey = '_id ' ;
962962 $ columns .= "\"_id \", " ;
963963 $ columnNames .= ': ' . $ bindKey . ', ' ;
@@ -983,8 +983,8 @@ public function createDocument(string $collection, Document $document): Document
983983
984984 $ stmt ->bindValue (':_uid ' , $ document ->getId (), PDO ::PARAM_STR );
985985
986- if (!empty ($ document ->getInternalId ())) {
987- $ stmt ->bindValue (':_id ' , $ document ->getInternalId (), PDO ::PARAM_STR );
986+ if (!empty ($ document ->getSequence ())) {
987+ $ stmt ->bindValue (':_id ' , $ document ->getSequence (), PDO ::PARAM_STR );
988988 }
989989
990990 $ attributeIndex = 0 ;
@@ -1029,7 +1029,7 @@ public function createDocument(string $collection, Document $document): Document
10291029 try {
10301030 $ this ->execute ($ stmt );
10311031 $ lastInsertedId = $ this ->getPDO ()->lastInsertId ();
1032- // internalId can be manually as well
1032+ // Sequence can be manually set as well
10331033 $ document ['$sequence ' ] ??= $ lastInsertedId ;
10341034
10351035 if (isset ($ stmtPermissions )) {
@@ -1062,15 +1062,15 @@ public function createDocuments(string $collection, array $documents): array
10621062 $ name = $ this ->filter ($ collection );
10631063 $ attributeKeys = Database::INTERNAL_ATTRIBUTE_KEYS ;
10641064
1065- $ hasInternalId = null ;
1065+ $ hasSequence = null ;
10661066 foreach ($ documents as $ document ) {
10671067 $ attributes = $ document ->getAttributes ();
10681068 $ attributeKeys = array_merge ($ attributeKeys , array_keys ($ attributes ));
10691069
1070- if ($ hasInternalId === null ) {
1071- $ hasInternalId = !empty ($ document ->getInternalId ());
1072- } elseif ($ hasInternalId == empty ($ document ->getInternalId ())) {
1073- throw new DatabaseException ('All documents must have an internalId if one is set ' );
1070+ if ($ hasSequence === null ) {
1071+ $ hasSequence = !empty ($ document ->getSequence ());
1072+ } elseif ($ hasSequence == empty ($ document ->getSequence ())) {
1073+ throw new DatabaseException ('All documents must have an sequence if one is set ' );
10741074 }
10751075 }
10761076 $ attributeKeys = array_unique ($ attributeKeys );
@@ -1099,9 +1099,9 @@ public function createDocuments(string $collection, array $documents): array
10991099 $ attributes ['_updatedAt ' ] = $ document ->getUpdatedAt ();
11001100 $ attributes ['_permissions ' ] = \json_encode ($ document ->getPermissions ());
11011101
1102- if (!empty ($ document ->getInternalId ())) {
1102+ if (!empty ($ document ->getSequence ())) {
11031103 $ sequences [$ document ->getId ()] = true ;
1104- $ attributes ['_id ' ] = $ document ->getInternalId ();
1104+ $ attributes ['_id ' ] = $ document ->getSequence ();
11051105 $ attributeKeys [] = '_id ' ;
11061106 }
11071107
@@ -1177,7 +1177,7 @@ public function createDocuments(string $collection, array $documents): array
11771177 $ collection ,
11781178 $ document ->getId (),
11791179 [Query::select (['$sequence ' ])]
1180- )->getInternalId ();
1180+ )->getSequence ();
11811181 }
11821182 }
11831183
@@ -1352,15 +1352,15 @@ public function updateDocument(string $collection, string $id, Document $documen
13521352 $ sql = "
13531353 UPDATE {$ this ->getSQLTable ($ name )}
13541354 SET {$ columns } _uid = :_newUid
1355- WHERE _id=:_internalId
1355+ WHERE _id=:_sequence
13561356 {$ this ->getTenantQuery ($ collection )}
13571357 " ;
13581358
13591359 $ sql = $ this ->trigger (Database::EVENT_DOCUMENT_UPDATE , $ sql );
13601360
13611361 $ stmt = $ this ->getPDO ()->prepare ($ sql );
13621362
1363- $ stmt ->bindValue (':_internalId ' , $ document ->getInternalId ());
1363+ $ stmt ->bindValue (':_sequence ' , $ document ->getSequence ());
13641364 $ stmt ->bindValue (':_newUid ' , $ document ->getId ());
13651365
13661366 if ($ this ->sharedTables ) {
@@ -1555,12 +1555,12 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
15551555
15561556 // Get most dominant/first order attribute
15571557 if ($ i === 0 && !empty ($ cursor )) {
1558- $ orderMethodInternalId = Query::TYPE_GREATER ; // To preserve natural order
1558+ $ orderMethodSequence = Query::TYPE_GREATER ; // To preserve natural order
15591559 $ orderMethod = $ orderType === Database::ORDER_DESC ? Query::TYPE_LESSER : Query::TYPE_GREATER ;
15601560
15611561 if ($ cursorDirection === Database::CURSOR_BEFORE ) {
15621562 $ orderType = $ orderType === Database::ORDER_ASC ? Database::ORDER_DESC : Database::ORDER_ASC ;
1563- $ orderMethodInternalId = $ orderType === Database::ORDER_ASC ? Query::TYPE_LESSER : Query::TYPE_GREATER ;
1563+ $ orderMethodSequence = $ orderType === Database::ORDER_ASC ? Query::TYPE_LESSER : Query::TYPE_GREATER ;
15641564 $ orderMethod = $ orderType === Database::ORDER_DESC ? Query::TYPE_LESSER : Query::TYPE_GREATER ;
15651565 }
15661566
@@ -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 ['$sequence ' ]}
1581+ {$ this ->quote ($ alias )}._id {$ this ->getSQLOperator ($ orderMethodSequence )} {$ cursor ['$sequence ' ]}
15821582 )
15831583 ) " ;
15841584 } elseif ($ cursorDirection === Database::CURSOR_BEFORE ) {
@@ -1662,7 +1662,7 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
16621662 try {
16631663 $ stmt = $ this ->getPDO ()->prepare ($ sql );
16641664 foreach ($ binds as $ key => $ value ) {
1665- if ($ key === ":internalId " ) {
1665+ if ($ key === ":sequence " ) {
16661666 $ stmt ->bindValue ($ key , $ value , PDO ::PARAM_INT );
16671667 } else {
16681668 $ stmt ->bindValue ($ key , $ value , $ this ->getPDOType ($ value ));
@@ -1927,8 +1927,8 @@ protected function getSQLCondition(Query $query, array &$binds): string
19271927 default => $ value
19281928 };
19291929 if ($ attribute === $ this ->quote ("_id " )) {
1930- $ binds [":internalId " ] = $ value ;
1931- $ conditions [] = "{$ alias }. {$ attribute } {$ operator } :internalId " ;
1930+ $ binds [":sequence " ] = $ value ;
1931+ $ conditions [] = "{$ alias }. {$ attribute } {$ operator } :sequence " ;
19321932 } else {
19331933 $ binds [": {$ placeholder }_ {$ key }" ] = $ value ;
19341934 $ conditions [] = "{$ alias }. {$ attribute } {$ operator } : {$ placeholder }_ {$ key }" ;
0 commit comments