Skip to content

Commit

Permalink
Added handling of 'text' data type + clearing instructions after go
Browse files Browse the repository at this point in the history
  • Loading branch information
carl-berg committed Mar 10, 2021
1 parent 7b991fa commit 5fc0cd9
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 2 deletions.
6 changes: 6 additions & 0 deletions DataDude.Tests/Core/Scripts/Migrations/1.0.0/01.Schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ CREATE TABLE Test_Nullable_FK(
)
GO

CREATE TABLE Test_Nullable_Text_Data_Type(
Id INT PRIMARY KEY,
Text TEXT NULL,
)
GO

CREATE TRIGGER People.EmployeeUpdatedAt ON People.Employee AFTER UPDATE AS BEGIN
UPDATE People.Employee
SET People.Employee.UpdatedAt = GETDATE()
Expand Down
33 changes: 33 additions & 0 deletions DataDude.Tests/Inserts/InstructionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,5 +279,38 @@ public async Task Can_Honor_Specified_Null_Values_When_Inserting_Nullable_FK()
firstOfficeId.ShouldBe(1);
secondOfficeId.ShouldBeNull();
}

[Fact]
public async Task Can_Handle_Nullable_Text_Data_Type()
{
using var connection = Fixture.CreateNewConnection();

await new Dude()
.Insert("Test_Nullable_Text_Data_Type")
.Go(connection);

var insertedItems = await connection.QueryAsync<(int, string)>("SELECT Id, Text FROM Test_Nullable_Text_Data_Type");
insertedItems.ShouldNotBeEmpty();
}

[Fact]
public async Task Instructions_Are_Cleared_After_Go()
{
using var connection = Fixture.CreateNewConnection();

var dude = new Dude();
await dude
.Insert("Office", new { Name = "test" })
.Go(connection);

await dude
.Insert("Employee", new { Name = "test" })
.Go(connection);

var insertedOffices = await connection.QuerySingleAsync<int>("SELECT COUNT(1) FROM Buildings.Office");
var insertedEmployees = await connection.QuerySingleAsync<int>("SELECT COUNT(1) FROM People.Employee");
insertedOffices.ShouldBe(1);
insertedEmployees.ShouldBe(1);
}
}
}
2 changes: 1 addition & 1 deletion DataDude/DataDude.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<Version>0.6.0</Version>
<Version>0.7.0</Version>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
Expand Down
1 change: 1 addition & 0 deletions DataDude/DataDudeContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public DataDudeContext(ISchemaLoader schemaLoader)
["varbinary"] = DbType.Binary,
["varchar"] = DbType.String,
["nvarchar"] = DbType.String,
["text"] = DbType.String,
["geography"] = DbType.String,
["timestamp"] = DbType.Binary,
};
Expand Down
2 changes: 2 additions & 0 deletions DataDude/Dude.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public async Task Go(IDbConnection connection, IDbTransaction? transaction = nul
throw new HandlerException($"Instruction of type '{instruction.GetType()}' lacks handler and cannot be processed");
}
}

Context.Instructions.Clear();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class StringValueProvider : ValueProvider
{
protected override ColumnValue? GetDefaultValue(ColumnInformation column, ColumnValue value)
{
if (column.DataType is "varchar" or "nvarchar")
if (column.DataType is "varchar" or "nvarchar" or "text")
{
return new ColumnValue(string.Empty);
}
Expand Down

0 comments on commit 5fc0cd9

Please sign in to comment.