Skip to content

Commit 7721a9c

Browse files
feat: add Async suffix to generated methods by default
1 parent acd05d4 commit 7721a9c

File tree

89 files changed

+1939
-1927
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+1939
-1927
lines changed

Drivers/Generators/CopyFromDeclareGen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class CopyFromDeclareGen(DbDriver dbDriver)
99
public MemberDeclarationSyntax Generate(string queryTextConstant, string argInterface, Query query)
1010
{
1111
return ParseMemberDeclaration($$"""
12-
public async Task {{query.Name}}(List<{{argInterface}}> args)
12+
public async Task {{query.Name.ToMethodName(dbDriver.Options.WithAsyncSuffix)}}(List<{{argInterface}}> args)
1313
{
1414
{{((ICopyFrom)dbDriver).GetCopyFromImpl(query, queryTextConstant)}}
1515
}

Drivers/Generators/ExecDeclareGen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public MemberDeclarationSyntax Generate(string queryTextConstant, string argInte
1313
{
1414
var parametersStr = CommonGen.GetMethodParameterList(argInterface, query.Params);
1515
return ParseMemberDeclaration($$"""
16-
public async Task {{query.Name}}({{parametersStr}})
16+
public async Task {{query.Name.ToMethodName(dbDriver.Options.WithAsyncSuffix)}}({{parametersStr}})
1717
{
1818
{{GetMethodBody(queryTextConstant, query)}}
1919
}

Drivers/Generators/ExecLastIdDeclareGen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public MemberDeclarationSyntax Generate(string queryTextConstant, string argInte
1313
{
1414
var parametersStr = CommonGen.GetMethodParameterList(argInterface, query.Params);
1515
return ParseMemberDeclaration($$"""
16-
public async Task<{{dbDriver.GetIdColumnType(query)}}> {{query.Name}}({{parametersStr}})
16+
public async Task<{{dbDriver.GetIdColumnType(query)}}> {{query.Name.ToMethodName(dbDriver.Options.WithAsyncSuffix)}}({{parametersStr}})
1717
{
1818
{{GetMethodBody(queryTextConstant, query)}}
1919
}

Drivers/Generators/ExecRowsDeclareGen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public MemberDeclarationSyntax Generate(string queryTextConstant, string argInte
1313
{
1414
var parametersStr = CommonGen.GetMethodParameterList(argInterface, query.Params);
1515
return ParseMemberDeclaration($$"""
16-
public async Task<long> {{query.Name}}({{parametersStr}})
16+
public async Task<long> {{query.Name.ToMethodName(dbDriver.Options.WithAsyncSuffix)}}({{parametersStr}})
1717
{
1818
{{GetMethodBody(queryTextConstant, query)}}
1919
}

Drivers/Generators/ManyDeclareGen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public MemberDeclarationSyntax Generate(string queryTextConstant, string argInte
1515
var parametersStr = CommonGen.GetMethodParameterList(argInterface, query.Params);
1616
var returnType = $"Task<List<{returnInterface}>>";
1717
return ParseMemberDeclaration($$"""
18-
public async {{returnType}} {{query.Name}}({{parametersStr}})
18+
public async {{returnType}} {{query.Name.ToMethodName(dbDriver.Options.WithAsyncSuffix)}}({{parametersStr}})
1919
{
2020
{{GetMethodBody(queryTextConstant, returnInterface, query)}}
2121
}

Drivers/Generators/OneDeclareGen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public MemberDeclarationSyntax Generate(string queryTextConstant, string argInte
1515
var returnType = $"Task<{dbDriver.AddNullableSuffixIfNeeded(returnInterface, false)}>";
1616
var parametersStr = CommonGen.GetMethodParameterList(argInterface, query.Params);
1717
return ParseMemberDeclaration($$"""
18-
public async {{returnType}} {{query.Name}}({{parametersStr}})
18+
public async {{returnType}} {{query.Name.ToMethodName(dbDriver.Options.WithAsyncSuffix)}}({{parametersStr}})
1919
{
2020
{{GetMethodBody(queryTextConstant, returnInterface, query)}}
2121
}

Extensions/StringExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ public static string ToModelName(this string value, string schema, string defaul
5151
return $"{schemaName}_{value.TrimEnd('s')}".ToPascalCase(); // TODO implement better way to turn words to singular
5252
}
5353

54+
public static string ToMethodName(this string value, bool withAsyncSuffix)
55+
{
56+
var methodName = value.ToPascalCase();
57+
return withAsyncSuffix ? $"{methodName}Async" : methodName;
58+
}
59+
5460
public static string AppendSemicolonUnlessEmpty(this string input)
5561
{
5662
return input == string.Empty ? "" : $"{input};";

PluginOptions/Options.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public Options(GenerateRequest generateRequest)
2525
NamespaceName = rawOptions.NamespaceName;
2626
DotnetFramework = DotnetFrameworkExtensions.ParseName(rawOptions.TargetFramework);
2727
Overrides = rawOptions.Overrides ?? [];
28-
28+
WithAsyncSuffix = rawOptions.WithAsyncSuffix;
29+
2930
if (rawOptions.DebugRequest && generateRequest.Settings.Codegen.Wasm is not null)
3031
throw new ArgumentException("Debug request mode cannot be used with WASM plugin");
3132
DebugRequest = rawOptions.DebugRequest;
@@ -57,6 +58,8 @@ public Options(GenerateRequest generateRequest)
5758
/// </summary>
5859
public bool UseCentralPackageManagement { get; }
5960

61+
public bool WithAsyncSuffix { get; }
62+
6063
private static readonly Dictionary<string, DriverName> EngineToDriverMapping = new()
6164
{
6265
{ "mysql", DriverName.MySqlConnector },

PluginOptions/RawOptions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public record RawOptions
99
public string OverrideDriverVersion { get; init; } = string.Empty;
1010

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

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

3232
[JsonPropertyName("useCentralPackageManagement")]
3333
public bool UseCentralPackageManagement { get; init; }
34+
35+
[JsonPropertyName("withAsyncSuffix")]
36+
public bool WithAsyncSuffix { get; init; } = true;
3437
}
3538

3639
public class OverrideOption

end2end/EndToEndScaffold/Consts.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static class Consts
2020
public const string GenericQuote2 = "\"Only 2 things are infinite, the universe and human stupidity\"";
2121

2222
public static readonly string CreateBojackAuthor = $$"""
23-
await this.QuerySql.CreateAuthor(new QuerySql.CreateAuthorArgs
23+
await this.QuerySql.CreateAuthorAsync(new QuerySql.CreateAuthorArgs
2424
{
2525
Id = {{BojackId}},
2626
Name = {{BojackAuthor}},
@@ -29,23 +29,23 @@ await this.QuerySql.CreateAuthor(new QuerySql.CreateAuthorArgs
2929
""";
3030

3131
public const string CreateBojackAuthorWithId = $$"""
32-
var bojackId = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs
32+
var bojackId = await this.QuerySql.CreateAuthorReturnIdAsync(new QuerySql.CreateAuthorReturnIdArgs
3333
{
3434
Name = {{BojackAuthor}},
3535
Bio = {{BojackTheme}}
3636
});
3737
""";
3838

3939
public const string CreateBookByBojack = $$"""
40-
var bojackBookId = await QuerySql.CreateBook(new QuerySql.CreateBookArgs
40+
var bojackBookId = await QuerySql.CreateBookAsync(new QuerySql.CreateBookArgs
4141
{
4242
Name = {{BojackBookTitle}},
4343
AuthorId = bojackId
4444
});
4545
""";
4646

4747
public static readonly string CreateDrSeussAuthor = $$"""
48-
await this.QuerySql.CreateAuthor(new QuerySql.CreateAuthorArgs
48+
await this.QuerySql.CreateAuthorAsync(new QuerySql.CreateAuthorArgs
4949
{
5050
Id = {{DrSeussId}},
5151
Name = {{DrSeussAuthor}},
@@ -54,31 +54,31 @@ await this.QuerySql.CreateAuthor(new QuerySql.CreateAuthorArgs
5454
""";
5555

5656
public const string CreateDrSeussAuthorWithId = $$"""
57-
var drSeussId = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs
57+
var drSeussId = await this.QuerySql.CreateAuthorReturnIdAsync(new QuerySql.CreateAuthorReturnIdArgs
5858
{
5959
Name = {{DrSeussAuthor}},
6060
Bio = {{DrSeussQuote}}
6161
});
6262
""";
6363

6464
public const string CreateBookByDrSeuss = $$"""
65-
var drSeussBookId = await QuerySql.CreateBook(new QuerySql.CreateBookArgs
65+
var drSeussBookId = await QuerySql.CreateBookAsync(new QuerySql.CreateBookArgs
6666
{
6767
AuthorId = drSeussId,
6868
Name = {{DrSeussBookTitle}}
6969
});
7070
""";
7171

7272
public const string CreateFirstGenericAuthor = $$"""
73-
var id1 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs
73+
var id1 = await this.QuerySql.CreateAuthorReturnIdAsync(new QuerySql.CreateAuthorReturnIdArgs
7474
{
7575
Name = {{GenericAuthor}},
7676
Bio = {{GenericQuote1}}
7777
});
7878
""";
7979

8080
public const string CreateSecondGenericAuthor = $$"""
81-
var id2 = await this.QuerySql.CreateAuthorReturnId(new QuerySql.CreateAuthorReturnIdArgs
81+
var id2 = await this.QuerySql.CreateAuthorReturnIdAsync(new QuerySql.CreateAuthorReturnIdArgs
8282
{
8383
Name = {{GenericAuthor}},
8484
Bio = {{GenericQuote2}}

0 commit comments

Comments
 (0)