@@ -1724,15 +1724,6 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
17241724
17251725 $ queries = array_map (fn ($ query ) => clone $ query , $ queries );
17261726
1727- // $orderAttributes = \array_map(fn ($orderAttribute) => match ($orderAttribute) {
1728- // '$id' => '_uid',
1729- // '$internalId' => '_id',
1730- // '$tenant' => '_tenant',
1731- // '$createdAt' => '_createdAt',
1732- // '$updatedAt' => '_updatedAt',
1733- // default => $orderAttribute
1734- // }, $orderAttributes);
1735-
17361727 $ hasIdAttribute = false ;
17371728 foreach ($ orderAttributes as $ i => $ attribute ) {
17381729 $ originalAttribute = $ attribute ;
@@ -1763,11 +1754,11 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
17631754 $ binds [':cursor ' ] = $ cursor [$ originalAttribute ];
17641755
17651756 $ where [] = "(
1766- {$ this -> quote ( $ defaultAlias) }. {$ this ->quote ($ attribute )} {$ this ->getSQLOperator ($ orderMethod )} :cursor
1757+ {$ defaultAlias }. {$ this ->quote ($ attribute )} {$ this ->getSQLOperator ($ orderMethod )} :cursor
17671758 OR (
1768- {$ this -> quote ( $ defaultAlias) }. {$ this ->quote ($ attribute )} = :cursor
1759+ {$ defaultAlias }. {$ this ->quote ($ attribute )} = :cursor
17691760 AND
1770- {$ this -> quote ( $ defaultAlias) }._id {$ this ->getSQLOperator ($ orderMethodInternalId )} {$ cursor ['$internalId ' ]}
1761+ {$ defaultAlias }._id {$ this ->getSQLOperator ($ orderMethodInternalId )} {$ cursor ['$internalId ' ]}
17711762 )
17721763 ) " ;
17731764 } elseif ($ cursorDirection === Database::CURSOR_BEFORE ) {
@@ -1791,7 +1782,7 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
17911782 : Query::TYPE_LESSER ;
17921783 }
17931784
1794- $ where [] = "( {$ this -> quote ( $ defaultAlias)} . { $ this -> quote ( ' _id ' )} {$ this ->getSQLOperator ($ orderMethod )} {$ cursor ['$internalId ' ]}) " ;
1785+ $ where [] = "( {$ defaultAlias} . _id {$ this ->getSQLOperator ($ orderMethod )} {$ cursor ['$internalId ' ]}) " ;
17951786 }
17961787
17971788 // Allow order type without any order attribute, fallback to the natural order (_id)
@@ -1802,9 +1793,9 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
18021793 $ order = $ order === Database::ORDER_ASC ? Database::ORDER_DESC : Database::ORDER_ASC ;
18031794 }
18041795
1805- $ orders [] = "{$ this -> quote ( $ defaultAlias)} . { $ this -> quote ( ' _id ' )} " .$ this ->filter ($ order );
1796+ $ orders [] = "{$ defaultAlias} . _id " .$ this ->filter ($ order );
18061797 } else {
1807- $ orders [] = "{ $ this -> quote ( $ defaultAlias)} . { $ this -> quote ( ' _id ' )} " . ($ cursorDirection === Database::CURSOR_AFTER ? Database::ORDER_ASC : Database::ORDER_DESC ); // Enforce last ORDER by '_id'
1798+ $ orders [] = "$ defaultAlias. _id " . ($ cursorDirection === Database::CURSOR_AFTER ? Database::ORDER_ASC : Database::ORDER_DESC ); // Enforce last ORDER by '_id'
18081799 }
18091800 }
18101801
@@ -2018,8 +2009,8 @@ public function sum(string $collection, string $attribute, array $queries = [],
20182009 : '' ;
20192010
20202011 $ sql = "
2021- SELECT SUM( {$ attribute }) as sum FROM (
2022- SELECT {$ attribute }
2012+ SELECT SUM( {$ this -> quote ( $ attribute) }) as sum FROM (
2013+ SELECT {$ this -> quote ( $ attribute) }
20232014 FROM {$ this ->getSQLTable ($ name )} AS {$ defaultAlias }
20242015 {$ sqlWhere }
20252016 {$ limit }
@@ -2045,55 +2036,6 @@ public function sum(string $collection, string $attribute, array $queries = [],
20452036 return $ result ['sum ' ] ?? 0 ;
20462037 }
20472038
2048- /**
2049- * Get the SQL projection given the selected attributes
2050- *
2051- * @param array<string> $selections
2052- * @param string $prefix
2053- * @return mixed
2054- * @throws Exception
2055- */
2056- protected function getAttributeProjection (array $ selections , string $ prefix = '' ): mixed
2057- {
2058- if (empty ($ selections ) || \in_array ('* ' , $ selections )) {
2059- if (!empty ($ prefix )) {
2060- return "` {$ prefix }`.* " ;
2061- }
2062- return '* ' ;
2063- }
2064-
2065- // Remove $id, $permissions and $collection if present since it is always selected by default
2066- $ selections = \array_diff ($ selections , ['$id ' , '$permissions ' , '$collection ' ]);
2067-
2068- $ selections [] = '_uid ' ;
2069- $ selections [] = '_permissions ' ;
2070-
2071- if (\in_array ('$internalId ' , $ selections )) {
2072- $ selections [] = '_id ' ;
2073- $ selections = \array_diff ($ selections , ['$internalId ' ]);
2074- }
2075- if (\in_array ('$createdAt ' , $ selections )) {
2076- $ selections [] = '_createdAt ' ;
2077- $ selections = \array_diff ($ selections , ['$createdAt ' ]);
2078- }
2079- if (\in_array ('$updatedAt ' , $ selections )) {
2080- $ selections [] = '_updatedAt ' ;
2081- $ selections = \array_diff ($ selections , ['$updatedAt ' ]);
2082- }
2083-
2084- if (!empty ($ prefix )) {
2085- foreach ($ selections as &$ selection ) {
2086- $ selection = "` {$ prefix }`.` {$ this ->filter ($ selection )}` " ;
2087- }
2088- } else {
2089- foreach ($ selections as &$ selection ) {
2090- $ selection = "` {$ this ->filter ($ selection )}` " ;
2091- }
2092- }
2093-
2094- return \implode (', ' , $ selections );
2095- }
2096-
20972039 /**
20982040 * Get SQL Condition
20992041 *
0 commit comments