tableName = $name; $this->columns = array(); $this->constraints = array(); $this->ifNotExists = false; } public function addSerial($name) { $this->columns[$name] = new SerialColumn($name); return $this; } public function addString($name, $maxSize=NULL, $nullable=false, $defaultValue=NULL) { $this->columns[$name] = new StringColumn($name, $maxSize, $nullable, $defaultValue); return $this; } public function addDateTime($name, $nullable=false, $defaultValue=NULL) { $this->columns[$name] = new DateTimeColumn($name, $nullable, $defaultValue); return $this; } public function addInt($name, $nullable=false, $defaultValue=NULL) { $this->columns[$name] = new IntColumn($name, $nullable, $defaultValue); return $this; } public function addBool($name, $defaultValue=false) { $this->columns[$name] = new BoolColumn($name, $defaultValue); return $this; } public function addJson($name, $nullable=false, $defaultValue=NULL) { $this->columns[$name] = new JsonColumn($name, $nullable, $defaultValue); return $this; } public function addEnum($name, $values, $nullable=false, $defaultValue=NULL) { $this->columns[$name] = new EnumColumn($name, $values, $nullable, $defaultValue); return $this; } public function primaryKey(...$names) { $this->constraints[] = new PrimaryKey($names); return $this; } public function unique(...$names) { $this->constraints[] = new Unique($names); return $this; } public function foreignKey($name, $refTable, $refColumn, $strategy = NULL) { $this->constraints[] = new ForeignKey($name, $refTable, $refColumn, $strategy); return $this; } public function onlyIfNotExists() { $this->ifNotExists = true; return $this; } public function execute() { return $this->sql->executeCreateTable($this); } public function ifNotExists() { return $this->ifNotExists; } public function getTableName() { return $this->tableName; } public function getColumns() { return $this->columns; } public function getConstraints() { return $this->constraints; } }