drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: "Transparent" Mode for Datetime Handling compatible with the underlying driver (timezone)

Open
#1,626 31 comments 3 reactions 0 assignees View on GitHub
db/mysql enhancement priority
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Describe what you want

## Context
I've been working with Drizzle for a possible adoption and have noticed that Drizzle is manipulating date values in a way that doesn't align with the behavior of the underlying MySql2 driver or other ORM/query builders that rely on it.

Indeed, MySql2 makes it possible to configure the timezone at the connection/pool level (other drivers, at least in MySql space offer a similar option): [Connection Options](https://github.com/mysqljs/mysql#connection-options)

This timezone configuration option makes it possible to manage scenarios where dates in a MySQL database are not stored in the UTC format (which is more frequent that one may imagine).
Essentially, this option ensures that all dates being sent to MySQL are converted from JavaScript's internal UTC format to the configured timezone. Similarly, all dates retrieved from MySQL are first converted back to UTC, before being transformed into JavaScript date objects.
This is crucial because the JavaScript Date constructor expects an input string to be in UTC format. Therefore, this feature ensures seamless conversion and compatibility between MySQL and JavaScript date formats, regardless of the timezone configuration.

## Problem
I've conducted several tests attempting to modify the timezone configuration during the creation of a MySql2 connection. However, these changes didn't seem to have any effect. Without having looked into the source code, it appears as though this option is being bypassed or short-circuited by Drizzle.

In my opinion, it would have been preferable if Drizzle didn't manipulate dates and leave the driver data untouched. Many SQL drivers, including MySql2, already have a built-in solution for handling timezones.

## A Universally Appealing Proposed Solution :)
That being said, given Drizzle's current approach to date handling, I believe a potential solution could be the introduction of a "transparent" mode along the "date" and "string" modes. This mode would allow users to opt out of Drizzle's date manipulation and rely on the underlying driver's date handling instead.

This new mode would provide a non breaking soloution that would make it possible to adopt drizzle in a smooth fashion for those having existing apps/database that rely on non utc stored dates.

Hopefully, this is a straigthforward change that will be accepted.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing Drizzle's MySQL datetime handling and how the underlying MySql2 connection timezone option is currently affected. Define the behavior of a transparent mode that leaves driver date handling untouched, then add coverage demonstrating compatibility with configured non-UTC timezones.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, typescript
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.