add SQLiteDriver.php and change MySQLDriver.php

This commit is contained in:
crazywhalecc
2022-08-27 19:47:45 +08:00
parent 085472a12c
commit dd01653da9
4 changed files with 68 additions and 38 deletions

View File

@@ -2,7 +2,7 @@
declare(strict_types=1);
namespace ZM\Store\MySQL;
namespace ZM\Store\Database;
use Doctrine\DBAL\Driver as DoctrineDriver;
use Doctrine\DBAL\Platforms\MySqlPlatform;
@@ -13,10 +13,10 @@ class MySQLDriver implements DoctrineDriver
public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
{
logger()->debug('Requiring new connection');
return new MySQLConnection($params);
return new DBConnection($params);
}
public function getDatabasePlatform(): MySqlPlatform
public function getDatabasePlatform()
{
return new MySqlPlatform();
}
@@ -33,14 +33,8 @@ class MySQLDriver implements DoctrineDriver
public function getDatabase($conn)
{
$conf = config('global.mysql');
if ($conn instanceof MySQLConnection) {
foreach ($conf as $v) {
if (($v['name'] ?? $v['dbname']) === $conn->getPoolName()) {
return $v['dbname'];
}
}
if ($conn instanceof DBConnection) {
return config('database')[$conn->getPoolName()]['dbname'] ?? '';
}
return '';
}

View File

@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace ZM\Store\Database;
use Doctrine\DBAL\Driver as DoctrineDriver;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Schema\SqliteSchemaManager;
class SQLiteDriver implements DoctrineDriver
{
public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
{
logger()->debug('Requiring new connection');
return new DBConnection($params);
}
public function getDatabasePlatform()
{
return new SqlitePlatform();
}
public function getSchemaManager($conn)
{
return new SqliteSchemaManager($conn);
}
public function getName()
{
return 'pdo_sqlite_pool';
}
public function getDatabase($conn)
{
if ($conn instanceof DBConnection) {
return config('database')[$conn->getPoolName()]['dbname'] ?? '';
}
return '';
}
}