dbal
dbal copied to clipboard
feat: add TIMESTAMP and TIME precision
Q | A |
---|---|
Type | feature |
Fixed issues |
Summary
Added support for precision for PostgreSQL TIMESTAMP and TIME. It would be nice to have this feature per column but it is impossible with the current implementation of datetime types.
How to use:
<?php
declare(strict_types=1);
namespace App\Doctrine;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsMiddleware;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Middleware;
use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
#[AsMiddleware]
class QueuesMiddleware implements Middleware
{
public function wrap(Driver $driver): Driver
{
return new class extends AbstractDriverMiddleware {
public function getDatabasePlatform(): PostgreSqlPlatform
{
$platform = new PostgreSqlPlatform();
$platform->setTimestampPrecision(6);
return $platform;
}
public function createDatabasePlatformForVersion($version): PostgreSqlPlatform
{
return $this->getDatabasePlatform();
}
};
}
}