Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
VAR_ID
  • Loading branch information
fogelito committed Mar 8, 2023
commit d7cfb36b60f22ab5222f9af9f5b5013df2a631c4
2 changes: 1 addition & 1 deletion src/Database/Adapter/MariaDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ protected function getSQLType(string $type, int $size, bool $signed = true): str

return "VARCHAR({$size})";

case Database::VAR_INTSTRING:
case Database::VAR_ID:
return 'INT UNSIGNED'; // Same as Primary Key Sqlite does not allow INT(11)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this INT(11) and override for SQLite?


case Database::VAR_INTEGER: // We don't support zerofill: https://stackoverflow.com/a/5634147/2299554
Expand Down
4 changes: 3 additions & 1 deletion src/Database/Adapter/Postgres.php
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,9 @@ protected function getSQLType(string $type, int $size, bool $signed = true): str
return "VARCHAR({$size})";
break;

case Database::VAR_INTSTRING:
case Database::VAR_ID:
return 'INTEGER';

case Database::VAR_INTEGER: // We don't support zerofill: https://stackoverflow.com/a/5634147/2299554

if ($size >= 8) { // INT = 4 bytes, BIGINT = 8 bytes
Expand Down
8 changes: 5 additions & 3 deletions src/Database/Adapter/SQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ public function getAttributeWidth(Document $collection): int
$total += 4; // INT takes 4 bytes
}
break;

case Database::VAR_ID:
$total += 4;
break;

case Database::VAR_FLOAT:
// DOUBLE takes 8 bytes
$total += 8;
Expand All @@ -363,9 +368,6 @@ public function getAttributeWidth(Document $collection): int
$total += 19; // 2022-06-26 14:46:24
break;

case Database::VAR_INTSTRING:
$total += 8;
break;
default:
throw new Exception('Unknown Type');
break;
Expand Down
8 changes: 4 additions & 4 deletions src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class Database
const VAR_STRING = 'string';
// Simple Types
const VAR_INTEGER = 'integer';
const VAR_INTSTRING = 'intstring';
const VAR_FLOAT = 'double';
const VAR_BOOLEAN = 'boolean';
const VAR_DATETIME = 'datetime';
const VAR_ID = 'id';

// Relationships Types
const VAR_DOCUMENT = 'document';
Expand Down Expand Up @@ -758,7 +758,7 @@ public function createAttribute(string $collection, string $id, string $type, in
case self::VAR_FLOAT:
case self::VAR_BOOLEAN:
case self::VAR_DATETIME:
case self::VAR_INTSTRING:
case self::VAR_ID:
break;
default:
throw new Exception('Unknown attribute type: ' . $type);
Expand Down Expand Up @@ -1997,8 +1997,8 @@ public function casting(Document $collection, Document $document): Document
case self::VAR_INTEGER:
$node = (int)$node;
break;
case self::VAR_INTSTRING:
// let's keeps it string at this point as it comes out from the DB can be used by all
case self::VAR_ID:
// Not sure, maybe string as it fetched from DB?
break;
case self::VAR_FLOAT:
$node = (float)$node;
Expand Down
4 changes: 2 additions & 2 deletions src/Database/Validator/Structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ public function isValid($document): bool
$validator = new Integer();
break;

case Database::VAR_INTSTRING:
$validator = new Text(50, min: 0);
case Database::VAR_ID:
$validator = new Text(20, min: 0);
break;

case Database::VAR_FLOAT:
Expand Down
2 changes: 1 addition & 1 deletion tests/Database/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public function testCreateCollectionWithSchema()
]),
new Document([
'$id' => ID::custom('collection_id'),
'type' => Database::VAR_INTSTRING,
'type' => Database::VAR_ID,
'size' => 0,
'required' => true,
'signed' => false,
Expand Down