Skip to content

Commit e6becec

Browse files
committed
Sync
2 parents 8a25d60 + af50cbb commit e6becec

67 files changed

Lines changed: 2099 additions & 449 deletions

File tree

Some content is hidden

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

.github/workflows/dotnet.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Action to build and publish the project as a nuget package to github package registry
2+
3+
on:
4+
push:
5+
branches: [master]
6+
env:
7+
DOTNET_VERSION: 8.0.414
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
Version: ${{ steps.gitversion.outputs.SemVer }}
14+
CommitsSinceVersionSource: ${{ steps.gitversion.outputs.CommitsSinceVersionSource }}
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0 #fetch-depth is needed for GitVersion
20+
#Install and calculate the new version with GitVersion
21+
- name: Install GitVersion
22+
uses: gittools/actions/gitversion/setup@v3.2.1
23+
with:
24+
versionSpec: '6.0.0'
25+
26+
- name: Set Version
27+
uses: gittools/actions/gitversion/execute@v3.2.1
28+
id: gitversion # step id used as reference for output values
29+
30+
- name: Show version
31+
run: |
32+
echo "Version: ${{ steps.gitversion.outputs.SemVer }}"
33+
echo "CommitsSinceVersionSource: ${{ steps.gitversion.outputs.CommitsSinceVersionSource }}"
34+
#Build/pack the project
35+
- name: Setup .NET
36+
uses: actions/setup-dotnet@v3
37+
with:
38+
dotnet-version: ${{ env.DOTNET_VERSION }}
39+
- name: Build
40+
run: |
41+
echo "Build solution"
42+
dotnet build --configuration Release
43+
publish:
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@v4
47+
with:
48+
fetch-depth: 0
49+
- name: Setup .NET
50+
uses: actions/setup-dotnet@v3
51+
with:
52+
dotnet-version: ${{ env.DOTNET_VERSION }}
53+
run: |
54+
echo "Publish"
55+
dotnet publish ./QMap.sln -c Release --nologo -p:SkipTests=true
56+
57+
58+

.github/workflows/release.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
on:
2+
push:
3+
branches: [master]
4+
tags:
5+
- "v[0-9]+.[0-9]+.[0-9]+"
6+
7+
env:
8+
DOTNET_VERSION: 8.0.414
9+
GITHUB_TOKEN: ${{ secrets.QMap-Package-publisher }}
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
- name: Verify commit exists in master
17+
run: |
18+
git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
19+
git branch --remote --contains | grep origin/master
20+
- name: Set VERSION variable from tag
21+
run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV
22+
- name: Build
23+
run: dotnet build --configuration Release
24+
- name: Pack
25+
run: dotnet pack --configuration Release --no-build --output .
26+
- name: Puush package
27+
run: dotnet nuget push NuGet.Workflow.0.nupkg --source https://nuget.pkg.github.com/acraven/index.json --api-key ${GITHUB_TOKEN}
28+
29+
30+
31+
32+
33+
34+
35+
36+

QMap.Benchmarks/QMap.Benchmarks.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net7.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
8-
</PropertyGroup>
8+
<IsPublishable>false</IsPublishable>
9+
</PropertyGroup>
910

1011
<ItemGroup>
1112
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />

QMap.Core/Dialects/ISqlDialect.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.

QMap.Core/IQMapConnection.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
using System.Data;
1+
using QMap.Core.Dialects;
2+
using System.Data;
23

34
namespace QMap.Core
45
{
56
public interface IQMapConnection : IDbConnection
67
{
7-
8+
ISqlDialect Dialect { get; }
89
}
910
}

QMap.Core/ISqlDialect.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Data;
2+
3+
namespace QMap.Core.Dialects
4+
{
5+
public interface ISqlDialect
6+
{
7+
public string ParameterName { get; }
8+
9+
public string Quotes { get; }
10+
11+
string? Map(object? obj);
12+
13+
bool RequireMapping(object? obj);
14+
15+
/// <summary>
16+
/// Common parameters buiding for <see cref="IDbCommand"/>
17+
/// </summary>
18+
/// <param name="dbCommand">Command</param>
19+
/// <param name="name">Name of parameter</param>
20+
/// <param name="value">Value of parameter</param>
21+
/// <param name="options">Additional options for creating parameters</param>
22+
/// <returns>Command with parameter</returns>
23+
IDbDataParameter BuildParameter(ref IDbCommand dbCommand, string name, object value, params object[] options);
24+
25+
/// <summary>
26+
/// Adds parameters to command
27+
/// </summary>
28+
/// <param name="dbCommand">Command</param>
29+
/// <param name="namedParameters">Dictionary of parameters</param>
30+
/// <returns>Parametrized command</returns>
31+
IDbCommand BuildParameters(IDbCommand dbCommand, Dictionary<string, object> namedParameters);
32+
}
33+
}

QMap.Core/Mapping/IEntityMapper.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
using System.Data;
1+
using System.Collections.ObjectModel;
2+
using System.Data;
3+
using System.Reflection;
24

35
namespace QMap.Core.Mapping
46
{
57
public interface IEntityMapper
68
{
79
T Map<T>(IDataReader dataReader) where T : class, new();
10+
11+
void IsMatchToTable(IDataReader dataReader, ReadOnlyCollection<PropertyInfo> properties);
812
}
913
}

QMap.Core/QMap.Core.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7+
<PackageProjectUrl>https://github.com/ADRNV/QMap</PackageProjectUrl>
8+
<Title>$(AssemblyName)</Title>
9+
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
710
</PropertyGroup>
811

912
<ItemGroup>

QMap.Core/QMapConnectionAdapterBase.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Data;
1+
using QMap.Core.Dialects;
2+
using System.Data;
23

34
namespace QMap.Core
45
{
@@ -11,6 +12,11 @@ public QMapConnectionAdapterBase(C connection)
1112
_connection = connection;
1213
}
1314

15+
public QMapConnectionAdapterBase(C connection, ISqlDialect sqlDialect)
16+
{
17+
_connection = connection;
18+
}
19+
1420
public virtual string ConnectionString
1521
{
1622
get => _connection.ConnectionString;
@@ -24,6 +30,8 @@ public virtual string ConnectionString
2430
public virtual string Database { get => _connection.Database; }
2531
public virtual ConnectionState State { get => _connection.State; }
2632

33+
public virtual ISqlDialect Dialect => new SqlDialectBase();
34+
2735
public virtual IDbTransaction BeginTransaction()
2836
{
2937
return _connection.BeginTransaction();

QMap.Core/SqlDialectBase.cs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+

2+
using System.Data;
3+
4+
namespace QMap.Core.Dialects
5+
{
6+
public class SqlDialectBase : ISqlDialect
7+
{
8+
public string ParameterName { get => "@"; set => throw new NotImplementedException(); }
9+
public string Quotes { get => "'"; set => throw new NotImplementedException(); }
10+
11+
IQMapConnection connection { get; set; }
12+
13+
protected List<Type> _mappingTypes = new()
14+
{
15+
typeof(string),
16+
typeof(DateTime)
17+
};
18+
19+
public virtual string? Map(object? obj)
20+
{
21+
return obj switch
22+
{
23+
DateTime dateTimeObj => $"{dateTimeObj.Year}{dateTimeObj.Month}{dateTimeObj.Month}",
24+
string strObject => $"{Quotes}{strObject}{Quotes}",
25+
int intObj => intObj.ToString(),
26+
bool boolObj => boolObj.ToString(),
27+
null => null,
28+
_ => throw new InvalidOperationException($"Cant map type for {obj.GetType()}")
29+
};
30+
}
31+
32+
public bool RequireMapping(object obj)
33+
{
34+
var t = obj.GetType();
35+
return _mappingTypes.Contains(t);
36+
}
37+
38+
public virtual IDbDataParameter BuildParameter(ref IDbCommand dbCommand, string name, object value, params object[] options)
39+
{
40+
var parameter = dbCommand.CreateParameter();
41+
42+
parameter.ParameterName = name;
43+
parameter.Value = value;
44+
45+
return parameter;
46+
}
47+
48+
public virtual IDbCommand BuildParameters(IDbCommand dbCommand, Dictionary<string, object> namedParameters)
49+
{
50+
IDbCommand parametrizedCommand = dbCommand;
51+
52+
foreach (var parameterName in namedParameters.Keys)
53+
{
54+
var parameter = BuildParameter(ref dbCommand, parameterName, null);
55+
56+
parameter = AssignValueWithType(ref parameter);
57+
}
58+
59+
return dbCommand;
60+
}
61+
62+
/// <summary>
63+
/// Base parameters type to DBType mapping
64+
/// </summary>
65+
/// <param name="parameter"></param>
66+
/// <returns></returns>
67+
/// <exception cref="InvalidOperationException"></exception>
68+
protected virtual IDbDataParameter AssignValueWithType(ref IDbDataParameter parameter)
69+
{
70+
var typedParam = parameter.Value switch
71+
{
72+
DateTime dateTimeObj => parameter.DbType = DbType.DateTime,
73+
string strObject => parameter.DbType = DbType.String,
74+
Int16 => parameter.DbType = DbType.Int16,
75+
Int32 => parameter.DbType = DbType.Int32,
76+
Int64 => parameter.DbType = DbType.Int64,
77+
Decimal => parameter.DbType = DbType.Decimal,
78+
float => parameter.DbType = DbType.Double,
79+
double => parameter.DbType = DbType.Double,
80+
Guid => parameter.DbType = DbType.Guid,
81+
_ => throw new NotImplementedException()
82+
};
83+
84+
parameter.DbType = typedParam;
85+
86+
return parameter;
87+
}
88+
}
89+
}

0 commit comments

Comments
 (0)