Ver Fonte

Add dirty flag for table columns

Nathaniel van Diepen há 7 anos atrás
pai
commit
4784fe0504
1 ficheiros alterados com 20 adições e 2 exclusões
  1. 20 2
      PDO/table.class.php

+ 20 - 2
PDO/table.class.php

@@ -47,7 +47,8 @@
 						'null'=> $col['null'] !== 'NO',
 						'key'=> $col['key'],
 						'default'=> $col['default'],
-						'extra'=> $col['extra']
+						'extra'=> $col['extra'],
+						'dirty'=> false
 					];
 				}
 				$query->closeCursor();
@@ -92,6 +93,9 @@
 				$this->exists();
 			}else{
 				// @todo alter table to add and remove columns
+				$columns = array_filter($this->columns, function($item){
+					return $item['dirty'];
+				});
 			}
 			$this->describe();
 		}
@@ -105,7 +109,21 @@
 			}
 		}
 		public function column(string $name, array $column){
-			$this->columns[$name] = $column;
+			if(!isset($this->columns[$name])){
+				$this->columns[$name] = [
+					'type'=> null,
+					'null'=> false,
+					'key'=> null,
+					'default'=> null,
+					'extra'=> null
+				];
+			}
+			foreach($this->columns[$name] as $key => &$val){
+				if(isset($column[$key])){
+					$val = $column[$key];
+				}
+			}
+			$column['dirty'] = true;
 			return $this;
 		}
 		public function primaryKey(...$columns){