public function format() { $sql = []; $sql[] = 'CREATE TABLE'; if ($this->createTableQuery->ifNotExists()) { $sql[] = 'IF NOT EXISTS'; } $sql[] = $this->formatterProvider->delimite($this->createTableQuery->getSchema()->getName()); $sql[] = '('; $columnList = []; foreach ($this->createTableQuery->getColumnList() as $columnFragment) { $columnList[] = $columnFragment->format($this->formatterProvider); } $sql[] = implode(', ', $columnList); $sql[] = ')'; return $this->sql(implode(' ', $sql)); }
/** * create the table from the given schema; this method needs to be optimized * * @param ISchema $schema * * @return $this */ public function createSchema(ISchema $schema) { if ($this->cache->load($cacheId = 'schema.' . $schema->getName()) === true) { return $this; } $createTableQuery = new CreateTableQuery($schema); $createTableQuery->setIfNotExists(); $createTableQuery->addColumn(new ColumnFragment($this->createPrimaryProperty())); $this->exec($createTableQuery); $this->cache->save($cacheId, true); return $this; }