/** * Convert CSV to database table. * * @param string $table * @param boolean $table_already_exists * @param boolean $clear_existing_records * @return void */ public function to_database($table = null, $table_already_exists = false, $clear_existing_records = false) { // if no pre-existing table defined... if (!$table_already_exists) { $t = new \Table($table); $t->create(); foreach ($this->columns as $column) { // create column; default length is 200 $t->string($column); } \Schema::execute($t); } else { // if clear existing records... \DB::query(sprintf("TRUNCATE TABLE `%s`", $table)); } // foreach row... foreach ($this->rows as $value) { // add to table \DB::table($table)->insert($value); } }
/** * Add any implicit commands to the schema table operation. * * @param Schema\Table $table * @return void */ protected static function implications($table) { // If the developer has specified columns for the table and the table is // not being created, we'll assume they simply want to add the columns // to the table and generate the add command. if (count($table->columns) > 0 and !$table->creating()) { $command = new Fluent(array('type' => 'add')); array_unshift($table->commands, $command); } // For some extra syntax sugar, we'll check for any implicit indexes // on the table since the developer may specify the index type on // the fluent column declaration for convenience. foreach ($table->columns as $column) { foreach (array('primary', 'unique', 'fulltext', 'index') as $key) { if (isset($column->attributes[$key])) { $table->{$key}($column->name); } } } }
public static function drop($table, $connection = null) { $table = new Schema\Table($table); $table->on($connection); $table->drop(); return static::execute($table); }