- WIP on Migration of MsSQL

This commit is contained in:
Dave Mc Nicoll committed 2025-05-21 18:46:34 +00:00
1 parent c54de30069
commit fb4985160a
17 files changed
+252 -175

No files matched your search

+8 -5
View File
@@ -111,15 +111,17 @@ class DatasetHandler
return $unmatched;
}
public function pullRelation(object $entity) : Generator
public function pullRelation(object $entity, bool $onlyPreviouslyLoaded = true) : Generator
{
foreach($this->entityResolver->reflectedClass->getProperties(true) as $name => $field){
foreach($this->entityResolver->reflectedClass->getProperties(true) as $name => $field) {
$relation = $this->entityResolver->searchFieldAnnotation($name, [ Relation::class ] );
if ($relation) {
$ignore = $this->entityResolver->searchFieldAnnotation($name, [ Relation\Ignore::class ] );
if ($ignore && $ignore->ignoreExport) {
$load = $onlyPreviouslyLoaded ? (new \ReflectionProperty($entity::class, $name))->isInitialized($entity) : true;
if ( ! $load || ( $ignore && $ignore->ignoreExport ) ) {
if ( $relation->isOneToOne() ) {
# @TODO TO INCLUDED INTO getTypes() RETURNED CLASS WHEN DONE !
yield $name => ( new \ReflectionClass($field->getTypes()[0]) )->newInstanceWithoutConstructor();
@@ -132,9 +134,10 @@ class DatasetHandler
continue;
}
# @TODO Must fix recursive bug.. this last check is way too basic to work
if ( $entity->__isset($name) && ($relation->entity ?? $relation->bridge) !== static::class ) {
if ( null !== $value = $entity->__isset($name) ?? null ) {
$value = $entity->$name ?? null;
if ( null !== $value ) {
if ( is_iterable($value) ) {
$list = [];
+12 -3
View File
@@ -69,16 +69,19 @@ class Column
{
$nullable = $this->nullable === 'YES';
$definitionValue = $this->getDefinitionValue($definition);
if ($nullable !== $definition->allowsNull()) {
return false;
}
if ( isset($definition->value) && $this->canHaveDefaultValue() ) {
if ( $definition->value !== $this->defaultValue()) {
if ( isset($definitionValue) && $this->canHaveDefaultValue() ) {
if ( $definitionValue !== $this->defaultValue() ) {
# dump($definition->value, $this->defaultValue(), $definition->name);
return false;
}
}
elseif (! isset($definition->value)) {
elseif (! isset($definitionValue)) {
if ( ! $this->defaultValueIsNull() ) {
return false;
}
@@ -87,6 +90,12 @@ class Column
return true;
}
protected function getDefinitionValue(ReflectedProperty $definition) : mixed
{
# Attribute's value first, then defined in class value
return $definition->getAttribute(Field::class)->object->default ?? $definition->value ?? null;
}
protected function defaultValueIsNull() : bool
{
return $this->defaultValue() === null;
+73
View File
@@ -0,0 +1,73 @@
<?php
namespace Ulmus\Entity\Mssql;
use Ulmus\Attribute\Property\Field;
use Ulmus\Entity\Mysql\id;
class Column extends \Ulmus\Entity\InformationSchema\Column
{
# TODO ! Handle FUNCTIONAL default value
protected function canHaveDefaultValue(): bool
{
return ! in_array(strtoupper($this->dataType), [
# 'BLOB', 'TINYBLOB', 'MEDIUMBLOB', 'LONGBLOB', 'JSON', 'TEXT', 'TINYTEXT', 'MEDIUMTEXT', 'LONGTEXT', 'GEOMETRY'
]);
}
protected function defaultValue() : mixed
{
if ($this->default === null) {
return null;
}
# Removing first pairs of brackets
$default = $this->isBetween($this->default, '(', ')') ? substr($this->default, 1, -1) : $this->default;
if ($default === "NULL") {
return null;
}
# Checking if another pairs of brackets surrounds the value
if ($this->isBetween($default, '(', ')')) {
$default = substr($default, 1, -1);
if (is_numeric($default)) {
return (int) $default;
}
}
elseif ($this->isBetween($default, "'", "'")) {
$default = new class($default) implements \Stringable {
public function __construct(
private readonly string $default
) {}
public function __toString(): string
{
return substr($this->default, 1, -1);;
}
};
}
else {
$default = new class($default) implements \Stringable {
public function __construct(
private readonly string $default
) {}
public function __toString(): string
{
return $this->default;
}
};
}
return (string) $default;
}
private function isBetween(string $str, string $first, string $last) : bool
{
return str_starts_with($str, $first) && str_ends_with($str, $last);
}
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace Ulmus\Entity\Mssql;
use Ulmus\EntityCollection,
Ulmus\Entity\Field\Datetime;
use Ulmus\{Attribute\Obj\Table as TableObj,};
use Ulmus\Attribute\Property\{Field, Filter, FilterJoin, Relation, Join, Virtual, Where};
#[TableObj(name: "tables", database: "information_schema")]
class Table extends \Ulmus\Entity\InformationSchema\Table
{
#[Relation(type: "oneToMany", key: "name", foreignKey: [ Column::class, 'tableName' ], entity: Column::class)]
#[Where('TABLE_SCHEMA', generateValue: [ Table::class, 'getSchema' ])]
public EntityCollection $columns;
}