定制 owlcorp/doctrine-microseconds-datetime 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

owlcorp/doctrine-microseconds-datetime

Composer 安装命令:

composer require owlcorp/doctrine-microseconds-datetime

包简介

Adds support of microseconds time formats to Doctrine ORM & Doctrine DBAL

README 文档

README

What is this about?

This library has no fancy logo. It also lacks all cool badges, but what it has is a simple & ready-to-use implementation of mili- and microsecond types for Doctrine ORM/DBAL.

Why?

Date and time is hard, databases are hard - a combination of the two is a nightmare. There's a 5+ years old issue describing the problem. To do it properly and across all platforms seems nearly impossible. However, it is possible to do it with a limited scope. This is why this package was created: I personally stepped into that issue many times over the years, and here came the time to stop copying & pasting the same code.

How to use?

  1. Install with composer: composer require owlcorp/doctrine-microseconds-datetime (it will work across PHP7.0-8+)
  2. Add DBAL types
  • If you're using Symfony, edit config/packages/doctrine.yaml and add:
    doctrine:
        dbal:
            types:
                time_micro: OwlCorp\DoctrineMicrotime\DBAL\Types\TimeMicroType
                time_immutable_micro: OwlCorp\DoctrineMicrotime\DBAL\Types\TimeImmutableMicroType
                datetime_micro: OwlCorp\DoctrineMicrotime\DBAL\Types\DateTimeMicroType
                datetime_immutable_micro: OwlCorp\DoctrineMicrotime\DBAL\Types\DateTimeImmutableMicroType
                datetimetz_micro: OwlCorp\DoctrineMicrotime\DBAL\Types\DateTimeTzMicroType
                datetimetz_immutable_micro: OwlCorp\DoctrineMicrotime\DBAL\Types\DateTimeTzImmutableMicroType
  • If you're not using Symfony check official Doctrine documentation.
  1. For ORM, you can use it like so:

    <?php declare(strict_types=1);
    
    use Doctrine\ORM\Mapping as ORM;
    
    #[ORM\Entity]
    class MicroEntity
    {
        #[ORM\Column(type: 'time_micro')] //you can use text names
        public \DateTime $time;
    
        #[ORM\Column(type: TimeImmutableMicroType::NAME)] //or constants
        public \DateTimeImmutable $timeImmutable;
    
        /**
         * @ORM\Column(type="datetime_micro") Of course, it works with annotations too
         */
        public \DateTime $dateTime;
    }

What's supported?

See table below. These are combos which I was able to test, and they should cover most of the usecases. If you know about another database engine supporting it and it can be confirmed easily issues are welcome :)

↓ DB ↓ | Type → time_micro datetime_micro datetimetz_micro3
PostgreSQL <10 2 2
PostgreSQL 10+
MySQL 5.6.4+
Oracle-Xe
Microsoft SQL <2008 ⚠️ ⚠️
Microsoft SQL 2008+ & Azure
SQLite 31 ⚠️ ⚠️
Other databases

✅ = full microseconds support (.000000) | ⚠️ = miliseconds only (.000) | ❌ = not supported

Quirks

  1. SQLite does't support native TIME/DATETIME fields, but internal functions support text-based representation with milisecond precision.
  2. Older PgSQL in certain edge-cases could loose some precision, you're unlikely to hit the non-Y2K year-2000 bug.
  3. Bonus: yes, timezone support is broken in most databases. Even where supported you probably shouldn't use it.

Sources

owlcorp/doctrine-microseconds-datetime 适用场景与选型建议

owlcorp/doctrine-microseconds-datetime 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.89k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2023 年 01 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 owlcorp/doctrine-microseconds-datetime 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 owlcorp/doctrine-microseconds-datetime 我们能提供哪些服务?
定制开发 / 二次开发

基于 owlcorp/doctrine-microseconds-datetime 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 10.89k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 3
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-10