public function drop_table_sql(\ebi\Dao $dao) { $quote = function ($name) { return '`' . $name . '`'; }; $sql = 'drop table ' . $quote($dao->table()); return $sql; }
/** * create table */ public function create_table_sql(\ebi\Dao $dao) { $columndef = $primary = []; $sql = 'create table ' . $this->quotation($dao->table()) . '(' . PHP_EOL; foreach ($dao->columns(true) as $prop_name => $column) { if ($this->create_table_prop_cond($dao, $prop_name)) { $column_str = ' ' . $this->to_column_type($dao, $dao->prop_anon($prop_name, 'type'), $column->column()) . ' null '; $columndef[] = $column_str; if ($dao->prop_anon($prop_name, 'primary') === true || $dao->prop_anon($prop_name, 'type') == 'serial') { $primary[] = $this->quotation($column->column()); } } } $sql .= implode(',' . PHP_EOL, $columndef) . PHP_EOL; if (!empty($primary)) { $sql .= ' ,primary key ( ' . implode(',', $primary) . ' ) ' . PHP_EOL; } $sql .= ' ) engine = InnoDB character set utf8 collate utf8_general_ci;' . PHP_EOL; return $sql; }
/** * create table */ public function create_table_sql(\ebi\Dao $dao) { $columndef = $primary = []; $sql = 'create table ' . $this->quotation($dao->table()) . '(' . PHP_EOL; foreach ($dao->columns(true) as $prop_name => $column) { $type = $dao->prop_anon($prop_name, 'type'); if ($this->create_table_prop_cond($dao, $prop_name)) { $column_str = ' ' . $this->to_column_type($dao, $type, $column->column()) . ($type != 'serial' ? ' null ' : ''); $columndef[] = $column_str; if ($dao->prop_anon($prop_name, 'primary') === true || $type != 'serial') { $primary[] = $this->quotation($column->column()); } } } $sql .= implode(',' . PHP_EOL, $columndef) . PHP_EOL; if (!empty($primary)) { $sql .= ' ,primary key ( ' . implode(',', $primary) . ' ) ' . PHP_EOL; } $sql .= ' );' . PHP_EOL; return $sql; }