mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-22 16:15:34 +08:00
add SQLiteDriver.php and change MySQLDriver.php
This commit is contained in:
41
src/ZM/Store/Database/MySQLDriver.php
Normal file
41
src/ZM/Store/Database/MySQLDriver.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Store\Database;
|
||||
|
||||
use Doctrine\DBAL\Driver as DoctrineDriver;
|
||||
use Doctrine\DBAL\Platforms\MySqlPlatform;
|
||||
use Doctrine\DBAL\Schema\MySqlSchemaManager;
|
||||
|
||||
class MySQLDriver 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 MySqlPlatform();
|
||||
}
|
||||
|
||||
public function getSchemaManager($conn)
|
||||
{
|
||||
return new MySqlSchemaManager($conn);
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'pdo_mysql_pool';
|
||||
}
|
||||
|
||||
public function getDatabase($conn)
|
||||
{
|
||||
if ($conn instanceof DBConnection) {
|
||||
return config('database')[$conn->getPoolName()]['dbname'] ?? '';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
41
src/ZM/Store/Database/SQLiteDriver.php
Normal file
41
src/ZM/Store/Database/SQLiteDriver.php
Normal 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 '';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user