dbal icon indicating copy to clipboard operation
dbal copied to clipboard

feat: add TIMESTAMP and TIME precision

Open vencakrecl opened this issue 8 months ago • 0 comments

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();
            }
        };
    }
}

vencakrecl avatar Jun 13 '24 19:06 vencakrecl