- Fixed SQLite truncate, added AdapterProxy autoloading
This commit is contained in:
		
							parent
							
								
									1ec582d1ac
								
							
						
					
					
						commit
						761e0401b0
					
				| @ -2,12 +2,27 @@ | ||||
| 
 | ||||
| namespace Ulmus\Container; | ||||
| 
 | ||||
| use Ulmus\ConnectionAdapter; | ||||
| 
 | ||||
| class AdapterProxy | ||||
| { | ||||
|     public array $connections = []; | ||||
| 
 | ||||
|     public function __construct(...$arguments) | ||||
|     { | ||||
|         $this->connections = $arguments; | ||||
|         $this->push(array_filter($arguments)); | ||||
|     } | ||||
| 
 | ||||
|     public function push(array|ConnectionAdapter $connection) : void | ||||
|     { | ||||
|         foreach((array) $connection as $adapter) { | ||||
|             foreach($this->connections as $existing) { | ||||
|                 if ($adapter === $existing) { | ||||
|                     continue 2; | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             $this->connections[] = $adapter; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -343,7 +343,20 @@ class EntityCollection extends \ArrayObject implements \JsonSerializable { | ||||
|             $list[] = $entity instanceof \JsonSerializable ? $entity->jsonSerialize() : $entity->toArray($includeRelations); | ||||
|         } | ||||
| 
 | ||||
|         return $list; | ||||
|         return $this->utf8ize($list, "UTF-8", "UTF-8"); | ||||
|     } | ||||
| 
 | ||||
|     protected function utf8ize(mixed $content) { | ||||
|         if (is_array($content)) { | ||||
|             foreach ($content as $key => $value) { | ||||
|                 $content[$key] = $this->utf8ize($value); | ||||
|             } | ||||
|         } | ||||
|         elseif (is_string($content)) { | ||||
|             return mb_convert_encoding($content, "UTF-8", "UTF-8"); | ||||
|         } | ||||
| 
 | ||||
|         return $content; | ||||
|     } | ||||
| 
 | ||||
|     public function fromArray(array $datasets, ? string /*stringable*/ $entityClass = null) : self | ||||
|  | ||||
| @ -43,12 +43,12 @@ trait EntityTrait { | ||||
|     #[Ignore]
 | ||||
|     public function initializeEntity(iterable|null $dataset = null) : void | ||||
|     { | ||||
|         $this->datasetHandler = new DatasetHandler(static::resolveEntity(), $this->entityStrictFieldsDeclaration); | ||||
| 
 | ||||
|         if ($dataset) { | ||||
|             $this->fromArray($dataset); | ||||
|         } | ||||
| 
 | ||||
|         $this->datasetHandler = new DatasetHandler(static::resolveEntity(), $this->entityStrictFieldsDeclaration); | ||||
| 
 | ||||
|         $this->resetVirtualProperties(); | ||||
|     } | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										28
									
								
								src/Query/Sqlite/Truncate.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								src/Query/Sqlite/Truncate.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,28 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace Ulmus\Query\Sqlite; | ||||
| 
 | ||||
| use Ulmus\Query\Fragment; | ||||
| 
 | ||||
| class Truncate extends Fragment { | ||||
| 
 | ||||
|     const SQL_TOKEN = "DELETE FROM"; | ||||
|      | ||||
|     public int $order = -100; | ||||
| 
 | ||||
|     public string $table; | ||||
|      | ||||
|     public function set(string $tableName) : self | ||||
|     { | ||||
|         $this->table = $tableName; | ||||
|          | ||||
|         return $this; | ||||
|     } | ||||
| 
 | ||||
|     public function render() : string | ||||
|     { | ||||
|         return $this->renderSegments([ | ||||
|             static::SQL_TOKEN, $this->table, | ||||
|         ]); | ||||
|     } | ||||
| } | ||||
| @ -3,6 +3,7 @@ | ||||
| namespace Ulmus\QueryBuilder\Sql; | ||||
| 
 | ||||
| use Ulmus\Query; | ||||
| use Ulmus\Adapter\AdapterInterface; | ||||
| 
 | ||||
| # Soon to extends SqlQueryBuilder
 | ||||
| class SqliteQueryBuilder extends MysqlQueryBuilder | ||||
| @ -38,4 +39,41 @@ class SqliteQueryBuilder extends MysqlQueryBuilder | ||||
| 
 | ||||
|         return $this; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     public function insert(array $fieldlist, string $table, ? string $alias = null, ? string $database = null, ? string $schema = null, bool $replace = false) : self | ||||
|     { | ||||
|         return parent::insert($fieldlist, $table, $alias, null, null, $replace); | ||||
|     } | ||||
| 
 | ||||
|     public function update(string $table, ? string $alias = null, ? string $database = null, ? string $schema = null) : self | ||||
|     { | ||||
|         return parent::update($table, $alias, null, null); | ||||
|     } | ||||
| 
 | ||||
|     public function create(AdapterInterface $adapter, array $fieldlist, string $table, ? string $database = null, ? string $schema = null) : self | ||||
|     { | ||||
|         return parent::create($adapter, $fieldlist, $table, null, null); | ||||
|     } | ||||
| 
 | ||||
|     public function alter(AdapterInterface $adapter, array $fieldlist, string $table, ? string $database = null, ? string $schema = null) : self | ||||
|     { | ||||
|         return parent::alter($adapter, $fieldlist, $table, null, null); | ||||
|     } | ||||
| 
 | ||||
|     public function from(string $table, ? string $alias = null, ? string $database = null, ? string $schema = null) : self | ||||
|     { | ||||
|         return parent::from($table, $alias, null, null); | ||||
|     } | ||||
| 
 | ||||
|     public function truncate(string $table, ? string $alias = null, ? string $database = null, ? string $schema = null) : self | ||||
|     { | ||||
|         $truncate = new Query\Sqlite\Truncate($this); | ||||
| 
 | ||||
|         $this->push($truncate); | ||||
| 
 | ||||
|         $truncate->set($table); | ||||
| 
 | ||||
|         return $this; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -5,7 +5,7 @@ namespace Ulmus\QueryBuilder; | ||||
| use Ulmus\Query\QueryFragmentInterface; | ||||
| 
 | ||||
| # TODO -> Extract from MysqlQueryBuilder to build an ISO/IEC 9075:2023 compatible layer for a basic SQL QueryBuilder
 | ||||
| class SqlQueryBuilder implements QueryBuilderInterface | ||||
| abstract class SqlQueryBuilder implements QueryBuilderInterface | ||||
| { | ||||
|     protected string $rendered; | ||||
| 
 | ||||
|  | ||||
| @ -216,7 +216,12 @@ class Repository implements RepositoryInterface | ||||
|         } | ||||
|         else { | ||||
|             if ( $primaryKeyDefinition === null ) { | ||||
|                 throw new \Exception(sprintf("No primary key found for entity %s", $this->entityClass)); | ||||
|                 if ( null !== $compoundKeyFields = Ulmus::resolveEntity($this->entityClass)->getCompoundKeyFields() ) { | ||||
|                     throw new \Exception("TO DO!"); | ||||
|                 } | ||||
|                 else { | ||||
|                     throw new \Exception(sprintf("No primary key found for entity %s", $this->entityClass)); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             $diff = $fieldsAndValue ?? $this->generateWritableDataset($entity); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user