Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/legacy-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ jobs:

steps:
- uses: actions/checkout@v4

- name: Set up .NET from global.json
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json

- name: Load .env file
uses: xom9ikk/dotenv@v2.3.0
Expand Down
2 changes: 1 addition & 1 deletion Drivers/Generators/CopyFromDeclareGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class CopyFromDeclareGen(DbDriver dbDriver)
public MemberDeclarationSyntax Generate(string queryTextConstant, string argInterface, Query query)
{
return ParseMemberDeclaration($$"""
public async Task {{query.Name}}(List<{{argInterface}}> args)
public async Task {{query.Name.ToMethodName(dbDriver.Options.WithAsyncSuffix)}}(List<{{argInterface}}> args)
{
{{((ICopyFrom)dbDriver).GetCopyFromImpl(query, queryTextConstant)}}
}
Expand Down
2 changes: 1 addition & 1 deletion Drivers/Generators/ExecDeclareGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public MemberDeclarationSyntax Generate(string queryTextConstant, string argInte
{
var parametersStr = CommonGen.GetMethodParameterList(argInterface, query.Params);
return ParseMemberDeclaration($$"""
public async Task {{query.Name}}({{parametersStr}})
public async Task {{query.Name.ToMethodName(dbDriver.Options.WithAsyncSuffix)}}({{parametersStr}})
{
{{GetMethodBody(queryTextConstant, query)}}
}
Expand Down
2 changes: 1 addition & 1 deletion Drivers/Generators/ExecLastIdDeclareGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public MemberDeclarationSyntax Generate(string queryTextConstant, string argInte
{
var parametersStr = CommonGen.GetMethodParameterList(argInterface, query.Params);
return ParseMemberDeclaration($$"""
public async Task<{{dbDriver.GetIdColumnType(query)}}> {{query.Name}}({{parametersStr}})
public async Task<{{dbDriver.GetIdColumnType(query)}}> {{query.Name.ToMethodName(dbDriver.Options.WithAsyncSuffix)}}({{parametersStr}})
{
{{GetMethodBody(queryTextConstant, query)}}
}
Expand Down
2 changes: 1 addition & 1 deletion Drivers/Generators/ExecRowsDeclareGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public MemberDeclarationSyntax Generate(string queryTextConstant, string argInte
{
var parametersStr = CommonGen.GetMethodParameterList(argInterface, query.Params);
return ParseMemberDeclaration($$"""
public async Task<long> {{query.Name}}({{parametersStr}})
public async Task<long> {{query.Name.ToMethodName(dbDriver.Options.WithAsyncSuffix)}}({{parametersStr}})
{
{{GetMethodBody(queryTextConstant, query)}}
}
Expand Down
2 changes: 1 addition & 1 deletion Drivers/Generators/ManyDeclareGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public MemberDeclarationSyntax Generate(string queryTextConstant, string argInte
var parametersStr = CommonGen.GetMethodParameterList(argInterface, query.Params);
var returnType = $"Task<List<{returnInterface}>>";
return ParseMemberDeclaration($$"""
public async {{returnType}} {{query.Name}}({{parametersStr}})
public async {{returnType}} {{query.Name.ToMethodName(dbDriver.Options.WithAsyncSuffix)}}({{parametersStr}})
{
{{GetMethodBody(queryTextConstant, returnInterface, query)}}
}
Expand Down
2 changes: 1 addition & 1 deletion Drivers/Generators/OneDeclareGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public MemberDeclarationSyntax Generate(string queryTextConstant, string argInte
var returnType = $"Task<{dbDriver.AddNullableSuffixIfNeeded(returnInterface, false)}>";
var parametersStr = CommonGen.GetMethodParameterList(argInterface, query.Params);
return ParseMemberDeclaration($$"""
public async {{returnType}} {{query.Name}}({{parametersStr}})
public async {{returnType}} {{query.Name.ToMethodName(dbDriver.Options.WithAsyncSuffix)}}({{parametersStr}})
{
{{GetMethodBody(queryTextConstant, returnInterface, query)}}
}
Expand Down
6 changes: 6 additions & 0 deletions Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public static string ToModelName(this string value, string schema, string defaul
return $"{schemaName}_{value.TrimEnd('s')}".ToPascalCase(); // TODO implement better way to turn words to singular
}

public static string ToMethodName(this string value, bool withAsyncSuffix)
{
var methodName = value.ToPascalCase();
return withAsyncSuffix ? $"{methodName}Async" : methodName;
}

public static string AppendSemicolonUnlessEmpty(this string input)
{
return input == string.Empty ? "" : $"{input};";
Expand Down
3 changes: 3 additions & 0 deletions PluginOptions/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public Options(GenerateRequest generateRequest)
NamespaceName = rawOptions.NamespaceName;
DotnetFramework = DotnetFrameworkExtensions.ParseName(rawOptions.TargetFramework);
Overrides = rawOptions.Overrides ?? [];
WithAsyncSuffix = rawOptions.WithAsyncSuffix;

if (rawOptions.DebugRequest && generateRequest.Settings.Codegen.Wasm is not null)
throw new ArgumentException("Debug request mode cannot be used with WASM plugin");
Expand Down Expand Up @@ -57,6 +58,8 @@ public Options(GenerateRequest generateRequest)
/// </summary>
public bool UseCentralPackageManagement { get; }

public bool WithAsyncSuffix { get; }

private static readonly Dictionary<string, DriverName> EngineToDriverMapping = new()
{
{ "mysql", DriverName.MySqlConnector },
Expand Down
5 changes: 4 additions & 1 deletion PluginOptions/RawOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public record RawOptions
public string OverrideDriverVersion { get; init; } = string.Empty;

[JsonPropertyName("generateCsproj")]
public bool GenerateCsproj { get; init; } = true; // generating .csproj files by default
public bool GenerateCsproj { get; init; } = true;

[JsonPropertyName("targetFramework")]
public string TargetFramework { get; init; } = DotnetFramework.Dotnet80.ToName();
Expand All @@ -31,6 +31,9 @@ public record RawOptions

[JsonPropertyName("useCentralPackageManagement")]
public bool UseCentralPackageManagement { get; init; }

[JsonPropertyName("withAsyncSuffix")]
public bool WithAsyncSuffix { get; init; } = true;
}

public class OverrideOption
Expand Down
1 change: 1 addition & 0 deletions docs/03_Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
| overrideDapperVersion | default:<br/> `2.1.35`<br/>values: The desired Dapper version | Yes | If `useDapper` is set to `true`, this option allows you to override the version of Dapper to be used. |
| Override | values: A nested override value like [this](#override-option). | Yes | Allows you to override the generated C# data types for specific columns in specific queries. This option accepts a `query_name:column_name` mapping and the overriden data type. | |
| useCentralPackageManagement | default: `false`<br/>values: `false`,`true` | Yes | If true, the code is generated to support central package management. |
| withAsyncSuffix | default: `true`<br/>values: `false`,`true` | Yes | When true, async methods will have the "Async" suffix appended to their names (e.g., `GetAuthorAsync`). When false, async methods will not have the suffix (e.g., `GetAuthor`). |

### Override option
Override for a specific query:
Expand Down
16 changes: 8 additions & 8 deletions end2end/EndToEndScaffold/Consts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static class Consts
public const string GenericQuote2 = "\"Only 2 things are infinite, the universe and human stupidity\"";

public static readonly string CreateBojackAuthor = $$"""
await this.QuerySql.CreateAuthor(new QuerySql.CreateAuthorArgs
await this.QuerySql.CreateAuthorAsync(new QuerySql.CreateAuthorArgs
{
Id = {{BojackId}},
Name = {{BojackAuthor}},
Expand All @@ -29,23 +29,23 @@ await this.QuerySql.CreateAuthor(new QuerySql.CreateAuthorArgs
""";

public const string CreateBojackAuthorWithId = $$"""
var bojackId = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs
var bojackId = await this.QuerySql.CreateAuthorReturnIdAsync(new QuerySql.CreateAuthorReturnIdArgs
{
Name = {{BojackAuthor}},
Bio = {{BojackTheme}}
});
""";

public const string CreateBookByBojack = $$"""
var bojackBookId = await QuerySql.CreateBook(new QuerySql.CreateBookArgs
var bojackBookId = await QuerySql.CreateBookAsync(new QuerySql.CreateBookArgs
{
Name = {{BojackBookTitle}},
AuthorId = bojackId
});
""";

public static readonly string CreateDrSeussAuthor = $$"""
await this.QuerySql.CreateAuthor(new QuerySql.CreateAuthorArgs
await this.QuerySql.CreateAuthorAsync(new QuerySql.CreateAuthorArgs
{
Id = {{DrSeussId}},
Name = {{DrSeussAuthor}},
Expand All @@ -54,31 +54,31 @@ await this.QuerySql.CreateAuthor(new QuerySql.CreateAuthorArgs
""";

public const string CreateDrSeussAuthorWithId = $$"""
var drSeussId = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs
var drSeussId = await this.QuerySql.CreateAuthorReturnIdAsync(new QuerySql.CreateAuthorReturnIdArgs
{
Name = {{DrSeussAuthor}},
Bio = {{DrSeussQuote}}
});
""";

public const string CreateBookByDrSeuss = $$"""
var drSeussBookId = await QuerySql.CreateBook(new QuerySql.CreateBookArgs
var drSeussBookId = await QuerySql.CreateBookAsync(new QuerySql.CreateBookArgs
{
AuthorId = drSeussId,
Name = {{DrSeussBookTitle}}
});
""";

public const string CreateFirstGenericAuthor = $$"""
var id1 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs
var id1 = await this.QuerySql.CreateAuthorReturnIdAsync(new QuerySql.CreateAuthorReturnIdArgs
{
Name = {{GenericAuthor}},
Bio = {{GenericQuote1}}
});
""";

public const string CreateSecondGenericAuthor = $$"""
var id2 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs
var id2 = await this.QuerySql.CreateAuthorReturnIdAsync(new QuerySql.CreateAuthorReturnIdArgs
{
Name = {{GenericAuthor}},
Bio = {{GenericQuote2}}
Expand Down
24 changes: 12 additions & 12 deletions end2end/EndToEndScaffold/Templates/AnnotationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static class AnnotationTests
{
Impl = $$"""
[Test]
public async Task TestOne()
public async Task TestOneAsync()
{
{{Consts.CreateBojackAuthor}}
{{Consts.CreateDrSeussAuthor}}
Expand All @@ -22,7 +22,7 @@ public async Task TestOne()
Name = {{Consts.BojackAuthor}},
Bio = {{Consts.BojackTheme}}
};
var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs
var actual = await this.QuerySql.GetAuthorAsync(new QuerySql.GetAuthorArgs
{
Name = {{Consts.BojackAuthor}}
});
Expand All @@ -41,7 +41,7 @@ void AssertSingularEquals(QuerySql.GetAuthorRow x, QuerySql.GetAuthorRow y)
{
Impl = $$"""
[Test]
public async Task TestMany()
public async Task TestManyAsync()
{
{{Consts.CreateBojackAuthor}}
{{Consts.CreateDrSeussAuthor}}
Expand All @@ -60,7 +60,7 @@ public async Task TestMany()
Bio = {{Consts.DrSeussQuote}}
}
};
var actual = await this.QuerySql.ListAuthors(new QuerySql.ListAuthorsArgs
var actual = await this.QuerySql.ListAuthorsAsync(new QuerySql.ListAuthorsArgs
{
Limit = 2,
Offset = 0
Expand All @@ -87,15 +87,15 @@ void AssertSequenceEquals(List<QuerySql.ListAuthorsRow> x, List<QuerySql.ListAut
{
Impl = $$"""
[Test]
public async Task TestExec()
public async Task TestExecAsync()
{
{{Consts.CreateBojackAuthor}}
{{Consts.CreateDrSeussAuthor}}
await this.QuerySql.DeleteAuthor(new QuerySql.DeleteAuthorArgs
await this.QuerySql.DeleteAuthorAsync(new QuerySql.DeleteAuthorArgs
{
Name = {{Consts.BojackAuthor}}
});
var actual = await this.QuerySql.GetAuthor(new QuerySql.GetAuthorArgs
var actual = await this.QuerySql.GetAuthorAsync(new QuerySql.GetAuthorArgs
{
Name = {{Consts.BojackAuthor}}
});
Expand All @@ -107,11 +107,11 @@ await this.QuerySql.DeleteAuthor(new QuerySql.DeleteAuthorArgs
{
Impl = $$"""
[Test]
public async Task TestExecRows()
public async Task TestExecRowsAsync()
{
{{Consts.CreateBojackAuthor}}
{{Consts.CreateDrSeussAuthor}}
var affectedRows = await this.QuerySql.UpdateAuthors(new QuerySql.UpdateAuthorsArgs
var affectedRows = await this.QuerySql.UpdateAuthorsAsync(new QuerySql.UpdateAuthorsArgs
{
Bio = {{Consts.GenericQuote1}}
});
Expand All @@ -131,7 +131,7 @@ public async Task TestExecRows()
Bio = {{Consts.GenericQuote1}}
}
};
var actual = await this.QuerySql.ListAuthors(new QuerySql.ListAuthorsArgs
var actual = await this.QuerySql.ListAuthorsAsync(new QuerySql.ListAuthorsArgs
{
Limit = 2,
Offset = 0
Expand All @@ -158,7 +158,7 @@ void AssertSequenceEquals(List<QuerySql.ListAuthorsRow> x, List<QuerySql.ListAut
{
Impl = $$"""
[Test]
public async Task TestExecLastId()
public async Task TestExecLastIdAsync()
{
{{Consts.CreateFirstGenericAuthor}}
var expected = new QuerySql.GetAuthorByIdRow
Expand All @@ -167,7 +167,7 @@ public async Task TestExecLastId()
Name = {{Consts.GenericAuthor}},
Bio = {{Consts.GenericQuote1}}
};
var actual = await QuerySql.GetAuthorById(new QuerySql.GetAuthorByIdArgs
var actual = await QuerySql.GetAuthorByIdAsync(new QuerySql.GetAuthorByIdArgs
{
Id = id1
});
Expand Down
Loading