Skip to content

Commit 2635255

Browse files
authored
fix plugin run without option field (#351)
* fix quick start * lint * fix tests
1 parent f2e985f commit 2635255

23 files changed

+47574
-2
lines changed

.github/workflows/legacy-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
shell: pwsh
6666
command: |
6767
$mysqlJob = Start-Job -ScriptBlock {
68-
choco install mysql --no-progress --version=8.4.4 -y --params "/serviceName:MySQL"
68+
choco install mysql --no-progress --version=8.4.6 -y --params "/serviceName:MySQL"
6969
return $LASTEXITCODE
7070
}
7171

PluginOptions/Options.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ public class Options
1111
public Options(GenerateRequest generateRequest)
1212
{
1313
var text = Encoding.UTF8.GetString(generateRequest.PluginOptions.ToByteArray());
14+
// handle empty options case
15+
if (text.Trim() == string.Empty)
16+
text = "{}";
17+
1418
var rawOptions = JsonSerializer.Deserialize<RawOptions>(text) ?? throw new InvalidOperationException();
1519

1620
DriverName = EngineToDriverMapping[generateRequest.Settings.Engine];
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// auto-generated by sqlc - do not edit
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
6+
namespace QuickStartMySqlDalGen;
7+
public readonly record struct Author(long Id, string Name, string? Bio);
8+
public readonly record struct Book(long Id, string Name, long AuthorId, string? Description);
9+
public readonly record struct ExtendedBio(string? AuthorName, string? Name, BiosBioType? BioType, HashSet<BiosAuthorType>? AuthorType);
10+
public enum BiosBioType
11+
{
12+
Invalid = 0, // reserved for invalid enum value
13+
Autobiography = 1,
14+
Biography = 2,
15+
Memoir = 3
16+
}
17+
18+
public static class BiosBioTypeExtensions
19+
{
20+
private static readonly Dictionary<string, BiosBioType> StringToEnum = new Dictionary<string, BiosBioType>()
21+
{
22+
[string.Empty] = BiosBioType.Invalid,
23+
["Autobiography"] = BiosBioType.Autobiography,
24+
["Biography"] = BiosBioType.Biography,
25+
["Memoir"] = BiosBioType.Memoir
26+
};
27+
public static BiosBioType ToBiosBioType(this string me)
28+
{
29+
return StringToEnum[me];
30+
}
31+
32+
public static HashSet<BiosBioType> ToBiosBioTypeSet(this string me)
33+
{
34+
return new HashSet<BiosBioType>(me.Split(',').ToList().Select(v => StringToEnum[v]));
35+
}
36+
}
37+
38+
public enum BiosAuthorType
39+
{
40+
Invalid = 0, // reserved for invalid enum value
41+
Author = 1,
42+
Editor = 2,
43+
Translator = 3
44+
}
45+
46+
public static class BiosAuthorTypeExtensions
47+
{
48+
private static readonly Dictionary<string, BiosAuthorType> StringToEnum = new Dictionary<string, BiosAuthorType>()
49+
{
50+
[string.Empty] = BiosAuthorType.Invalid,
51+
["Author"] = BiosAuthorType.Author,
52+
["Editor"] = BiosAuthorType.Editor,
53+
["Translator"] = BiosAuthorType.Translator
54+
};
55+
public static BiosAuthorType ToBiosAuthorType(this string me)
56+
{
57+
return StringToEnum[me];
58+
}
59+
60+
public static HashSet<BiosAuthorType> ToBiosAuthorTypeSet(this string me)
61+
{
62+
return new HashSet<BiosAuthorType>(me.Split(',').ToList().Select(v => StringToEnum[v]));
63+
}
64+
}

0 commit comments

Comments
 (0)