Grammars
3 weeks ago
Blueprint.php
3 weeks ago
Builder.php
3 weeks ago
ColumnDefinition.php
3 weeks ago
ForeignIdColumnDefinition.php
3 weeks ago
ForeignKeyDefinition.php
3 weeks ago
IndexDefinition.php
3 weeks ago
MySqlBuilder.php
3 weeks ago
MySqlSchemaState.php
3 weeks ago
PostgresBuilder.php
3 weeks ago
PostgresSchemaState.php
3 weeks ago
SQLiteBuilder.php
3 weeks ago
SchemaState.php
3 weeks ago
SqlServerBuilder.php
3 weeks ago
SqliteSchemaState.php
3 weeks ago
SQLiteBuilder.php
84 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWPSCOPED\Illuminate\Database\Schema; |
| 4 | |
| 5 | use IAWPSCOPED\Illuminate\Support\Facades\File; |
| 6 | /** @internal */ |
| 7 | class SQLiteBuilder extends Builder |
| 8 | { |
| 9 | /** |
| 10 | * Create a database in the schema. |
| 11 | * |
| 12 | * @param string $name |
| 13 | * @return bool |
| 14 | */ |
| 15 | public function createDatabase($name) |
| 16 | { |
| 17 | return File::put($name, '') !== \false; |
| 18 | } |
| 19 | /** |
| 20 | * Drop a database from the schema if the database exists. |
| 21 | * |
| 22 | * @param string $name |
| 23 | * @return bool |
| 24 | */ |
| 25 | public function dropDatabaseIfExists($name) |
| 26 | { |
| 27 | return File::exists($name) ? File::delete($name) : \true; |
| 28 | } |
| 29 | /** |
| 30 | * Drop all tables from the database. |
| 31 | * |
| 32 | * @return void |
| 33 | */ |
| 34 | public function dropAllTables() |
| 35 | { |
| 36 | if ($this->connection->getDatabaseName() !== ':memory:') { |
| 37 | return $this->refreshDatabaseFile(); |
| 38 | } |
| 39 | $this->connection->select($this->grammar->compileEnableWriteableSchema()); |
| 40 | $this->connection->select($this->grammar->compileDropAllTables()); |
| 41 | $this->connection->select($this->grammar->compileDisableWriteableSchema()); |
| 42 | $this->connection->select($this->grammar->compileRebuild()); |
| 43 | } |
| 44 | /** |
| 45 | * Drop all views from the database. |
| 46 | * |
| 47 | * @return void |
| 48 | */ |
| 49 | public function dropAllViews() |
| 50 | { |
| 51 | $this->connection->select($this->grammar->compileEnableWriteableSchema()); |
| 52 | $this->connection->select($this->grammar->compileDropAllViews()); |
| 53 | $this->connection->select($this->grammar->compileDisableWriteableSchema()); |
| 54 | $this->connection->select($this->grammar->compileRebuild()); |
| 55 | } |
| 56 | /** |
| 57 | * Get all of the table names for the database. |
| 58 | * |
| 59 | * @return array |
| 60 | */ |
| 61 | public function getAllTables() |
| 62 | { |
| 63 | return $this->connection->select($this->grammar->compileGetAllTables()); |
| 64 | } |
| 65 | /** |
| 66 | * Get all of the view names for the database. |
| 67 | * |
| 68 | * @return array |
| 69 | */ |
| 70 | public function getAllViews() |
| 71 | { |
| 72 | return $this->connection->select($this->grammar->compileGetAllViews()); |
| 73 | } |
| 74 | /** |
| 75 | * Empty the database file. |
| 76 | * |
| 77 | * @return void |
| 78 | */ |
| 79 | public function refreshDatabaseFile() |
| 80 | { |
| 81 | \file_put_contents($this->connection->getDatabaseName(), ''); |
| 82 | } |
| 83 | } |
| 84 |