DapperAOT icon indicating copy to clipboard operation
DapperAOT copied to clipboard

feat: `DateOnly` and `TimeOnly` support

Open DeagleGross opened this issue 1 year ago • 0 comments

In .NET6 DateOnly and TimeOnly were introduced. Current PR proposes support for those in Dapper.AOT.

I performed testing against MsSql and PostgreSql. Check DateOnlyTimeOnlyTests.cs for validating how data is being parsed from database via System.Data.Common.DbDataReader.

Here is how data is parsed and how I convert it:

SQL db-type c# type DbDataReader.GetValue() returns how converted notes
Postgre timestamp DateTime DateTime Convert.ToDateTime() ...
MsSql datetime DateTime DateTime Convert.ToDateTime() the only difference between Postgre and MsSql - name of "timestamp" type
Postgre timestamp DateOnly DateTime Convert.ToDateTime() -> DateOnly.FromDateTime() ...
Postgre timestamp TimeOnly DateTime Convert.ToDateTime() -> TimeOnly.FromDateTime() ...
-------
Postgre date DateTime DateTime Convert.ToDateTime() technically date is a datetime as well, so left as is
Postgre date DateOnly DateTime Convert.ToDateTime() -> DateOnly.FromDateTime()
Postgre date TimeOnly DateTime Convert.ToDateTime() -> TimeOnly.FromDateTime() will always return default(TimeOnly). Dont know if it is better to explicitly throw here?
-------
Postgre time DateTime TimeSpan Convert.ToDateTime() throws InvalidCastException TimeOnly can't be a DateTime
Postgre time DateOnly TimeSpan Convert.ToDateTime() throws InvalidCastException TimeOnly can't be a DateOnly
Postgre time TimeOnly TimeSpan cast object arg to TimeSpan -> TimeOnly.FromTimeSpan()

I have adjusted the implementation of CommandUtils.As<T> according to the table above, and then wrote integration tests (only for postgreSql).

Note: I also wrote a code to exclude non-compatible input files for unit Interceptors tests (we dont need to run .netFx tests against DateOnly.input.cs, because .netFx does not support DateOnly and TimeOnly types).

Closes #116

DeagleGross avatar Sep 21 '24 14:09 DeagleGross