Skip to content

Commit

Permalink
SqlHydra.Cli v2.0.2 - Set mssql DateOnly / TimeOnly params to `DA…
Browse files Browse the repository at this point in the history
…TE` / `TIME`. #58
  • Loading branch information
JordanMarr committed Jun 9, 2023
1 parent 29ad35c commit 4d38266
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/SqlHydra.Cli/SqlHydra.Cli.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Version>2.0.1</Version>
<Version>2.0.2</Version>
<WarningsAsErrors>
<!-- Incomplete pattern matches on this expression. -->
FS0025
Expand Down
4 changes: 2 additions & 2 deletions src/SqlHydra.Cli/SqlServer/SqlServerDataTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ let supportedTypeMappings =
"TEXT", "string", DbType.String, None, nameof r.GetString
"NTEXT", "string", DbType.String, None, nameof r.GetString
"DATETIMEOFFSET", "System.DateTimeOffset", DbType.DateTimeOffset, None, nameof r.GetDateTimeOffset
"DATE", "System.DateOnly", DbType.Date, None, "GetDateOnly"
"TIME", "System.TimeOnly", DbType.Time, None, "GetTimeOnly"
"DATE", "System.DateOnly", DbType.Date, Some (nameof DbType.Date), "GetDateOnly"
"TIME", "System.TimeOnly", DbType.Time, Some (nameof DbType.Time), "GetTimeOnly"
"DATETIME", "System.DateTime", DbType.DateTime, Some (nameof DbType.DateTime), nameof r.GetDateTime
"DATETIME2", "System.DateTime", DbType.DateTime2, Some (nameof DbType.DateTime2), nameof r.GetDateTime
"SMALLDATETIME", "System.DateTime", DbType.DateTime, Some (nameof DbType.DateTime), nameof r.GetDateTime
Expand Down
6 changes: 6 additions & 0 deletions src/Tests/SqlServer/AdventureWorksNet6.fs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ module HumanResources =
LoginID: string
OrganizationLevel: Option<int16>
JobTitle: string
[<SqlHydra.ProviderDbType("Date")>]
BirthDate: System.DateOnly
MaritalStatus: string
Gender: string
[<SqlHydra.ProviderDbType("Date")>]
HireDate: System.DateOnly
SalariedFlag: bool
VacationHours: int16
Expand All @@ -68,7 +70,9 @@ module HumanResources =
{ BusinessEntityID: int
DepartmentID: int16
ShiftID: byte
[<SqlHydra.ProviderDbType("Date")>]
StartDate: System.DateOnly
[<SqlHydra.ProviderDbType("Date")>]
EndDate: Option<System.DateOnly>
[<SqlHydra.ProviderDbType("DateTime")>]
ModifiedDate: System.DateTime }
Expand Down Expand Up @@ -100,7 +104,9 @@ module HumanResources =
type Shift =
{ ShiftID: byte
Name: string
[<SqlHydra.ProviderDbType("Time")>]
StartTime: System.TimeOnly
[<SqlHydra.ProviderDbType("Time")>]
EndTime: System.TimeOnly
[<SqlHydra.ProviderDbType("DateTime")>]
ModifiedDate: System.DateTime }
Expand Down
6 changes: 6 additions & 0 deletions src/Tests/SqlServer/AdventureWorksNet7.fs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ module HumanResources =
LoginID: string
OrganizationLevel: Option<int16>
JobTitle: string
[<SqlHydra.ProviderDbType("Date")>]
BirthDate: System.DateOnly
MaritalStatus: string
Gender: string
[<SqlHydra.ProviderDbType("Date")>]
HireDate: System.DateOnly
SalariedFlag: bool
VacationHours: int16
Expand All @@ -68,7 +70,9 @@ module HumanResources =
{ BusinessEntityID: int
DepartmentID: int16
ShiftID: byte
[<SqlHydra.ProviderDbType("Date")>]
StartDate: System.DateOnly
[<SqlHydra.ProviderDbType("Date")>]
EndDate: Option<System.DateOnly>
[<SqlHydra.ProviderDbType("DateTime")>]
ModifiedDate: System.DateTime }
Expand Down Expand Up @@ -100,7 +104,9 @@ module HumanResources =
type Shift =
{ ShiftID: byte
Name: string
[<SqlHydra.ProviderDbType("Time")>]
StartTime: System.TimeOnly
[<SqlHydra.ProviderDbType("Time")>]
EndTime: System.TimeOnly
[<SqlHydra.ProviderDbType("DateTime")>]
ModifiedDate: System.DateTime }
Expand Down
78 changes: 61 additions & 17 deletions src/Tests/SqlServer/QueryIntegrationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -577,23 +577,6 @@ let tests =
gt0 employeeBirthDates
}

testTask "Query Shift with TimeOnly" {
use ctx = openContext()

let minStartTime = System.TimeOnly(9, 30)

let shiftsAfter930AM =
select {
for s in HumanResources.Shift do
where (s.StartTime >= minStartTime)
}
|> ctx.Read HydraReader.Read

// There are 3 shifts: day, evening and night.
// Results should contain 2 shifts: evening and night
gt0 shiftsAfter930AM
}

testTask "Update Employee DateOnly" {
use ctx = openContext()
ctx.BeginTransaction()
Expand Down Expand Up @@ -634,6 +617,67 @@ let tests =
ctx.RollbackTransaction()
}

testTask "Query Shift Record with TimeOnly" {
use ctx = openContext()

let minStartTime = System.TimeOnly(9, 30)

let shiftsAfter930AM =
select {
for s in HumanResources.Shift do
where (s.StartTime >= minStartTime)
}
|> ctx.Read HydraReader.Read

// There are 3 shifts: day, evening and night.
// Results should contain 2 shifts: evening and night
gt0 shiftsAfter930AM
}

testTask "Query Shift Column with TimeOnly" {
use ctx = openContext()

let minStartTime = System.TimeOnly(9, 30)

let shiftsAfter930AM =
select {
for s in HumanResources.Shift do
where (s.StartTime >= minStartTime)
select s.StartTime
}
|> ctx.Read HydraReader.Read

// There are 3 shifts: day, evening and night.
// Results should contain 2 shifts: evening and night
gt0 shiftsAfter930AM
}

testTask "Update Shift with TimeOnly" {
use ctx = openContext()
ctx.BeginTransaction()

let minStartTime = System.TimeOnly(9, 30)
let updatedStartTime = System.TimeOnly(10, 30)

do! updateTask (Shared ctx) {
for s in HumanResources.Shift do
set s.StartTime updatedStartTime
where (s.StartTime >= minStartTime)
}

let! shiftsat1030AM =
selectTask HydraReader.Read (Shared ctx) {
for s in HumanResources.Shift do
where (s.StartTime = updatedStartTime)
}

// There are 3 shifts: day, evening and night.
// Results should contain 2 shifts: evening and night
gt0 shiftsat1030AM

ctx.RollbackTransaction()
}

testTask "Insert, update, and select with both datetime and datetime2 precision" {
use ctx = openContext ()
ctx.BeginTransaction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ module HumanResources =
LoginID: string
OrganizationLevel: Option<int16>
JobTitle: string
[<SqlHydra.ProviderDbType("Date")>]
BirthDate: System.DateOnly
MaritalStatus: string
Gender: string
[<SqlHydra.ProviderDbType("Date")>]
HireDate: System.DateOnly
SalariedFlag: bool
VacationHours: int16
Expand All @@ -63,7 +65,9 @@ module HumanResources =
{ BusinessEntityID: int
DepartmentID: int16
ShiftID: byte
[<SqlHydra.ProviderDbType("Date")>]
StartDate: System.DateOnly
[<SqlHydra.ProviderDbType("Date")>]
EndDate: Option<System.DateOnly>
[<SqlHydra.ProviderDbType("DateTime")>]
ModifiedDate: System.DateTime }
Expand All @@ -89,7 +93,9 @@ module HumanResources =
type Shift =
{ ShiftID: byte
Name: string
[<SqlHydra.ProviderDbType("Time")>]
StartTime: System.TimeOnly
[<SqlHydra.ProviderDbType("Time")>]
EndTime: System.TimeOnly
[<SqlHydra.ProviderDbType("DateTime")>]
ModifiedDate: System.DateTime }
Expand Down Expand Up @@ -125,6 +131,7 @@ module HumanResources =
JobTitle: string
Department: string
GroupName: string
[<SqlHydra.ProviderDbType("Date")>]
StartDate: System.DateOnly }

[<CLIMutable>]
Expand All @@ -138,7 +145,9 @@ module HumanResources =
Shift: string
Department: string
GroupName: string
[<SqlHydra.ProviderDbType("Date")>]
StartDate: System.DateOnly
[<SqlHydra.ProviderDbType("Date")>]
EndDate: Option<System.DateOnly> }

[<CLIMutable>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ module HumanResources =
LoginID: string
OrganizationLevel: Option<int16>
JobTitle: string
[<SqlHydra.ProviderDbType("Date")>]
BirthDate: System.DateOnly
MaritalStatus: string
Gender: string
[<SqlHydra.ProviderDbType("Date")>]
HireDate: System.DateOnly
SalariedFlag: bool
VacationHours: int16
Expand All @@ -63,7 +65,9 @@ module HumanResources =
{ BusinessEntityID: int
DepartmentID: int16
ShiftID: byte
[<SqlHydra.ProviderDbType("Date")>]
StartDate: System.DateOnly
[<SqlHydra.ProviderDbType("Date")>]
EndDate: Option<System.DateOnly>
[<SqlHydra.ProviderDbType("DateTime")>]
ModifiedDate: System.DateTime }
Expand All @@ -89,7 +93,9 @@ module HumanResources =
type Shift =
{ ShiftID: byte
Name: string
[<SqlHydra.ProviderDbType("Time")>]
StartTime: System.TimeOnly
[<SqlHydra.ProviderDbType("Time")>]
EndTime: System.TimeOnly
[<SqlHydra.ProviderDbType("DateTime")>]
ModifiedDate: System.DateTime }
Expand Down Expand Up @@ -125,6 +131,7 @@ module HumanResources =
JobTitle: string
Department: string
GroupName: string
[<SqlHydra.ProviderDbType("Date")>]
StartDate: System.DateOnly }

[<CLIMutable>]
Expand All @@ -138,7 +145,9 @@ module HumanResources =
Shift: string
Department: string
GroupName: string
[<SqlHydra.ProviderDbType("Date")>]
StartDate: System.DateOnly
[<SqlHydra.ProviderDbType("Date")>]
EndDate: Option<System.DateOnly> }

[<CLIMutable>]
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<PackageReference Include="Verify.Expecto" Version="19.12.1" />
<PackageReference Include="YoloDev.Expecto.TestSdk" Version="0.13.3" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="4.0.0" Condition="'$(TargetFramework)' == 'net6.0'" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.0.1" Condition="'$(TargetFramework)' == 'net7.0'" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.1" Condition="'$(TargetFramework)' == 'net7.0'" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SqlHydra.Query\SqlHydra.Query.fsproj" />
Expand Down

0 comments on commit 4d38266

Please sign in to comment.