Skip to content

Commit eb35e68

Browse files
authored
Merge pull request #847 from utopia-php/big-init
Big int
2 parents 7f6bc87 + 1968ec4 commit eb35e68

21 files changed

Lines changed: 875 additions & 25 deletions

src/Database/Adapter.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,13 @@ abstract public function getLimitForString(): int;
903903
*/
904904
abstract public function getLimitForInt(): int;
905905

906+
/**
907+
* Get max BIGINT limit
908+
*
909+
* @return int
910+
*/
911+
abstract public function getLimitForBigInt(): int;
912+
906913
/**
907914
* Get maximum attributes limit.
908915
*
@@ -1472,6 +1479,11 @@ abstract public function decodeLinestring(string $wkb): array;
14721479
*/
14731480
abstract public function decodePolygon(string $wkb): array;
14741481

1482+
public function getSupportForUnsignedBigInt(): bool
1483+
{
1484+
return false;
1485+
}
1486+
14751487
/**
14761488
* Returns the document after casting
14771489
* @param Document $collection

src/Database/Adapter/MariaDB.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1751,6 +1751,10 @@ protected function getSQLType(string $type, int $size, bool $signed = true, bool
17511751

17521752
return 'INT' . $signed;
17531753

1754+
case Database::VAR_BIGINT:
1755+
$signed = ($signed) ? '' : ' UNSIGNED';
1756+
return 'BIGINT' . $signed;
1757+
17541758
case Database::VAR_FLOAT:
17551759
$signed = ($signed) ? '' : ' UNSIGNED';
17561760
return 'DOUBLE' . $signed;
@@ -1765,7 +1769,7 @@ protected function getSQLType(string $type, int $size, bool $signed = true, bool
17651769
return 'DATETIME(3)';
17661770

17671771
default:
1768-
throw new DatabaseException('Unknown type: ' . $type . '. Must be one of ' . Database::VAR_STRING . ', ' . Database::VAR_VARCHAR . ', ' . Database::VAR_TEXT . ', ' . Database::VAR_MEDIUMTEXT . ', ' . Database::VAR_LONGTEXT . ', ' . Database::VAR_INTEGER . ', ' . Database::VAR_FLOAT . ', ' . Database::VAR_BOOLEAN . ', ' . Database::VAR_DATETIME . ', ' . Database::VAR_RELATIONSHIP . ', ' . Database::VAR_POINT . ', ' . Database::VAR_LINESTRING . ', ' . Database::VAR_POLYGON);
1772+
throw new DatabaseException('Unknown type: ' . $type . '. Must be one of ' . Database::VAR_STRING . ', ' . Database::VAR_VARCHAR . ', ' . Database::VAR_TEXT . ', ' . Database::VAR_MEDIUMTEXT . ', ' . Database::VAR_LONGTEXT . ', ' . Database::VAR_INTEGER . ', ' . Database::VAR_BIGINT . ', ' . Database::VAR_FLOAT . ', ' . Database::VAR_BOOLEAN . ', ' . Database::VAR_DATETIME . ', ' . Database::VAR_RELATIONSHIP . ', ' . Database::VAR_POINT . ', ' . Database::VAR_LINESTRING . ', ' . Database::VAR_POLYGON);
17691773
}
17701774
}
17711775

@@ -2273,6 +2277,11 @@ public function getSupportForObject(): bool
22732277
return false;
22742278
}
22752279

2280+
public function getSupportForUnsignedBigInt(): bool
2281+
{
2282+
return true;
2283+
}
2284+
22762285
/**
22772286
* Are object (JSON) indexes supported?
22782287
*

src/Database/Adapter/Memory.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,6 +2119,16 @@ public function castingAfter(Document $collection, Document $document): Document
21192119
return $document;
21202120
}
21212121

2122+
/**
2123+
* Get max BIGINT limit
2124+
*
2125+
* @return int
2126+
*/
2127+
public function getLimitForBigInt(): int
2128+
{
2129+
return Database::MAX_BIG_INT;
2130+
}
2131+
21222132
public function getSupportForInternalCasting(): bool
21232133
{
21242134
return false;

src/Database/Adapter/Mongo.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,7 @@ public function castingAfter(Document $collection, Document $document): Document
13301330
foreach ($value as &$node) {
13311331
switch ($type) {
13321332
case Database::VAR_INTEGER:
1333+
case Database::VAR_BIGINT:
13331334
$node = (int)$node;
13341335
break;
13351336
case Database::VAR_DATETIME:
@@ -2272,6 +2273,7 @@ private function getMongoTypeCode(string $appwriteType): string
22722273
Database::VAR_MEDIUMTEXT => 'string',
22732274
Database::VAR_LONGTEXT => 'string',
22742275
Database::VAR_INTEGER => 'int',
2276+
Database::VAR_BIGINT => 'long',
22752277
Database::VAR_FLOAT => 'double',
22762278
Database::VAR_BOOLEAN => 'bool',
22772279
Database::VAR_DATETIME => 'date',
@@ -3065,6 +3067,16 @@ public function getLimitForInt(): int
30653067
return 4294967295;
30663068
}
30673069

3070+
/**
3071+
* Get max BIGINT limit
3072+
*
3073+
* @return int
3074+
*/
3075+
public function getLimitForBigInt(): int
3076+
{
3077+
return Database::MAX_BIG_INT;
3078+
}
3079+
30683080
/**
30693081
* Get maximum column limit.
30703082
* Returns 0 to indicate no limit

src/Database/Adapter/Pool.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,16 @@ public function getLimitForInt(): int
353353
return $this->delegate(__FUNCTION__, \func_get_args());
354354
}
355355

356+
public function getLimitForBigInt(): int
357+
{
358+
return $this->delegate(__FUNCTION__, \func_get_args());
359+
}
360+
361+
public function getSupportForUnsignedBigInt(): bool
362+
{
363+
return $this->delegate(__FUNCTION__, \func_get_args());
364+
}
365+
356366
public function getLimitForAttributes(): int
357367
{
358368
return $this->delegate(__FUNCTION__, \func_get_args());

src/Database/Adapter/Postgres.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1972,6 +1972,9 @@ protected function getSQLType(string $type, int $size, bool $signed = true, bool
19721972

19731973
return 'INTEGER';
19741974

1975+
case Database::VAR_BIGINT:
1976+
return 'BIGINT';
1977+
19751978
case Database::VAR_FLOAT:
19761979
return 'DOUBLE PRECISION';
19771980

@@ -2000,7 +2003,7 @@ protected function getSQLType(string $type, int $size, bool $signed = true, bool
20002003
return "VECTOR({$size})";
20012004

20022005
default:
2003-
throw new DatabaseException('Unknown Type: ' . $type . '. Must be one of ' . Database::VAR_STRING . ', ' . Database::VAR_VARCHAR . ', ' . Database::VAR_TEXT . ', ' . Database::VAR_MEDIUMTEXT . ', ' . Database::VAR_LONGTEXT . ', ' . Database::VAR_INTEGER . ', ' . Database::VAR_FLOAT . ', ' . Database::VAR_BOOLEAN . ', ' . Database::VAR_DATETIME . ', ' . Database::VAR_RELATIONSHIP . ', ' . Database::VAR_OBJECT . ', ' . Database::VAR_POINT . ', ' . Database::VAR_LINESTRING . ', ' . Database::VAR_POLYGON);
2006+
throw new DatabaseException('Unknown Type: ' . $type . '. Must be one of ' . Database::VAR_STRING . ', ' . Database::VAR_VARCHAR . ', ' . Database::VAR_TEXT . ', ' . Database::VAR_MEDIUMTEXT . ', ' . Database::VAR_LONGTEXT . ', ' . Database::VAR_INTEGER . ', ' . Database::VAR_BIGINT . ', ' . Database::VAR_FLOAT . ', ' . Database::VAR_BOOLEAN . ', ' . Database::VAR_DATETIME . ', ' . Database::VAR_RELATIONSHIP . ', ' . Database::VAR_OBJECT . ', ' . Database::VAR_POINT . ', ' . Database::VAR_LINESTRING . ', ' . Database::VAR_POLYGON);
20042007
}
20052008
}
20062009

src/Database/Adapter/Redis.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,16 @@ public function getSupportForOrderRandom(): bool
949949
return true;
950950
}
951951

952+
/**
953+
* Get max BIGINT limit
954+
*
955+
* @return int
956+
*/
957+
public function getLimitForBigInt(): int
958+
{
959+
return Database::MAX_BIG_INT;
960+
}
961+
952962
public function getSupportForInternalCasting(): bool
953963
{
954964
return false;

src/Database/Adapter/SQL.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,16 @@ public function getLimitForInt(): int
912912
return 4294967295;
913913
}
914914

915+
/**
916+
* Get max BIGINT limit
917+
*
918+
* @return int
919+
*/
920+
public function getLimitForBigInt(): int
921+
{
922+
return Database::MAX_BIG_INT;
923+
}
924+
915925
/**
916926
* Get maximum column limit.
917927
* https://mariadb.com/kb/en/innodb-limitations/#limitations-on-schema
@@ -1207,6 +1217,10 @@ public function getAttributeWidth(Document $collection): int
12071217
}
12081218
break;
12091219

1220+
case Database::VAR_BIGINT:
1221+
$total += 8; // BIGINT 8 bytes
1222+
break;
1223+
12101224
case Database::VAR_FLOAT:
12111225
$total += 8; // DOUBLE 8 bytes
12121226
break;

src/Database/Adapter/SQLite.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,11 @@ public function getSupportForObject(): bool
16791679
return false;
16801680
}
16811681

1682+
public function getSupportForUnsignedBigInt(): bool
1683+
{
1684+
return false;
1685+
}
1686+
16821687
/**
16831688
* Are object (JSON) indexes supported?
16841689
*

0 commit comments

Comments
 (0)