wazum/datetime-fractional-seconds 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

wazum/datetime-fractional-seconds

Composer 安装命令:

composer require wazum/datetime-fractional-seconds

包简介

Custom Doctrine type for DATETIME with fractional seconds support

README 文档

README

CI

A TYPO3 custom Doctrine type for DATETIME with fractional seconds support.

Compatible with TYPO3 12 LTS and 13 on PHP 8.2+.

Use case

If you need more control over the order of records in your database you need fractional seconds precision.

Let's assume you have an event driven system and store events in the database and multiple events are stored in the same second (very likely), you need a higher precision timestamp if you ever want to process your event streams in the right order.

Background

Doctrine (the ORM used by TYPO3) does not support fractional seconds for DATETIME fields.

There's an open issue about that here: doctrine/dbal#2873

Prerequisites

A database that supports DATETIME with fractional seconds is required. 👆 This extension supports MariaDB 10.2+, MySQL 5.7+ and PostgreSQL 10+. Other database systems are not affected and will fall back to the default behavior.

You'll find a list of supported database systems in this comment here: doctrine/dbal#2873 (comment)

Please submit a pull request if you need this behavior with TYPO3 and implemented it yourself.

Installation

composer require "wazum/datetime-fractional-seconds"

Usage

After installation every DATETIME field in ext_tables.sql with a fractional seconds precision — e.g. occurred_on DATETIME(6) — will be created with this length (6). Any DATETIME field without a precision length will be created without it (the default behavior).

With a precision on the database field you can then use a format that supports this in your code (the .u in the following example for a length of six).

Format Description Example
v Milliseconds (up to three digits) 12.345
u Microseconds (up to six digits) 45.654321

See https://www.php.net/manual/en/datetimeimmutable.createfromformat.php for format options.

private const DATETIME_FORMAT = 'Y-m-d H:i:s.u';

public function __invoke(SomethingHappened $event): void 
{
    $occurredOn = \DateTimeImmutable::createFromFormat(
        self::DATETIME_FORMAT,
        $event->getOccurredOn()
    );
}

Possible problems

Extending ConnectionPool

This extension extends the Core ConnectionPool to get a database connection.

$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\TYPO3\CMS\Core\Database\ConnectionPool::class] = [
    'className' => \Wazum\DatetimeFractionalSeconds\Core\Database\ConnectionPool::class
];

If you use another extension which does the same, you have to handle this yourself.

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2022-06-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固