method getAlterTable documentation in bbn\Db\Languages\Sqlite

Return a string for alter table sql statement.

Example

$cfg = [ 'fields' => [ 'id' => [ 'type' => 'binary', 'maxlength' => 32 ], 'role' => [ 'type' => 'enum', 'default' => 'user' ], 'permission' => [ 'type' => 'set, 'default' => 'read' ], 'balance' => [ 'type' => 'real', 'maxlength' => 10, 'signed' => true, 'default' => 0 ], 'created_at' => [ 'type' => 'datetime', 'default' => 'CURRENT_TIMESTAMP' ], 'role_id' => [ 'alter_type' => 'drop' ] ] ]; X::dump($db->getAlterTable('users', $cfg)); // (string) ALTER TABLE "users" ADD "id" blob(32) NOT NULL; // ALTER TABLE "users" ADD "role" text NOT NULL DEFAULT "user"; // ALTER TABLE "users" ADD "permission" text NOT NULL DEFAULT 'read'; // ALTER TABLE "users" ADD "balance" real(10) NOT NULL DEFAULT 0; // ALTER TABLE "users" ADD "created_at" real NOT NULL DEFAULT CURRENT_TIMESTAMP; // ALTER TABLE "users" DROP COLUMN "role_id"; function(string $table, array $cfg) { if (empty($cfg['fields'])) { throw new \Exception(X::_('Fields are not specified')); } if ($this->check() && Str::checkName($table)) { $st = ''; foreach ($cfg['fields'] as $name => $col) { $st .= 'ALTER TABLE ' . $this->escape($table) . ' '; $st .= $this->getAlterColumn($table, array_merge($col, [ 'col_name' => $name, 'no_table_exp' => true ])); $st .= ";" . PHP_EOL; } } return $st ?? ''; }

Return a string for alter table sql statement. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.