Skip to content

Commit

Permalink
update version
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Nov 1, 2024
1 parent 35334dd commit 768792c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 36 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"psx/sql": "^3.0|^4.0",
"psx/nested": "^0.1",
"symfony/uid": "^6.0|^7.0",
"typeapi/editor": "^0.2|^1.0"
"typeapi/editor": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
Expand Down
34 changes: 11 additions & 23 deletions src/Generator/EntityExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ public function getMapping(Type $type, array $tableNames): array
} elseif ($property->getType() === 'object') {
$mapping[$this->getColumnName($property)] = implode(':', [$property->getName(), $property->getType()]);
} elseif ($property->getType() === 'array') {
if (self::isScalar($property->getFirstRef() ?? '')) {
if (self::isScalar($property->getReference() ?? '')) {
$mapping[$this->getColumnName($property)] = $property->getName();
} else {
$config = $this->getRelationConfig($type, $property, $tableNames);
$mapping[$this->getColumnName($property)] = implode(':', $config);
}
} elseif ($property->getType() === 'map') {
if (self::isScalar($property->getFirstRef() ?? '')) {
if (self::isScalar($property->getReference() ?? '')) {
$mapping[$this->getColumnName($property)] = $property->getName();
} else {
$config = $this->getRelationConfig($type, $property, $tableNames);
Expand Down Expand Up @@ -144,9 +144,9 @@ public function getRouteName(Type $type): string
private function getRelationConfig(Type $type, Property $property, array $tableNames): array
{
$tableName = $tableNames[$type->getName() ?? ''] ?? '';
$foreignTableName = $tableName . '_' . self::underscore($property->getFirstRef() ?? '');
$foreignTableName = $tableName . '_' . self::underscore($property->getReference() ?? '');
$typeColumn = self::underscore($type->getName() ?? '') . '_id';
$foreignColumn = self::underscore($property->getFirstRef() ?? '') . '_id';
$foreignColumn = self::underscore($property->getReference() ?? '') . '_id';

return [
$property->getName(),
Expand All @@ -172,8 +172,8 @@ private function createTableFromType(Schema $schema, Type $type, array $tableNam

$table->addColumn($columnName, $columnType, $columnOptions);

if ($property->getType() === 'object' && isset($tableNames[$property->getFirstRef()])) {
$relations[] = [$tableName, $tableNames[$property->getFirstRef() ?? ''], [$columnName], ['id']];
if ($property->getType() === 'object' && isset($tableNames[$property->getReference()])) {
$relations[] = [$tableName, $tableNames[$property->getReference() ?? ''], [$columnName], ['id']];
}
} elseif (in_array($property->getType(), ['map', 'array'])) {
$config = $this->getRelationConfig($type, $property, $tableNames);
Expand All @@ -188,9 +188,9 @@ private function createTableFromType(Schema $schema, Type $type, array $tableNam
$relationTable->addColumn($foreignColumn, 'integer');
$relationTable->setPrimaryKey(['id']);

if (isset($tableNames[$property->getFirstRef()])) {
if (isset($tableNames[$property->getReference()])) {
$relations[] = [$relationTableName, $tableName, [$typeColumn], ['id']];
$relations[] = [$relationTableName, $tableNames[$property->getFirstRef() ?? ''], [$foreignColumn], ['id']];
$relations[] = [$relationTableName, $tableNames[$property->getReference() ?? ''], [$foreignColumn], ['id']];
}
}
}
Expand All @@ -212,13 +212,13 @@ public function getColumnType(Property $property): ?string
} elseif ($property->getFormat() === 'time') {
return 'time';
} else {
return $property->getMaxLength() > 500 ? 'text' : 'string';
return 'string';
}
} elseif ($property->getType() === 'object') {
// reference to a different entity
return 'integer';
} elseif (in_array($property->getType(), ['map', 'array'])) {
if (self::isScalar($property->getFirstRef() ?? '')) {
if (self::isScalar($property->getReference() ?? '')) {
// if we have a scalar array we use a json property
return 'json';
} else {
Expand All @@ -238,26 +238,14 @@ private function getColumnOptions(Property $property): array
{
$options = ['notnull' => false];

if ($property->getType() === 'integer' || $property->getType() === 'number') {
$maximum = (int) $property->getMaximum();
if ($maximum > 0) {
$options['length'] = $maximum;
}
} elseif ($property->getType() === 'string') {
$maxLength = (int) $property->getMaxLength();
if ($maxLength > 0) {
$options['length'] = $maxLength;
}
}

return $options;
}

public static function getColumnName(Property $property): string
{
if ($property->getType() === 'object') {
// reference to a different entity
$ref = $property->getFirstRef();
$ref = $property->getReference();
if (!empty($ref)) {
return self::underscore($ref) . '_id';
}
Expand Down
24 changes: 12 additions & 12 deletions src/Generator/JqlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private function getDefinition(Type $type, array $tableNames, Document $document
continue;
}

$index = $document->indexOfType($property->getFirstRef() ?? '');
$index = $document->indexOfType($property->getReference() ?? '');
if ($index === null) {
continue;
}
Expand All @@ -121,7 +121,7 @@ private function getDefinition(Type $type, array $tableNames, Document $document
continue;
}

$foreignTable = $tableNames[$property->getFirstRef() ?? ''];
$foreignTable = $tableNames[$property->getReference() ?? ''];

$foreignColumns = [];
$entityDefinition = $this->getDefinition($foreignType, $tableNames, $document, $foreignColumns, $depth + 1);
Expand All @@ -140,7 +140,7 @@ private function getDefinition(Type $type, array $tableNames, Document $document
'$definition' => $entityDefinition,
];
} elseif ($property->getType() === 'map') {
if (EntityExecutor::isScalar($property->getFirstRef() ?? '')) {
if (EntityExecutor::isScalar($property->getReference() ?? '')) {
$columnName = EntityExecutor::getColumnName($property);
$columns[] = $columnName;

Expand All @@ -153,7 +153,7 @@ private function getDefinition(Type $type, array $tableNames, Document $document
continue;
}

$index = $document->indexOfType($property->getFirstRef() ?? '');
$index = $document->indexOfType($property->getReference() ?? '');
if ($index === null) {
continue;
}
Expand All @@ -164,8 +164,8 @@ private function getDefinition(Type $type, array $tableNames, Document $document
}

$table = $tableNames[$type->getName() ?? ''];
$foreignTable = $tableNames[$property->getFirstRef() ?? ''];
$relationTable = $table . '_' . EntityExecutor::underscore($property->getFirstRef() ?? '');
$foreignTable = $tableNames[$property->getReference() ?? ''];
$relationTable = $table . '_' . EntityExecutor::underscore($property->getReference() ?? '');

$foreignColumns = [];
$mapDefinition = $this->getDefinition($foreignType, $tableNames, $document, $foreignColumns, $depth + 1);
Expand All @@ -179,7 +179,7 @@ private function getDefinition(Type $type, array $tableNames, Document $document
$query = 'SELECT ' . implode(', ', $foreignColumns) . ' ';
$query.= 'FROM ' . $relationTable . ' rel ';
$query.= 'INNER JOIN ' . $foreignTable . ' entity ';
$query.= 'ON entity.id = rel.' . EntityExecutor::underscore($property->getFirstRef() ?? '') . '_id ';
$query.= 'ON entity.id = rel.' . EntityExecutor::underscore($property->getReference() ?? '') . '_id ';
$query.= 'WHERE rel.' . EntityExecutor::underscore($type->getName() ?? '') . '_id = :id ';
$query.= 'ORDER BY entity.id DESC ';
$query.= 'LIMIT 16';
Expand All @@ -196,7 +196,7 @@ private function getDefinition(Type $type, array $tableNames, Document $document
];
}
} elseif ($property->getType() === 'array') {
if (EntityExecutor::isScalar($property->getFirstRef() ?? '')) {
if (EntityExecutor::isScalar($property->getReference() ?? '')) {
$columns[] = EntityExecutor::getColumnName($property);

$value = [
Expand All @@ -207,7 +207,7 @@ private function getDefinition(Type $type, array $tableNames, Document $document
continue;
}

$index = $document->indexOfType($property->getFirstRef() ?? '');
$index = $document->indexOfType($property->getReference() ?? '');
if ($index === null) {
continue;
}
Expand All @@ -218,8 +218,8 @@ private function getDefinition(Type $type, array $tableNames, Document $document
}

$table = $tableNames[$type->getName() ?? ''];
$foreignTable = $tableNames[$property->getFirstRef() ?? ''];
$relationTable = $table . '_' . EntityExecutor::underscore($property->getFirstRef() ?? '');
$foreignTable = $tableNames[$property->getReference() ?? ''];
$relationTable = $table . '_' . EntityExecutor::underscore($property->getReference() ?? '');

$foreignColumns = [];
$arrayDefinition = $this->getDefinition($foreignType, $tableNames, $document, $foreignColumns, $depth + 1);
Expand All @@ -231,7 +231,7 @@ private function getDefinition(Type $type, array $tableNames, Document $document
$query = 'SELECT ' . implode(', ', $foreignColumns) . ' ';
$query.= 'FROM ' . $relationTable . ' rel ';
$query.= 'INNER JOIN ' . $foreignTable . ' entity ';
$query.= 'ON entity.id = rel.' . EntityExecutor::underscore($property->getFirstRef() ?? '') . '_id ';
$query.= 'ON entity.id = rel.' . EntityExecutor::underscore($property->getReference() ?? '') . '_id ';
$query.= 'WHERE rel.' . EntityExecutor::underscore($type->getName() ?? '') . '_id = :id ';
$query.= 'ORDER BY entity.id DESC ';
$query.= 'LIMIT 16';
Expand Down

0 comments on commit 768792c

Please sign in to comment.