drizzle-team / drizzle-team/drizzle-orm
[BUG]: Inconsistent parsing of TIME column between join() and with: queries
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Report hasn't been filed before.
- [x] I have verified that the bug I'm about to report hasn't been filed before.
### What version of `drizzle-orm` are you using?
0.43.1
### What version of `drizzle-kit` are you using?
0.31.1
### Other packages
_No response_
### Describe the Bug
## What is the undesired behavior?
When querying a table that contains a TIME column (e.g., open_time), the format of the returned value differs depending on how the related table is queried. Specifically:
- When using with: { relation: true }, the TIME column is returned as a string with milliseconds (e.g., "00:00:00.000").
- When using join(), the same column is returned as a plain "HH:mm:ss" string (e.g., "00:00:00").
This leads to inconsistent behavior and unexpected formatting differences in application code.
## What are the steps to reproduce it?
1. Define a MySQL table with a TIME column (open_time).
2. Use Drizzle's findMany() query with a with: clause to include the relation:
```ts
const result = await db.query.notices.findMany({
where: ...,
with: {
studio: true,
},
});
console.log(result[0].studio.open_time); // "00:00:00.000"
```
3. Use a join() query to fetch the same relation:
```ts
const result = await db
.select()
.from(notices)
.leftJoin(studios, eq(notices.studioId, studios.id));
console.log(result[0].studio.open_time); // "00:00:00"
```
## What is the desired result?
The TIME column should be consistently parsed and returned in the same format regardless of the query style. Ideally, it should always return as "HH:mm:ss" (string) unless explicitly parsed or cast to another type.
## Additional Context
### What database engine are you using?
MySQL: 8.0.37
### Are you using a specific cloud provider?
No
### Do you think this bug pertains to a specific database driver?
Yes, likely related to the mysql2 driver and how Drizzle parses TIME values when using nested queries.
The version of mysql2 I'm using is 3.14.1.
Contributor guide
Assessment
This issue has not been assessed yet.