Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cd40038

Browse files
committedJun 25, 2024
tmp
1 parent 6eb5df5 commit cd40038

13 files changed

+73
-109
lines changed
 

‎.editorconfig

+9-9
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ csharp_style_conditional_delegate_call = true
9393

9494
# Modifier preferences
9595
csharp_prefer_static_local_function = true
96-
csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async
96+
csharp_preferred_modifier_order = public, private, protected, internal, file, static, extern, new, virtual, abstract, sealed, override, readonly, unsafe, required, volatile, async
9797

9898
# Code-block preferences
9999
csharp_prefer_braces = true
@@ -178,24 +178,24 @@ dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
178178

179179
dotnet_naming_symbols.interface.applicable_kinds = interface
180180
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
181-
dotnet_naming_symbols.interface.required_modifiers =
181+
dotnet_naming_symbols.interface.required_modifiers =
182182

183183
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
184184
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
185-
dotnet_naming_symbols.types.required_modifiers =
185+
dotnet_naming_symbols.types.required_modifiers =
186186

187187
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
188188
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
189-
dotnet_naming_symbols.non_field_members.required_modifiers =
189+
dotnet_naming_symbols.non_field_members.required_modifiers =
190190

191191
# Naming styles
192192

193-
dotnet_naming_style.pascal_case.required_prefix =
194-
dotnet_naming_style.pascal_case.required_suffix =
195-
dotnet_naming_style.pascal_case.word_separator =
193+
dotnet_naming_style.pascal_case.required_prefix =
194+
dotnet_naming_style.pascal_case.required_suffix =
195+
dotnet_naming_style.pascal_case.word_separator =
196196
dotnet_naming_style.pascal_case.capitalization = pascal_case
197197

198198
dotnet_naming_style.begins_with_i.required_prefix = I
199-
dotnet_naming_style.begins_with_i.required_suffix =
200-
dotnet_naming_style.begins_with_i.word_separator =
199+
dotnet_naming_style.begins_with_i.required_suffix =
200+
dotnet_naming_style.begins_with_i.word_separator =
201201
dotnet_naming_style.begins_with_i.capitalization = pascal_case

‎.vscode/settings.json

-8
This file was deleted.

‎CodeGenerator/CodeGenerator.cs

+24-28
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,8 @@ namespace SqlcGenCsharp;
1313

1414
public class CodeGenerator
1515
{
16-
private static readonly char[] Separator = ['/'];
17-
private Options? _options;
1816
private DbDriver? _dbDriver;
19-
20-
private void InitGenerators(GenerateRequest generateRequest)
21-
{
22-
Options = new Options(generateRequest);
23-
DbDriver = InstantiateDriver();
24-
}
17+
private Options? _options;
2518

2619
private Options Options
2720
{
@@ -35,6 +28,12 @@ private DbDriver DbDriver
3528
set => _dbDriver = value;
3629
}
3730

31+
private void InitGenerators(GenerateRequest generateRequest)
32+
{
33+
Options = new Options(generateRequest);
34+
DbDriver = InstantiateDriver();
35+
}
36+
3837
private DbDriver InstantiateDriver()
3938
{
4039
return Options.DriverName switch
@@ -74,29 +73,18 @@ string QueryFilenameToClassName(string filenameWithExtension)
7473
Path.GetExtension(filenameWithExtension)[1..].FirstCharToUpper());
7574
}
7675
}
77-
78-
private string GenerateNamespace(GenerateRequest generateRequest)
79-
{
80-
var parts = generateRequest.Settings.Codegen.Out
81-
.Split(Separator, StringSplitOptions.RemoveEmptyEntries);
82-
return parts.Length > 0 ? parts[0] : "GeneratedNamespace";
83-
}
84-
76+
8577
private File GenerateFile(IEnumerable<Query> queries, string className)
8678
{
8779
var (requiredGems, classDeclaration) = GenerateClass(queries, className);
8880
var contents = $"""
89-
{Consts.AutoGeneratedComment}
90-
{requiredGems.Select(r => r.Build()).JoinByNewLine()}
91-
92-
{classDeclaration.Build()}
93-
""";
81+
{Consts.AutoGeneratedComment}
82+
{requiredGems.Select(r => r.Build()).JoinByNewLine()}
9483
95-
return new File
96-
{
97-
Name = $"{className.SnakeCase()}.rb",
98-
Contents = ByteString.CopyFromUtf8(contents)
99-
};
84+
{classDeclaration.Build()}
85+
""";
86+
87+
return new File { Name = $"{className.SnakeCase()}.rb", Contents = ByteString.CopyFromUtf8(contents) };
10088
}
10189

10290
private File GenerateGemfile()
@@ -144,15 +132,23 @@ private static SimpleStatement GenerateDataclass(string name, ClassMember classM
144132

145133
private SimpleStatement? GetQueryColumnsDataclass(Query query)
146134
{
147-
if (query.Columns.Count <= 0) return null;
135+
if (query.Columns.Count <= 0)
136+
{
137+
return null;
138+
}
139+
148140
return query.Columns.Count <= 0
149141
? null
150142
: GenerateDataclass(query.Name, ClassMember.Row, query.Columns, Options);
151143
}
152144

153145
private SimpleStatement? GetQueryParamsDataclass(Query query)
154146
{
155-
if (query.Params.Count <= 0) return null;
147+
if (query.Params.Count <= 0)
148+
{
149+
return null;
150+
}
151+
156152
var columns = query.Params.Select(p => p.Column);
157153
return GenerateDataclass(query.Name, ClassMember.Args, columns, Options);
158154
}

‎Drivers/Drivers.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<ItemGroup>
1010
<ProjectReference Include="..\Extensions\Extensions.csproj"/>
1111
<ProjectReference Include="..\PluginOptions\PluginOptions.csproj"/>
12-
<ProjectReference Include="..\RubySyntax\RubySyntax.csproj" />
12+
<ProjectReference Include="..\RubySyntax\RubySyntax.csproj"/>
1313
</ItemGroup>
1414

1515
</Project>

‎Drivers/MethodGen.cs

+23-18
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ public static MethodDeclaration OneDeclare(string funcName, string queryTextCons
2525
]
2626
);
2727

28-
return new MethodDeclaration(funcName, GetMethodArgs(argInterface, parameters), new List<IComposable>
29-
{
30-
new WithResource(Variable.Pool.AsProperty(), Variable.Client.AsVar(), withResourceBody)
31-
});
28+
return new MethodDeclaration(funcName, GetMethodArgs(argInterface, parameters),
29+
new List<IComposable>
30+
{
31+
new WithResource(Variable.Pool.AsProperty(), Variable.Client.AsVar(), withResourceBody)
32+
});
3233
}
3334

3435
private static string? GetMethodArgs(string argInterface, IList<Parameter> parameters)
@@ -39,7 +40,8 @@ public static MethodDeclaration OneDeclare(string funcName, string queryTextCons
3940
public static MethodDeclaration ManyDeclare(string funcName, string queryTextConstant, string argInterface,
4041
string returnInterface, IList<Parameter> parameters, IList<Column> columns)
4142
{
42-
var listAppend = new ListAppend(Variable.Entities.AsVar(), new NewObject(returnInterface, GetColumnsInitExpressions(columns)));
43+
var listAppend = new ListAppend(Variable.Entities.AsVar(),
44+
new NewObject(returnInterface, GetColumnsInitExpressions(columns)));
4345
IEnumerable<IComposable> withResourceBody = new List<IComposable>();
4446
var queryParams = GetQueryParams(argInterface, parameters);
4547
withResourceBody = withResourceBody.AppendIfNotNull(queryParams);
@@ -53,10 +55,11 @@ public static MethodDeclaration ManyDeclare(string funcName, string queryTextCon
5355
]
5456
);
5557

56-
return new MethodDeclaration(funcName, GetMethodArgs(argInterface, parameters), new List<IComposable>
57-
{
58-
new WithResource(Variable.Pool.AsProperty(), Variable.Client.AsVar(), withResourceBody)
59-
});
58+
return new MethodDeclaration(funcName, GetMethodArgs(argInterface, parameters),
59+
new List<IComposable>
60+
{
61+
new WithResource(Variable.Pool.AsProperty(), Variable.Client.AsVar(), withResourceBody)
62+
});
6063
}
6164

6265
public static MethodDeclaration ExecDeclare(string funcName, string queryTextConstant, string argInterface,
@@ -68,13 +71,14 @@ public static MethodDeclaration ExecDeclare(string funcName, string queryTextCon
6871
withResourceBody = withResourceBody.Concat(
6972
[
7073
PrepareQuery(queryTextConstant),
71-
ExecuteStmt(queryTextConstant, queryParams),
74+
ExecuteStmt(queryTextConstant, queryParams)
7275
]
7376
);
74-
return new MethodDeclaration(funcName, GetMethodArgs(argInterface, parameters), new List<IComposable>
75-
{
76-
new WithResource(Variable.Pool.AsProperty(), Variable.Client.AsVar(), withResourceBody)
77-
});
77+
return new MethodDeclaration(funcName, GetMethodArgs(argInterface, parameters),
78+
new List<IComposable>
79+
{
80+
new WithResource(Variable.Pool.AsProperty(), Variable.Client.AsVar(), withResourceBody)
81+
});
7882
}
7983

8084
public static MethodDeclaration ExecLastIdDeclare(string funcName, string queryTextConstant, string argInterface,
@@ -90,10 +94,11 @@ public static MethodDeclaration ExecLastIdDeclare(string funcName, string queryT
9094
new SimpleExpression($"return {Variable.Client.AsVar()}.last_id")
9195
]
9296
);
93-
return new MethodDeclaration(funcName, GetMethodArgs(argInterface, parameters), new List<IComposable>
94-
{
95-
new WithResource(Variable.Pool.AsProperty(), Variable.Client.AsVar(), withResourceBody)
96-
});
97+
return new MethodDeclaration(funcName, GetMethodArgs(argInterface, parameters),
98+
new List<IComposable>
99+
{
100+
new WithResource(Variable.Pool.AsProperty(), Variable.Client.AsVar(), withResourceBody)
101+
});
97102
}
98103

99104
private static SimpleStatement? GetQueryParams(string argInterface, IList<Parameter> parameters)

‎Drivers/Mysql2Driver.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@
22
using RubyCodegen;
33
using System.Collections.Generic;
44
using System.Linq;
5-
using System.Text.RegularExpressions;
65

76
namespace SqlcGenCsharp.Drivers;
87

9-
public partial class Mysql2Driver : DbDriver
8+
public class Mysql2Driver : DbDriver
109
{
1110
public override MethodDeclaration GetInitMethod()
1211
{
1312
return new MethodDeclaration("initialize", "connection_pool_params, mysql2_params",
1413
[
1514
new NewObject("ConnectionPool", [new SimpleExpression("**connection_pool_params")],
1615
new SimpleStatement("@pool", new NewObject(
17-
"Mysql2::Client", [new SimpleExpression("**mysql2_params")], null
16+
"Mysql2::Client", [new SimpleExpression("**mysql2_params")]
1817
)
1918
)
2019
)

‎Drivers/PgDriver.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public override MethodDeclaration GetInitMethod()
1313
[
1414
new NewObject("ConnectionPool", [new SimpleExpression("**connection_pool_params")],
1515
new SimpleStatement("@pool", new NewObject(
16-
"PG.connect", [new SimpleExpression("**pg_params")], null
16+
"PG.connect", [new SimpleExpression("**pg_params")]
1717
)
1818
)
1919
)

‎Extensions/RoslynExtensions.cs

-32
This file was deleted.

‎Extensions/StringExtensions.cs

+3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ public static string Indent(this string lines)
5454
private static int FirstNonWhitespaceIndex(this string input)
5555
{
5656
if (string.IsNullOrEmpty(input))
57+
{
5758
return -1;
59+
}
60+
5861
var trimmed = input.TrimStart();
5962
return trimmed.Length == 0 ? -1 : input.Length - trimmed.Length;
6063
}

‎LocalRunner/LocalRunner.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<ProjectReference Include="..\SqlcGenRuby\SqlcGenRuby.csproj" />
12+
<ProjectReference Include="..\SqlcGenRuby\SqlcGenRuby.csproj"/>
1313
</ItemGroup>
1414

1515
</Project>

‎README.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![CI](https://github.com/DaredevilOSS/sqlc-gen-csharp/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/DaredevilOSS/sqlc-gen-csharp/actions/workflows/main.yml)
1+
[![CI](https://github.com/DaredevilOSS/sqlc-gen-ruby/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/DaredevilOSS/sqlc-gen-ruby/actions/workflows/main.yml)
22

33
# sqlc-gen-ruby
44
## Usage
@@ -39,8 +39,8 @@ TBD
3939
4040
## Examples & Tests
4141
The below examples in here are automatically tested:
42-
- [MySqlConnectorExample](MySqlConnectorExample/MySqlConnectorExample.csproj)
43-
- [NpgsqlExample](NpgsqlExample/NpgsqlExample.csproj)
42+
- [MySql2Example](examples/mysql2)
43+
- [PgExample](examples/pg)
4444
4545
# Contributing
4646
## Local plugin development
@@ -54,7 +54,7 @@ Follow the instructions in each of these:
5454

5555
### Protobuf
5656
SQLC protobuf are defined in sqlc-dev/sqlc repository.
57-
Generating C# code from protocol buffer files:
57+
Generating Ruby code from protocol buffer files:
5858
```
5959
make protobuf-generate
6060
```
@@ -85,5 +85,4 @@ The release flow in this repo follows the semver conventions, building tag as `v
8585
8686
### Release structure
8787
The new created tag will create a draft release with it, in the release there will be the wasm plugin embedded in the release.<br/>
88-
> All we have left to do now is to add the changelog and publish the draft
89-
88+
> Publish the draft

‎RubySyntax/Flows.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ public string Build()
1515
}
1616
}
1717

18-
public class NewObject(string objectType, IEnumerable<SimpleExpression> initExpressions,
18+
public class NewObject(
19+
string objectType,
20+
IEnumerable<SimpleExpression> initExpressions,
1921
IComposable? bodyExpression = null) : IComposable
2022
{
2123
public string Build()

‎WasmRunner/WasmRunner.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
</PropertyGroup>
1717

1818
<ItemGroup>
19-
<ProjectReference Include="..\SqlcGenRuby\SqlcGenRuby.csproj" />
19+
<ProjectReference Include="..\SqlcGenRuby\SqlcGenRuby.csproj"/>
2020
</ItemGroup>
2121
</Project>

0 commit comments

Comments
 (0)
Please sign in to comment.