Skip to content

Commit 94d1d31

Browse files
author
jmd
committed
Use Template Generator and spike release to github
1 parent 179408f commit 94d1d31

25 files changed

+350
-499
lines changed

.github/workflows/build-and-test.yml

+38-6
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,22 @@ jobs:
1616
- name: Setup .NET
1717
uses: actions/setup-dotnet@v2
1818
with:
19-
dotnet-version: 6.x.x
20-
19+
dotnet-version: 8.x.x
20+
21+
- name: Calculate Version Parameters
22+
id: version
23+
run: |
24+
build=${{github.run_number}}
25+
template=`cat ./VERSION`
26+
shortsha=$(git rev-parse --short ${{ github.sha }})
27+
echo "template=$template" >> $GITHUB_OUTPUT
28+
echo "template=$template"
29+
echo "shortsha=$shortsha" >> $GITHUB_OUTPUT
30+
echo "shortsha=$shortsha"
31+
echo "semver=${template//build/$build}+sha.$shortsha" >> $GITHUB_OUTPUT
32+
echo "semver=${template//build/$build}+sha.$shortsha"
33+
echo "msver=${template//build/$build}.0" >> $GITHUB_OUTPUT
34+
echo "msver=${template//build/$build}.0"
2135
2236
# Starting the SQL Server here so that it has time to get up and running before we get to the tests, it seems doing this before the restore and build
2337
# is consistent enough.
@@ -28,16 +42,34 @@ jobs:
2842
run: dotnet restore src/DotJEM.Json.Storage2.sln
2943

3044
- name: Build
31-
run: dotnet build src/DotJEM.Json.Storage2.sln --configuration Release --no-restore
45+
working-directory: ./src
46+
run: >
47+
dotnet build --configuration Release --no-restore
48+
/p:Version=${{steps.version.outputs.semver}}
49+
/p:PackageVersion=${{steps.version.outputs.semver}}
50+
/p:AssemblyVersion=${{steps.version.outputs.msver}}
51+
/p:FileVersion=${{steps.version.outputs.msver}}
3252
3353
- name: Create Test Database
3454
run: docker exec -i sql-server /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P UUID58cf785a1c9c4bb3b62cb593d530c865! -d master -Q "CREATE DATABASE storage2test" \
3555

3656
- name: Test
37-
run: dotnet test src/DotJEM.Json.Storage2.sln --configuration Release --no-build --verbosity normal
57+
working-directory: ./src
58+
run: dotnet test --configuration Release --no-build --verbosity normal
3859
env:
3960
MSSQL_SA_PASSWORD: UUID58cf785a1c9c4bb3b62cb593d530c865!
4061
mssql_connection: "Data Source=localhost,1433; User Id=sa;;Initial Catalog=storage2test;Password=UUID58cf785a1c9c4bb3b62cb593d530c865!"
4162

42-
- name: Pack
43-
run: dotnet pack src/DotJEM.Json.Storage2.sln --configuration Release
63+
- name: Package
64+
working-directory: ./src
65+
run: >
66+
dotnet pack --configuration Release --no-restore
67+
/p:Version=${{steps.version.outputs.semver}}
68+
/p:PackageVersion=${{steps.version.outputs.semver}}
69+
/p:AssemblyVersion=${{steps.version.outputs.msver}}
70+
/p:FileVersion=${{steps.version.outputs.msver}}
71+
72+
- name: Publish
73+
if: github.event_name == 'push'
74+
working-directory: ./src
75+
run: dotnet nuget push **/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate

VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1.build

src/DotJEM.Json.Storage2.Test/DotJEM.Json.Storage2.Test.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
</PropertyGroup>

src/DotJEM.Json.Storage2.Test/SqlServerStorageAreaFactoryTest.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ public async Task EnsureLogTable_NoTableExists_ShouldCreateTables()
3131
StorageObject so3 = await area.UpdateAsync(so.Id, JObject.FromObject(new { foo = "Fax" }));
3232
Console.WriteLine(so3);
3333

34-
StorageObject? so4 = await area.GetAsync(so.Id);
34+
StorageObject so4 = await area.UpdateAsync(so.Id, JObject.FromObject(new { foo = "Foo" }));
3535
Console.WriteLine(so4);
3636

37+
StorageObject? so5 = await area.GetAsync(so.Id);
38+
Console.WriteLine(so5);
39+
3740
}
3841
}

src/DotJEM.Json.Storage2.Test/TestSqlConnectionFactory.cs

-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,5 @@ public static class TestSqlConnectionFactory
77
public static string ConnectionString =
88
Environment.GetEnvironmentVariable("mssql_connection") ??
99
"Data Source=.\\DEV;Initial Catalog=json-storage2-test;Integrated Security=True";
10-
11-
12-
1310
public static SqlConnection CreateConnection() => new (ConnectionString);
1411
}

src/DotJEM.Json.Storage2.Test/Util/ReplacerTest.cs

-29
This file was deleted.

src/DotJEM.Json.Storage2.sln

+19-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,22 @@ VisualStudioVersion = 17.1.32421.90
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotJEM.Json.Storage2", "DotJEM.Json.Storage2\DotJEM.Json.Storage2.csproj", "{4AE2A873-D73F-4029-A345-6265BA308678}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotJEM.Json.Storage2.Test", "DotJEM.Json.Storage2.Test\DotJEM.Json.Storage2.Test.csproj", "{EA688743-1005-459D-B7DF-A003F3BF2E68}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotJEM.Json.Storage2.Test", "DotJEM.Json.Storage2.Test\DotJEM.Json.Storage2.Test.csproj", "{EA688743-1005-459D-B7DF-A003F3BF2E68}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".solution", ".solution", "{F5F9E656-86A4-47D1-9A26-EE6B12AF6742}"
11+
ProjectSection(SolutionItems) = preProject
12+
..\.gitignore = ..\.gitignore
13+
..\avatar.png = ..\avatar.png
14+
..\LICENSE = ..\LICENSE
15+
..\README.md = ..\README.md
16+
EndProjectSection
17+
EndProject
18+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{4102E97B-9490-43B2-B2B4-CA028DDC1146}"
19+
EndProject
20+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{666265F2-4376-4168-86AA-822C7645660B}"
21+
ProjectSection(SolutionItems) = preProject
22+
..\.github\workflows\build-and-test.yml = ..\.github\workflows\build-and-test.yml
23+
EndProjectSection
924
EndProject
1025
Global
1126
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -25,6 +40,9 @@ Global
2540
GlobalSection(SolutionProperties) = preSolution
2641
HideSolutionNode = FALSE
2742
EndGlobalSection
43+
GlobalSection(NestedProjects) = preSolution
44+
{666265F2-4376-4168-86AA-822C7645660B} = {4102E97B-9490-43B2-B2B4-CA028DDC1146}
45+
EndGlobalSection
2846
GlobalSection(ExtensibilityGlobals) = postSolution
2947
SolutionGuid = {6A31B693-C99A-4DEA-9CA1-9EAC1607C3A2}
3048
EndGlobalSection

src/DotJEM.Json.Storage2/DotJEM.Json.Storage2.csproj

+9-36
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
5-
<!--<TargetFramework>netstandard2.0</TargetFramework>-->
6-
<LangVersion>latest</LangVersion>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<LangVersion>latest</LangVersion>
76
<ImplicitUsings>enable</ImplicitUsings>
87
<Nullable>enable</Nullable>
98
<PackageLicenseExpression>MIT</PackageLicenseExpression>
@@ -28,47 +27,21 @@
2827

2928
<PackageIcon>avatar.png</PackageIcon>
3029
<PackageReadmeFile>README.md</PackageReadmeFile>
31-
32-
<!--<ImplicitUsings>enable</ImplicitUsings>-->
33-
<!--<Nullable>enable</Nullable>-->
3430
</PropertyGroup>
3531

3632
<ItemGroup>
37-
<None Remove="SqlServer\Statements\CreateDataTable.sql" />
38-
<None Remove="SqlServer\Statements\CreateLogTable.sql" />
39-
<None Remove="SqlServer\Statements\CreateSchema.sql" />
40-
<None Remove="SqlServer\Statements\CreateSchemasTable.sql" />
41-
<None Remove="SqlServer\Statements\DeleteDataTable.sql" />
42-
<None Remove="SqlServer\Statements\InsertIntoDataTable.sql" />
43-
<None Remove="SqlServer\Statements\SelectFromDataTable.sql" />
44-
<None Remove="SqlServer\Statements\SelectSchemaExists.sql" />
45-
<None Remove="SqlServer\Statements\SelectSchemaNames.sql" />
46-
<None Remove="SqlServer\Statements\SelectTableNames.sql" />
47-
<None Remove="SqlServer\Statements\UpdateDataTable.sql" />
33+
<None Remove="SqlServer\Statements\*.sql" />
4834
</ItemGroup>
4935

5036
<ItemGroup>
51-
<EmbeddedResource Include="SqlServer\Statements\CreateSchema.sql">
52-
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
53-
</EmbeddedResource>
54-
<EmbeddedResource Include="SqlServer\Statements\CreateDataTable.sql">
55-
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
56-
</EmbeddedResource>
57-
<EmbeddedResource Include="SqlServer\Statements\CreateLogTable.sql" />
58-
<EmbeddedResource Include="SqlServer\Statements\CreateSchemasTable.sql" />
59-
<EmbeddedResource Include="SqlServer\Statements\DeleteDataTable.sql" />
60-
<EmbeddedResource Include="SqlServer\Statements\InsertIntoDataTable.sql" />
61-
<EmbeddedResource Include="SqlServer\Statements\SelectFromDataTable.sql" />
62-
<EmbeddedResource Include="SqlServer\Statements\SelectSchemaExists.sql" />
63-
<EmbeddedResource Include="SqlServer\Statements\SelectSchemaNames.sql" />
64-
<EmbeddedResource Include="SqlServer\Statements\SelectTableNames.sql" />
65-
<EmbeddedResource Include="SqlServer\Statements\UpdateDataTable.sql" />
37+
<AdditionalFiles Include="SqlServer\Statements\*.sql" TemplateClass="SqlTemplates" />
6638
</ItemGroup>
6739

68-
<ItemGroup>
69-
<PackageReference Include="Dapper" Version="2.0.123" />
70-
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
71-
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
40+
<ItemGroup>
41+
<PackageReference Include="Dapper" Version="2.1.35" />
42+
<PackageReference Include="DotJEM.SourceGen.TemplateGenerator" Version="0.1.13-beta001" />
43+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
44+
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
7245
</ItemGroup>
7346

7447
<ItemGroup>

src/DotJEM.Json.Storage2/IStorageArea.cs

+13-4
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,23 @@ public interface IStorageArea
1212
//Task<IEnumerable<StorageObject>> GetAsync();
1313
//Task<IEnumerable<StorageObject>> GetAsync(long skip, int take = 100);
1414
#else
15-
IAsyncEnumerable<StorageObject> GetAsync();
16-
IAsyncEnumerable<StorageObject> GetAsync(long skip, int take = 100);
15+
//IAsyncEnumerable<StorageObject> GetAsync();
16+
//IAsyncEnumerable<StorageObject> GetAsync(CancellationToken cancellation);
17+
//IAsyncEnumerable<StorageObject> GetAsync(long skip);
18+
//IAsyncEnumerable<StorageObject> GetAsync(long skip, CancellationToken cancellation);
19+
//IAsyncEnumerable<StorageObject> GetAsync(long skip, int take, CancellationToken cancellation);
1720
#endif
1821

1922
Task<StorageObject?> GetAsync(Guid id);
23+
Task<StorageObject?> GetAsync(Guid id, CancellationToken cancellation);
2024
Task<StorageObject> InsertAsync(string contentType, JObject obj);
21-
Task<StorageObject> InsertAsync(StorageObject obj);
25+
Task<StorageObject> InsertAsync(string contentType, JObject obj, CancellationToken cancellation);
26+
Task<StorageObject> InsertAsync(InsertStorageObject obj);
27+
Task<StorageObject> InsertAsync(InsertStorageObject obj, CancellationToken cancellation);
2228
Task<StorageObject> UpdateAsync(Guid id, JObject obj);
23-
Task<StorageObject> UpdateAsync(StorageObject obj);
29+
Task<StorageObject> UpdateAsync(Guid id, JObject obj, CancellationToken cancellation);
30+
Task<StorageObject> UpdateAsync(UpdateStorageObject obj);
31+
Task<StorageObject> UpdateAsync(UpdateStorageObject obj, CancellationToken cancellation);
2432
Task<StorageObject?> DeleteAsync(Guid id);
33+
Task<StorageObject?> DeleteAsync(Guid id, CancellationToken cancellation);
2534
}

src/DotJEM.Json.Storage2/SqlServer/Initialization/Temp.cs

+7-47
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,10 @@ public static class Temp
1212
{
1313
public static async Task<SqlServerStorageAreaFactory> Create(string schema, SqlServerConnectionFactory connectionFactory)
1414
{
15-
#if NETSTANDARD2_0
16-
using SqlConnection connection = connectionFactory.Create();
17-
await connection.OpenAsync().ConfigureAwait(false);
18-
19-
using SqlCommand command = new(SqlServerStatements.Load("SelectSchemaExists"));
20-
command.Parameters.Add("schema", SqlDbType.NVarChar).Value = schema;
21-
command.Connection = connection;
22-
23-
int schemaExists = (int)(await command.ExecuteScalarAsync().ConfigureAwait(false) ?? throw new Exception());
24-
if (schemaExists == 0)
25-
{
26-
//TODO: Needs to pass a state object to track creation of schema.
27-
return new SqlServerStorageAreaFactory(new SqlServerSchemaStateManager(connectionFactory, schema, false));
28-
}
29-
30-
using SqlCommand command2 = new(SqlServerStatements.Load("SelectTableNames"));
31-
command2.Parameters.Add(new SqlParameter("schema", SqlDbType.NVarChar)).Value = schema;
32-
command2.Connection = connection;
33-
34-
using SqlDataReader reader = await command2.ExecuteReaderAsync().ConfigureAwait(false);
35-
#else
3615
await using SqlConnection connection = connectionFactory.Create();
3716
await connection.OpenAsync().ConfigureAwait(false);
3817

39-
await using SqlCommand command = new(SqlServerStatements.Load("SelectSchemaExists"));
18+
await using SqlCommand command = new(SqlTemplates.SelectSchemaExists());
4019
command.Parameters.Add("schema", SqlDbType.NVarChar).Value = schema;
4120
command.Connection = connection;
4221

@@ -48,12 +27,12 @@ public static async Task<SqlServerStorageAreaFactory> Create(string schema, SqlS
4827
return new SqlServerStorageAreaFactory(new SqlServerSchemaStateManager(connectionFactory, schema, false));
4928
}
5029

51-
await using SqlCommand command2 = new(SqlServerStatements.Load("SelectTableNames"));
30+
await using SqlCommand command2 = new(SqlTemplates.SelectTableNames());
5231
command2.Parameters.Add(new SqlParameter("schema", SqlDbType.NVarChar)).Value = schema;
5332
command2.Connection = connection;
5433

5534
await using SqlDataReader reader = await command2.ExecuteReaderAsync().ConfigureAwait(false);
56-
#endif
35+
5736

5837
HashSet<string> names = new();
5938
while (await reader.ReadAsync())
@@ -101,20 +80,8 @@ public async Task Ensure()
10180

10281
await padlock.WaitAsync();
10382

104-
string commandText = SqlServerStatements.Load("CreateSchema", ("schema", SchemaName));
83+
string commandText = SqlTemplates.CreateSchema(SchemaName);
10584

106-
107-
#if NETSTANDARD2_0
108-
using SqlConnection connection = connectionFactory.Create();
109-
using SqlCommand command = new SqlCommand(commandText, connection);
110-
await connection.OpenAsync().ConfigureAwait(false);
111-
112-
using SqlTransaction transaction = connection.BeginTransaction(IsolationLevel.ReadUncommitted);
113-
command.Connection = connection;
114-
command.Transaction = transaction;
115-
await command.ExecuteNonQueryAsync().ConfigureAwait(false);
116-
transaction.Commit();
117-
#else
11885
await using SqlConnection connection = connectionFactory.Create();
11986
await using SqlCommand command = new SqlCommand(commandText, connection);
12087
await connection.OpenAsync().ConfigureAwait(false);
@@ -124,7 +91,6 @@ public async Task Ensure()
12491
command.Transaction = transaction;
12592
await command.ExecuteNonQueryAsync().ConfigureAwait(false);
12693
await transaction.CommitAsync().ConfigureAwait(false);
127-
#endif
12894

12995
created = true;
13096
padlock.Release();
@@ -159,15 +125,9 @@ public async Task Ensure()
159125
if (created)
160126
return;
161127

162-
Dictionary<string, string> map = new() {
163-
{ "schema", Schema },
164-
{ "data_table_name", $"{AreaName}.data" },
165-
{ "log_table_name", $"{AreaName}.log" },
166-
{ "schema_table_name", $"{AreaName}.schemas" }
167-
};
168-
string dataTableCommandText = SqlServerStatements.Load("CreateDataTable", map);
169-
string logTableCommandText = SqlServerStatements.Load("CreateLogTable", map);
170-
string schemaTableCommandText = SqlServerStatements.Load("CreateSchemasTable", map);
128+
string dataTableCommandText = SqlTemplates.CreateDataTable(Schema, AreaName);// SqlServerStatements.Load("CreateDataTable", map);
129+
string logTableCommandText = SqlTemplates.CreateLogTable(Schema, AreaName); // SqlServerStatements.Load("CreateLogTable", map);
130+
string schemaTableCommandText = SqlTemplates.CreateSchemasTable(Schema, AreaName); // SqlServerStatements.Load("CreateSchemasTable", map);
171131

172132
//await using SqlConnection connection = connectionFactory.Create();
173133
using SqlConnection connection = connectionFactory.Create();

0 commit comments

Comments
 (0)