Skip to content

Commit 3523c19

Browse files
authored
Merge pull request #712 from utopia-php/feat-mongo-tmp-pulls
Feat mongo tmp pulls
2 parents 5f77bec + 901a7d8 commit 3523c19

File tree

17 files changed

+959
-478
lines changed

17 files changed

+959
-478
lines changed

src/Database/Adapter.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,12 +1271,45 @@ abstract public function getInternalIndexesKeys(): array;
12711271
*/
12721272
abstract public function getSchemaAttributes(string $collection): array;
12731273

1274+
/**
1275+
* Get the query to check for tenant when in shared tables mode
1276+
*
1277+
* @param string $collection The collection being queried
1278+
* @param string $alias The alias of the parent collection if in a subquery
1279+
* @return string
1280+
*/
1281+
abstract public function getTenantQuery(string $collection, string $alias = ''): string;
1282+
12741283
/**
12751284
* @param mixed $stmt
12761285
* @return bool
12771286
*/
12781287
abstract protected function execute(mixed $stmt): bool;
12791288

1289+
/**
1290+
* Decode a WKB or textual POINT into [x, y]
1291+
*
1292+
* @param string $wkb
1293+
* @return float[] Array with two elements: [x, y]
1294+
*/
1295+
abstract public function decodePoint(string $wkb): array;
1296+
1297+
/**
1298+
* Decode a WKB or textual LINESTRING into [[x1, y1], [x2, y2], ...]
1299+
*
1300+
* @param string $wkb
1301+
* @return float[][] Array of points, each as [x, y]
1302+
*/
1303+
abstract public function decodeLinestring(string $wkb): array;
1304+
1305+
/**
1306+
* Decode a WKB or textual POLYGON into [[[x1, y1], [x2, y2], ...], ...]
1307+
*
1308+
* @param string $wkb
1309+
* @return float[][][] Array of rings, each ring is an array of points [x, y]
1310+
*/
1311+
abstract public function decodePolygon(string $wkb): array;
1312+
12801313
/**
12811314
* Returns the document after casting
12821315
* @param Document $collection

src/Database/Adapter/MariaDB.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function createCollection(string $name, array $attributes = [], array $in
155155

156156
$collection = "
157157
CREATE TABLE {$this->getSQLTable($id)} (
158-
_id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
158+
_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
159159
_uid VARCHAR(255) NOT NULL,
160160
_createdAt DATETIME(3) DEFAULT NULL,
161161
_updatedAt DATETIME(3) DEFAULT NULL,
@@ -186,7 +186,7 @@ public function createCollection(string $name, array $attributes = [], array $in
186186

187187
$permissions = "
188188
CREATE TABLE {$this->getSQLTable($id . '_perms')} (
189-
_id int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
189+
_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
190190
_type VARCHAR(12) NOT NULL,
191191
_permission VARCHAR(255) NOT NULL,
192192
_document VARCHAR(255) NOT NULL,

src/Database/Adapter/Mongo.php

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,7 @@ public function getSequences(string $collection, array $documents): array
13011301

13021302
// Continue fetching with getMore
13031303
while ($cursorId && $cursorId !== 0) {
1304-
$moreResponse = $this->client->getMore($cursorId, $name, self::DEFAULT_BATCH_SIZE);
1304+
$moreResponse = $this->client->getMore((int)$cursorId, $name, self::DEFAULT_BATCH_SIZE);
13051305
$moreResults = $moreResponse->cursor->nextBatch ?? [];
13061306

13071307
if (empty($moreResults)) {
@@ -1313,7 +1313,7 @@ public function getSequences(string $collection, array $documents): array
13131313
}
13141314

13151315
// Update cursor ID for next iteration
1316-
$cursorId = $moreResponse->cursor->id ?? null;
1316+
$cursorId = (int)($moreResponse->cursor->id ?? 0);
13171317
}
13181318
} catch (MongoException $e) {
13191319
throw $this->processException($e);
@@ -1612,7 +1612,6 @@ public function find(Document $collection, array $queries = [], ?int $limit = 25
16121612

16131613
$response = $this->client->find($name, $filters, $options);
16141614
$results = $response->cursor->firstBatch ?? [];
1615-
16161615
// Process first batch
16171616
foreach ($results as $result) {
16181617
$record = $this->replaceChars('_', '$', (array)$result);
@@ -1629,7 +1628,7 @@ public function find(Document $collection, array $queries = [], ?int $limit = 25
16291628
break;
16301629
}
16311630

1632-
$moreResponse = $this->client->getMore($cursorId, $name, self::DEFAULT_BATCH_SIZE);
1631+
$moreResponse = $this->client->getMore((int)$cursorId, $name, self::DEFAULT_BATCH_SIZE);
16331632
$moreResults = $moreResponse->cursor->nextBatch ?? [];
16341633

16351634
if (empty($moreResults)) {
@@ -1646,7 +1645,7 @@ public function find(Document $collection, array $queries = [], ?int $limit = 25
16461645
}
16471646
}
16481647

1649-
$cursorId = $moreResponse->cursor->id ?? 0;
1648+
$cursorId = (int)($moreResponse->cursor->id ?? 0);
16501649
}
16511650

16521651
} catch (MongoException $e) {
@@ -2264,7 +2263,7 @@ public function getSupportForFulltextWildcardIndex(): bool
22642263
*/
22652264
public function getSupportForQueryContains(): bool
22662265
{
2267-
return false;
2266+
return true;
22682267
}
22692268

22702269
/**
@@ -2553,7 +2552,6 @@ public function getKeywords(): array
25532552

25542553
protected function processException(Exception $e): \Exception
25552554
{
2556-
25572555
// Timeout
25582556
if ($e->getCode() === 50) {
25592557
return new Timeout('Query timed out', $e->getCode(), $e);
@@ -2660,4 +2658,45 @@ public function getTenantFilters(
26602658

26612659
return ['$in' => $values];
26622660
}
2661+
2662+
public function decodePoint(string $wkb): array
2663+
{
2664+
return [];
2665+
}
2666+
2667+
/**
2668+
* Decode a WKB or textual LINESTRING into [[x1, y1], [x2, y2], ...]
2669+
*
2670+
* @param string $wkb
2671+
* @return float[][] Array of points, each as [x, y]
2672+
*/
2673+
public function decodeLinestring(string $wkb): array
2674+
{
2675+
return [];
2676+
}
2677+
2678+
/**
2679+
* Decode a WKB or textual POLYGON into [[[x1, y1], [x2, y2], ...], ...]
2680+
*
2681+
* @param string $wkb
2682+
* @return float[][][] Array of rings, each ring is an array of points [x, y]
2683+
*/
2684+
public function decodePolygon(string $wkb): array
2685+
{
2686+
return [];
2687+
}
2688+
2689+
/**
2690+
* Get the query to check for tenant when in shared tables mode
2691+
*
2692+
* @param string $collection The collection being queried
2693+
* @param string $alias The alias of the parent collection if in a subquery
2694+
* @return string
2695+
*/
2696+
public function getTenantQuery(string $collection, string $alias = ''): string
2697+
{
2698+
return '';
2699+
}
2700+
2701+
26632702
}

src/Database/Adapter/Pool.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -470,13 +470,7 @@ public function getKeywords(): array
470470
return $this->delegate(__FUNCTION__, \func_get_args());
471471
}
472472

473-
/**
474-
* @param array<string,mixed> $selections
475-
* @param string $prefix
476-
* @param array<string,mixed> $spatialAttributes
477-
* @return mixed
478-
*/
479-
protected function getAttributeProjection(array $selections, string $prefix, array $spatialAttributes = []): mixed
473+
protected function getAttributeProjection(array $selections, string $prefix): mixed
480474
{
481475
return $this->delegate(__FUNCTION__, \func_get_args());
482476
}
@@ -550,6 +544,21 @@ public function getSupportForSpatialAxisOrder(): bool
550544
return $this->delegate(__FUNCTION__, \func_get_args());
551545
}
552546

547+
public function decodePoint(string $wkb): array
548+
{
549+
return $this->delegate(__FUNCTION__, \func_get_args());
550+
}
551+
552+
public function decodeLinestring(string $wkb): array
553+
{
554+
return $this->delegate(__FUNCTION__, \func_get_args());
555+
}
556+
557+
public function decodePolygon(string $wkb): array
558+
{
559+
return $this->delegate(__FUNCTION__, \func_get_args());
560+
}
561+
553562
public function castingBefore(Document $collection, Document $document): Document
554563
{
555564
return $this->delegate(__FUNCTION__, \func_get_args());

0 commit comments

Comments
 (0)