1<?php 2 3namespace Illuminate\Database\Schema; 4 5use Illuminate\Support\Facades\File; 6 7class 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 /** 21 * Drop a database from the schema if the database exists. 22 * 23 * @param string $name 24 * @return bool 25 */ 26 public function dropDatabaseIfExists($name) 27 { 28 return File::exists($name) 29 ? File::delete($name) 30 : true; 31 } 32 33 /** 34 * Drop all tables from the database. 35 * 36 * @return void 37 */ 38 public function dropAllTables() 39 { 40 if ($this->connection->getDatabaseName() !== ':memory:') { 41 return $this->refreshDatabaseFile(); 42 } 43 44 $this->connection->select($this->grammar->compileEnableWriteableSchema()); 45 46 $this->connection->select($this->grammar->compileDropAllTables()); 47 48 $this->connection->select($this->grammar->compileDisableWriteableSchema()); 49 50 $this->connection->select($this->grammar->compileRebuild()); 51 } 52 53 /** 54 * Drop all views from the database. 55 * 56 * @return void 57 */ 58 public function dropAllViews() 59 { 60 $this->connection->select($this->grammar->compileEnableWriteableSchema()); 61 62 $this->connection->select($this->grammar->compileDropAllViews()); 63 64 $this->connection->select($this->grammar->compileDisableWriteableSchema()); 65 66 $this->connection->select($this->grammar->compileRebuild()); 67 } 68 69 /** 70 * Empty the database file. 71 * 72 * @return void 73 */ 74 public function refreshDatabaseFile() 75 { 76 file_put_contents($this->connection->getDatabaseName(), ''); 77 } 78} 79