Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Elanis committed Oct 17, 2019
2 parents 3d3f5da + a6b0696 commit 4f0457e
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 13 deletions.
91 changes: 91 additions & 0 deletions Dysnomia.Common.SQL/DbHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
MIT License
Copyright (c) 2019 Axel "Elanis" Soupé
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
using System.Collections.Generic;
using System.Data;
using System.Threading.Tasks;

namespace Dysnomia.Common.SQL {
public static class DbHelper {
private static void BindParameters(IDbCommand command, Dictionary<string, object> parametersData) {
if(parametersData != null) {
foreach(KeyValuePair<string, object> kvp in parametersData) {
var parameter = command.CreateParameter();
parameter.ParameterName = kvp.Key;
parameter.Value = kvp.Value;

command.Parameters.Add(parameter);
}
}
}

private static void OpenConnection(IDbConnection connection) {
if(connection.State == ConnectionState.Broken) {
connection.Close();
}

if(connection.State == ConnectionState.Closed) {
connection.Open();
}
}

public async static Task<IDataReader> ExecStoredProcedure(IDbConnection connection, string procName, Dictionary<string, object> parameters = null) {
using(IDbCommand command = connection.CreateCommand()) {
command.CommandType = CommandType.StoredProcedure;
command.CommandText = procName;

OpenConnection(command.Connection);

BindParameters(command, parameters);

return await Task.Run(() => command.ExecuteReader());
}
}

public async static Task<IDataReader> ExecuteQuery(IDbConnection connection, string sqlStatement, Dictionary<string, object> parameters = null) {
using(IDbCommand command = connection.CreateCommand()) {
command.CommandType = CommandType.Text;
command.CommandText = sqlStatement;

OpenConnection(command.Connection);

BindParameters(command, parameters);

return await Task.Run(() => command.ExecuteReader());
}
}

public async static Task<int> ExecuteNonQuery(IDbConnection connection, string sqlStatement, Dictionary<string, object> parameters = null) {
using(IDbCommand command = connection.CreateCommand()) {
command.CommandType = CommandType.Text;
command.CommandText = sqlStatement;

OpenConnection(command.Connection);

BindParameters(command, parameters);

return await Task.Run(() => command.ExecuteNonQuery());
}
}
}
}
4 changes: 2 additions & 2 deletions Dysnomia.Common.SQL/DbReaderMapper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
MIT License
Copyright (c) 2019 Axel "Elanis" Soupé
Expand All @@ -20,7 +20,7 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
*/
using System;
using System.Data;

Expand Down
16 changes: 6 additions & 10 deletions Dysnomia.Common.SQL/Dysnomia.Common.SQL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@
<TargetFrameworks>netcoreapp2.0;netcoreapp2.1;netcoreapp2.2;netcoreapp3.0</TargetFrameworks>
<Authors>Axel "Elanis" Soupé</Authors>
<Company>Dysnomia</Company>
<Description>A .NET Core Micro-ORM for PostgreSQL &amp; SQL Server</Description>
<Description>A driver agnostic Micro-ORM for .NET Core</Description>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageProjectUrl>https://github.com/Dysnomia-Studio/Dysnomia.Common.SQL</PackageProjectUrl>
<RepositoryUrl>https://github.com/Dysnomia-Studio/Dysnomia.Common.SQL</RepositoryUrl>
<RepositoryType>Github</RepositoryType>
<PackageReleaseNotes>Add:
- DbReaderMapper.GetGuid() (3 overrides)

Fix:
- DbReaderMapper.GetInt64() were returning Int32
- There were a typo in name of DbReaderMapper.GetNullableShort()

(https://github.com/Dysnomia-Studio/Dysnomia.Common.SQL/commit/d99e1ee22a4b59a1ee235bc78441d96198722c35)</PackageReleaseNotes>
<Version>1.0.2</Version>
<PackageReleaseNotes>- Open connection only if needed
- Renamed ExecSelect to ExecuteQuery and ExecStatement to ExecuteNonQuery</PackageReleaseNotes>
<Version>1.0.3-rc5</Version>
<AssemblyVersion>1.0.3.5</AssemblyVersion>
<FileVersion>1.0.3.5</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
[
![](https://img.shields.io/nuget/dt/Dysnomia.Common.SQL?label=NuGet%20Downloads)
![](https://img.shields.io/nuget/v/Dysnomia.Common.SQL?label=NuGet%20Version)
](https://nuget.org/packages/Dysnomia.Common.SQL)


# Dysnomia.Common.SQL
A .NET Core Micro-ORM for PostgreSQL & SQL Server
A driver agnostic Micro-ORM for .NET Core

## Why creating this Micro-ORM and publishing it to Github ?
Because I like creating my own libraries, and anyway I was creating this so why not making it public ? There's no sensitive data, and it can help many peoples :)
Expand Down

0 comments on commit 4f0457e

Please sign in to comment.