devleand/doctrine-dbal-timestamp-type

Timestamp type for Doctrine DBAL

0.1.1 2022-01-08 16:08 UTC

This package is not auto-updated.

Last update: 2024-05-26 04:20:23 UTC


README

Library for cross-platform timestamp support for Doctrine DBAL.

How it works?

The Timestamp type is inherited from the Doctrine DateTime type. When saving/retrieving a value, it converts the value to a date in UTC format. Thus, for platforms without direct support of the timestamp type, support is achieved by storing the value in the UTC format in the datetime field.

Installation

composer require devleand/doctrine-dbal-timestamp-type

And add the type to Doctrine\DBAL:

\Doctrine\DBAL\Types\Type::addType('timestamp', 'Devleand\Doctrine\DBAL\Types\TimestampType');

Symfony

Add this to config/packages/doctrine.yaml:

doctrine:
    dbal:
        types:
            timestamp: Devleand\Doctrine\DBAL\Types\TimestampType
        mapping_types:
            timestamp: timestamp

Example of complete file content:

doctrine:
    dbal:
        url: '%env(resolve:DATABASE_URL)%'
        types:
            timestamp: Devleand\Doctrine\DBAL\Types\TimestampType
        mapping_types:
            timestamp: timestamp

    orm:
        auto_generate_proxy_classes: true
        naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
        auto_mapping: true
        mappings:
            App:
                is_bundle: false
                type: annotation
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App