ConnectionFactory.php
3 weeks ago
Connector.php
2 years ago
ConnectorInterface.php
2 years ago
MySqlConnector.php
2 years ago
PostgresConnector.php
3 weeks ago
SQLiteConnector.php
3 weeks ago
SqlServerConnector.php
3 weeks ago
SQLiteConnector.php
36 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWPSCOPED\Illuminate\Database\Connectors; |
| 4 | |
| 5 | use IAWPSCOPED\Illuminate\Database\SQLiteDatabaseDoesNotExistException; |
| 6 | /** @internal */ |
| 7 | class SQLiteConnector extends Connector implements ConnectorInterface |
| 8 | { |
| 9 | /** |
| 10 | * Establish a database connection. |
| 11 | * |
| 12 | * @param array $config |
| 13 | * @return \PDO |
| 14 | * |
| 15 | * @throws \Illuminate\Database\SQLiteDatabaseDoesNotExistException |
| 16 | */ |
| 17 | public function connect(array $config) |
| 18 | { |
| 19 | $options = $this->getOptions($config); |
| 20 | // SQLite supports "in-memory" databases that only last as long as the owning |
| 21 | // connection does. These are useful for tests or for short lifetime store |
| 22 | // querying. In-memory databases may only have a single open connection. |
| 23 | if ($config['database'] === ':memory:') { |
| 24 | return $this->createConnection('sqlite::memory:', $config, $options); |
| 25 | } |
| 26 | $path = \realpath($config['database']); |
| 27 | // Here we'll verify that the SQLite database exists before going any further |
| 28 | // as the developer probably wants to know if the database exists and this |
| 29 | // SQLite driver will not throw any exception if it does not by default. |
| 30 | if ($path === \false) { |
| 31 | throw new SQLiteDatabaseDoesNotExistException($config['database']); |
| 32 | } |
| 33 | return $this->createConnection("sqlite:{$path}", $config, $options); |
| 34 | } |
| 35 | } |
| 36 |