forked from DapperLib/DapperAOT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: support DbString in DapperAOT (DapperLib#119)
* start * add dbstring example to query * create test * start processing * support DbString! * last checks * regenerate for netfx * fix DAP44 error appeared in refactor * pre-review fixes * change DbString configuration method declaration * address initial comments * DbStringHelpers to file class * include `file` via preprocessor directive * only in dapper AOT * move to Dapper.AOT.Test.Integration.csproj * setup the infra for test * test is executed targeting docker db * remove debug * some other tries * Revert "some other tries" This reverts commit a95b6ff. * Revert "remove debug" This reverts commit 44e37d0. * Revert "test is executed targeting docker db" This reverts commit c5a4fee. * Revert "setup the infra for test" This reverts commit 63fd1a9. * Revert "move to Dapper.AOT.Test.Integration.csproj" This reverts commit e804648. * address PR comments * adjust a test * use global:: for DapperSpecialType
- Loading branch information
1 parent
42778fa
commit 21b383a
Showing
22 changed files
with
927 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# DAP048 | ||
|
||
[DbString](https://github.com/DapperLib/Dapper/blob/main/Dapper/DbString.cs) causes heap allocations, but achieves the same as | ||
[DbValueAttribute](https://github.com/DapperLib/DapperAOT/blob/main/src/Dapper.AOT/DbValueAttribute.cs). | ||
|
||
Bad: | ||
|
||
``` c# | ||
public void DapperCode(DbConnection conn) | ||
{ | ||
var sql = "SELECT COUNT(*) FROM Foo WHERE Name = @Name;"; | ||
var cars = conn.Query<int>(sql, | ||
new | ||
{ | ||
Name = new DbString | ||
{ | ||
Value = "MyFoo", | ||
IsFixedLength = false, | ||
Length = 5, | ||
IsAnsi = true | ||
} | ||
}); | ||
} | ||
``` | ||
|
||
Good: | ||
|
||
``` c# | ||
public void DapperCode(DbConnection conn) | ||
{ | ||
var sql = "SELECT COUNT(*) FROM Foo WHERE Name = @Name;"; | ||
var cars = conn.Query<int>(sql, | ||
new MyPoco | ||
{ | ||
Name = "MyFoo" | ||
}); | ||
} | ||
|
||
class MyPoco | ||
{ | ||
[DbValue(Length = 5, DbType = DbType.AnsiStringFixedLength)] // specify properties here | ||
public string Name { get; set; } | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/Dapper.AOT.Analyzers/CodeAnalysis/Extensions/IncludedGenerationExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Dapper.CodeAnalysis.Extensions | ||
{ | ||
internal static class IncludedGenerationExtensions | ||
{ | ||
public static bool HasAny(this IncludedGeneration value, IncludedGeneration flag) => (value & flag) != 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace Dapper.CodeAnalysis | ||
{ | ||
/// <summary> | ||
/// Contains data about current generation run. | ||
/// </summary> | ||
internal class GeneratorContext | ||
{ | ||
/// <summary> | ||
/// Specifies which generation types should be included in the output. | ||
/// </summary> | ||
public IncludedGeneration IncludedGenerationTypes { get; private set; } | ||
|
||
public GeneratorContext() | ||
{ | ||
// set default included generation types here | ||
IncludedGenerationTypes = IncludedGeneration.InterceptsLocationAttribute; | ||
} | ||
|
||
/// <summary> | ||
/// Adds another generation type to the list of already included types. | ||
/// </summary> | ||
/// <param name="anotherType">another generation type to include in the output</param> | ||
public void IncludeGenerationType(IncludedGeneration anotherType) | ||
{ | ||
IncludedGenerationTypes |= anotherType; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 25 additions & 11 deletions
36
...rs/InterceptorsLocationAttributeWriter.cs → ...nalysis/Writers/PreGeneratedCodeWriter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.