Closed PauliusLozys closed 9 months ago
The overall change introduces a new feature that allows time values to be truncated to a specified duration across various parts of the system. This is achieved by adding a TimeTruncate
configuration option and updating the relevant functions to accept this new parameter. The feature impacts how date-time values are processed and formatted, affecting database connection configurations, parameter interpolation, and utility functions. It extends the system's flexibility in handling time values according to user-specified precision.
Files | Change Summary |
---|---|
AUTHORS , README.md |
Added a new author and introduced the timeTruncate configuration option in the documentation. |
connection.go , packets.go , utils.go |
Modified functions to include the TimeTruncate parameter, affecting date-time value processing. |
dsn.go , dsn_test.go |
Updated the Config struct to include TimeTruncate , enhanced DSN parsing and formatting to support this new field, and added relevant tests. |
utils_test.go |
Modified tests to incorporate time truncation testing, reflecting the new functionality. |
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
~I think t.Truncate() should be called in caller of appendDateTime.~
Sorry. Adding truncate option to appendDateTime makes it easy to find a bug like missing truncate.
When caller don't need truncate, caller can pass 0
.
~I think t.Truncate() should be called in caller of appendDateTime.~
Sorry. Adding truncate option to appendDateTime makes it easy to find a bug like missing truncate. When caller don't need truncate, caller can pass
0
.
Thanks for the review! I'm a little confused about the comment. Do you mean to keep the function as it is, or move the truncation logic outside appendDateTime
?
I think having truncation inside appendDateTime
would seem more appropriate as this function's purpose is to format time string. Having the ability to pass additional formatting parameters like truncation seems appropriate and would show that such option is available.
But if you think it's better to have it outside, I'll change it.
Thanks for the review! I'm a little confused about the comment. Do you mean to keep the function as it is, or move the truncation logic outside
appendDateTime
?
Keep as it is.
We may revert adding TimeTruncate to Config obj, although keeping this feature.
See #1548 for detail.
Description
This introduces
timeTruncate
parameter that will truncatetime.Time
values in query arguments.After https://github.com/go-sql-driver/mysql/issues/1121,
Timestamp
andDatetime
indexes inMariaDB
broke due to nanoseconds now being present intime.Time
https://github.com/go-sql-driver/mysql/issues/1121#issuecomment-852920526.Query without nanoseconds part: On MariaDB v11.2.2
Same query on MySQL v8.3.0
Query with nanosecond part: On MariaDB v11.2.2
On MySQL v8.3.0
Currently, to have correct timestamp/datetime index usage is to either use
time.Truncate(time.Microsecond)
ortime.Round(time.Microsecond)
. This can be very repetitive and is very likely to be forgotten when writing the query. Having a parameter that would truncate incomingtime.Time
values in the driver would prove useful and would remove the need to writetime.Truncate
methods every time a time value needs to be bound to an argument for MariaDB databases.Checklist
Summary by CodeRabbit
timeTruncate
configuration option allowing users to truncate time values to a specified duration.README.md
andAUTHORS
files with new configuration options and contributor details.timeTruncate
configuration.