3
namespace Upside\Db\Schema\Compiler;
5
use Upside\Db\Schema\AlterTable;
6
use Upside\Db\Schema\BaseColumn;
7
use Upside\Db\Schema\Compiler;
8
use Upside\Db\Schema\CreateTable;
10
class SQLite extends Compiler
13
protected array $modifiers = ['nullable', 'default', 'autoincrement'];
14
protected string $autoincrement = 'AUTOINCREMENT';
17
private bool $nopk = false;
19
protected function handle_type_integer(BaseColumn $column): string
24
protected function handle_type_time(BaseColumn $column): string
29
protected function handle_type_timestamp(BaseColumn $column): string
34
public function handle_modifier_autoincrement(BaseColumn $column): string
36
$modifier = parent::handle_modifier_autoincrement($column);
38
if ($modifier !== '') {
40
$modifier = 'PRIMARY KEY ' . $modifier;
46
public function handle_primary_key(CreateTable $schema): string
52
return parent::handle_primary_key($schema);
55
protected function handle_engine(CreateTable $schema): string
60
protected function handle_add_unique(AlterTable $table, $data): string
62
return 'CREATE UNIQUE INDEX ' . $this->wrap($data['name']) . ' ON ' . $this->wrap($table->get_table_name()) . '(' . $this->wrap_array($data['columns']) . ')';
65
protected function handle_add_index(AlterTable $table, $data): string
67
return 'CREATE INDEX ' . $this->wrap($data['name']) . ' ON ' . $this->wrap($table->get_table_name()) . '(' . $this->wrap_array($data['columns']) . ')';
70
public function current_database(string $dsn): array
73
'result' => \substr($dsn, \strpos($dsn, ':') + 1),
77
public function get_tables(string $database): array
79
$sql = 'SELECT ' . $this->wrap('name') . ' FROM ' . $this->wrap('sqlite_master') . ' WHERE type = ? ORDER BY ' . $this->wrap('name') . ' ASC';
83
'params' => ['table'],
87
public function get_columns(string $database, string $table): array
90
'sql' => 'PRAGMA table_info(' . $this->wrap($table) . ')',
95
public function rename_table(string $current, string $new): array
98
'sql' => 'ALTER TABLE ' . $this->wrap($current) . ' RENAME TO ' . $this->wrap($new),