Skip to content

Commit

Permalink
Merge branch 'v5'
Browse files Browse the repository at this point in the history
  • Loading branch information
schotime committed Nov 13, 2020
2 parents 4b17292 + 01b9f8a commit ce374c8
Show file tree
Hide file tree
Showing 99 changed files with 2,730 additions and 1,492 deletions.
14 changes: 12 additions & 2 deletions NPoco.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26228.4
# Visual Studio Version 16
VisualStudioVersion = 16.0.30509.190
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{C7A94BA4-5689-4651-872D-7D7711D2DEDF}"
EndProject
Expand All @@ -18,6 +18,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NPoco.Tests", "test\NPoco.T
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NPoco.JsonNet", "src\NPoco.JsonNet\NPoco.JsonNet.csproj", "{8DCCBC0A-36D4-4F3C-9B16-39B23AAFD726}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NPoco.SqlServer", "src\NPoco.SqlServer\NPoco.SqlServer.csproj", "{15554441-8CF4-4B7B-A6D3-914463BFFF42}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -36,6 +38,10 @@ Global
{8DCCBC0A-36D4-4F3C-9B16-39B23AAFD726}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8DCCBC0A-36D4-4F3C-9B16-39B23AAFD726}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8DCCBC0A-36D4-4F3C-9B16-39B23AAFD726}.Release|Any CPU.Build.0 = Release|Any CPU
{15554441-8CF4-4B7B-A6D3-914463BFFF42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{15554441-8CF4-4B7B-A6D3-914463BFFF42}.Debug|Any CPU.Build.0 = Debug|Any CPU
{15554441-8CF4-4B7B-A6D3-914463BFFF42}.Release|Any CPU.ActiveCfg = Release|Any CPU
{15554441-8CF4-4B7B-A6D3-914463BFFF42}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -44,5 +50,9 @@ Global
{56481BBA-35A1-4061-9FE8-0ED9E1B6A0A3} = {C7A94BA4-5689-4651-872D-7D7711D2DEDF}
{B39C2641-0655-47CC-A1A3-5E1F84714FB5} = {8EDBB46A-95F8-442E-A432-19A50ED0683B}
{8DCCBC0A-36D4-4F3C-9B16-39B23AAFD726} = {C7A94BA4-5689-4651-872D-7D7711D2DEDF}
{15554441-8CF4-4B7B-A6D3-914463BFFF42} = {C7A94BA4-5689-4651-872D-7D7711D2DEDF}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {75EBE34D-2D61-4748-A383-DB920088B393}
EndGlobalSection
EndGlobal
11 changes: 8 additions & 3 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Properties {
$build_artifacts_dir = "$build_dir\build"
$solution_dir = "$build_dir\src\NPoco"
$jsonnet = "$build_dir\src\NPoco.JsonNet"
$sqlserver = "$build_dir\src\NPoco.SqlServer"
}

FormatTaskName (("-"*25) + "[{0}]" + ("-"*25))
Expand All @@ -19,10 +20,14 @@ Task Build -depends Clean {
Write-Host "Creating BuildArtifacts" -ForegroundColor Green
Exec { dotnet restore }
Set-Location "$solution_dir"
#$env:DNX_BUILD_VERSION="alpha02"
Exec { dotnet pack --configuration release --output $build_artifacts_dir }
if ($env:BUILD_SUFFIX -ne "") {
$suffix = "/p:VersionSuffix=""$env:BUILD_SUFFIX"""
}
Exec { dotnet pack --configuration release --output $build_artifacts_dir $suffix }
Set-Location "$jsonnet"
Exec { dotnet pack --configuration release --output $build_artifacts_dir }
Exec { dotnet pack --configuration release --output $build_artifacts_dir $suffix }
Set-Location "$sqlserver"
Exec { dotnet pack --configuration release --output $build_artifacts_dir $suffix }
}

Task Clean {
Expand Down
38 changes: 4 additions & 34 deletions src/NPoco.JsonNet/NPoco.JsonNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,27 @@

<PropertyGroup>
<Description>Provides an implementation to use Json.NET as the serializer for serialized columns</Description>
<VersionPrefix>4.0.0</VersionPrefix>
<TargetFrameworks>net35;net45;net40;netstandard1.3;netstandard2.0</TargetFrameworks>
<VersionPrefix>5.0.0</VersionPrefix>
<TargetFrameworks>net461;netstandard2.0;netstandard2.1</TargetFrameworks>
<AssemblyName>NPoco.JsonNet</AssemblyName>
<PackageId>NPoco.JsonNet</PackageId>
<PackageTags>orm;sql;micro-orm;database;mvc</PackageTags>
<PackageProjectUrl>https://github.com/schotime/NPoco</PackageProjectUrl>
<PackageLicense>http://www.apache.org/licenses/LICENSE-2.0</PackageLicense>
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netstandard1.3' ">$(PackageTargetFallback);dnxcore50</PackageTargetFallback>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
<LangVersion>8.0</LangVersion>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\NPoco\NPoco.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net40' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net35' ">
<Reference Include="System" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="Microsoft.CSharp" Version="4.3.0" />
<PackageReference Include="System.Collections" Version="4.3.0" />
<PackageReference Include="System.Linq" Version="4.3.0" />
<PackageReference Include="System.Runtime" Version="4.3.0" />
<PackageReference Include="System.Threading" Version="4.3.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
</ItemGroup>

<PropertyGroup>
<FrameworkPathOverride Condition="'$(TargetFramework)' == 'net35'">C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Client</FrameworkPathOverride>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using System.Data.SqlClient;
using Microsoft.Data.SqlClient;
using System.Linq;

namespace NPoco.DatabaseTypes
Expand All @@ -21,10 +21,10 @@ public override string BuildPageQuery(long skip, long take, PagingHelper.SQLPart
return sqlPage;
}

public override string GetAutoIncrementExpression(TableInfo ti)
public override string? GetAutoIncrementExpression(TableInfo ti)
{
if (!string.IsNullOrEmpty(ti.SequenceName))
return string.Format("NEXT VALUE FOR {0}", ti.SequenceName);
return $"NEXT VALUE FOR {ti.SequenceName}";

return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Threading.Tasks;

namespace NPoco.DatabaseTypes
{
Expand All @@ -19,14 +20,11 @@ public override object ExecuteInsert<T>(Database db, DbCommand cmd, string prima
return db.ExecuteScalar<object>("SELECT @@@IDENTITY AS NewID;");
}


#if !NET35 && !NET40
public override async System.Threading.Tasks.Task<object> ExecuteInsertAsync<T>(Database db, DbCommand cmd, string primaryKeyName, bool useOutputClause, T poco, object[] args)
public override async Task<object> ExecuteInsertAsync<T>(Database db, DbCommand cmd, string primaryKeyName, bool useOutputClause, T poco, object[] args)
{
await db.ExecuteNonQueryHelperAsync(cmd);
return await db.ExecuteScalarAsync<object>("SELECT @@@IDENTITY AS NewID;");
await db.ExecuteNonQueryHelperAsync(cmd).ConfigureAwait(false);
return await db.ExecuteScalarAsync<object>("SELECT @@@IDENTITY AS NewID;").ConfigureAwait(false);
}
#endif

public override IsolationLevel GetDefaultTransactionIsolationLevel()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
using Microsoft.Data.SqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Text.RegularExpressions;
using System.Text;
using System.Threading.Tasks;
using NPoco.SqlServer;

namespace NPoco.DatabaseTypes
{
public class SqlServerDatabaseType : DatabaseType
{
public bool UseOutputClause { get; set; }

private static readonly Regex OrderByAlias = new Regex(@"[\""\[\]\w]+\.([\[\]\""\w]+)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);

public override bool UseColumnAliases()
{
return true;
}

public override string BuildPageQuery(long skip, long take, PagingHelper.SQLParts parts, ref object[] args)
{
parts.sqlOrderBy = string.IsNullOrEmpty(parts.sqlOrderBy) ? null : OrderByAlias.Replace(parts.sqlOrderBy, "$1");
var sqlPage = string.Format("SELECT {4} FROM (SELECT poco_base.*, ROW_NUMBER() OVER ({0}) poco_rn \nFROM ( \n{1}) poco_base ) poco_paged \nWHERE poco_rn > @{2} AND poco_rn <= @{3} \nORDER BY poco_rn",
parts.sqlOrderBy ?? "ORDER BY (SELECT NULL /*poco_dual*/)", parts.sqlUnordered, args.Length, args.Length + 1, parts.sqlColumns);
args = args.Concat(new object[] { skip, skip + take }).ToArray();

return sqlPage;
return PagingHelper.BuildPaging(skip, take, parts, ref args);
}

private void AdjustSqlInsertCommandText(DbCommand cmd, bool useOutputClause)
{
if (!UseOutputClause && !useOutputClause)
Expand Down Expand Up @@ -57,26 +52,17 @@ public override object ExecuteInsert<T>(Database db, DbCommand cmd, string prima
return db.ExecuteScalarHelper(cmd);
}

#if !NET35 && !NET40
public override System.Threading.Tasks.Task<object> ExecuteInsertAsync<T>(Database db, DbCommand cmd, string primaryKeyName, bool useOutputClause, T poco, object[] args)
public override Task<object> ExecuteInsertAsync<T>(Database db, DbCommand cmd, string primaryKeyName, bool useOutputClause, T poco, object[] args)
{
AdjustSqlInsertCommandText(cmd, useOutputClause);
return db.ExecuteScalarHelperAsync(cmd);
}
#endif

public override string GetExistsSql()
{
return "IF EXISTS (SELECT 1 FROM {0} WHERE {1}) SELECT 1 ELSE SELECT 0";
}

#if !DNXCORE50
public override void InsertBulk<T>(IDatabase db, IEnumerable<T> pocos)
{
SqlBulkCopyHelper.BulkInsert(db, pocos);
}
#endif

public override IsolationLevel GetDefaultTransactionIsolationLevel()
{
return IsolationLevel.ReadCommitted;
Expand All @@ -90,9 +76,19 @@ public override IsolationLevel GetDefaultTransactionIsolationLevel()
return base.LookupDbType(type, name);
}

public override void InsertBulk<T>(IDatabase db, IEnumerable<T> pocos, InsertBulkOptions? options)
{
SqlBulkCopyHelper.BulkInsert(db, pocos, options);
}

public override Task InsertBulkAsync<T>(IDatabase db, IEnumerable<T> pocos, InsertBulkOptions options)
{
return SqlBulkCopyHelper.BulkInsertAsync(db, pocos, options);
}

public override string GetProviderName()
{
return "System.Data.SqlClient";
return "Microsoft.Data.SqlClient";
}

public override object ProcessDefaultMappings(PocoColumn pocoColumn, object value)
Expand All @@ -103,5 +99,49 @@ public override object ProcessDefaultMappings(PocoColumn pocoColumn, object valu
}
return base.ProcessDefaultMappings(pocoColumn, value);
}


public override string FormatCommand(string sql, object[] args)
{
if (sql == null)
return "";

var sb = new StringBuilder();
if (args != null && args.Length > 0)
{
for (int i = 0; i < args.Length; i++)
{
var value = args[i];
var formatted = args[i] as FormattedParameter;
if (formatted != null)
{
value = formatted.Value;
}

var p = new SqlParameter();
ParameterHelper.SetParameterValue(this, p, args[i]);
if (p.Size == 0 || p.SqlDbType == SqlDbType.UniqueIdentifier)
{
if (value == null && (p.SqlDbType == SqlDbType.NVarChar || p.SqlDbType == SqlDbType.VarChar))
{
sb.AppendFormat("DECLARE {0}{1} {2} = null\n", GetParameterPrefix(string.Empty), i, p.SqlDbType);
}
else
{
sb.AppendFormat("DECLARE {0}{1} {2} = '{3}'\n", GetParameterPrefix(string.Empty), i, p.SqlDbType, value);
}
}
else
{
sb.AppendFormat("DECLARE {0}{1} {2}[{3}] = '{4}'\n", GetParameterPrefix(string.Empty), i, p.SqlDbType, p.Size, value);
}
}
}

sb.AppendFormat("\n{0}", sql);

return sb.ToString();
}

}
}
32 changes: 32 additions & 0 deletions src/NPoco.SqlServer/DefaultPollyPolicy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using Microsoft.Data.SqlClient;
using Polly;
using Polly.Retry;

namespace NPoco.SqlServer
{
public class DefaultPollyPolicy : IPollyPolicy
{
public virtual RetryPolicy RetryPolicy { get; set; } = RetryPolicyImp;

public virtual AsyncRetryPolicy AsyncRetryPolicy { get; set; } = RetryPolicyAsyncImp;

public static IEnumerable<TimeSpan> RetryTimes { get; set; } = new[]
{
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(3),
TimeSpan.FromSeconds(5)
};

private static readonly AsyncRetryPolicy RetryPolicyAsyncImp = Policy
.Handle<SqlException>(SqlServerTransientExceptionDetector.ShouldRetryOn)
.Or<TimeoutException>()
.WaitAndRetryAsync(RetryTimes);

private static readonly RetryPolicy RetryPolicyImp = Policy
.Handle<SqlException>(SqlServerTransientExceptionDetector.ShouldRetryOn)
.Or<TimeoutException>()
.WaitAndRetry(RetryTimes);
}
}
10 changes: 10 additions & 0 deletions src/NPoco.SqlServer/IPollyPolicy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Polly.Retry;

namespace NPoco.SqlServer
{
public interface IPollyPolicy
{
RetryPolicy RetryPolicy { get; set; }
AsyncRetryPolicy AsyncRetryPolicy { get; set; }
}
}
25 changes: 25 additions & 0 deletions src/NPoco.SqlServer/NPoco.SqlServer.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>An extremely easy to use Micro-ORM supporting Sql Server.</Description>
<VersionPrefix>5.0.0</VersionPrefix>
<TargetFrameworks>net461;netstandard2.0;netstandard2.1</TargetFrameworks>
<AssemblyName>NPoco.SqlServer</AssemblyName>
<PackageId>NPoco.SqlServer</PackageId>
<Authors>Adam Schröder</Authors>
<PackageTags>orm;sql;micro-orm;database;mvc</PackageTags>
<PackageProjectUrl>https://github.com/schotime/NPoco</PackageProjectUrl>
<LangVersion>8.0</LangVersion>
<nullable>enable</nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="2.0.1" />
<PackageReference Include="Polly" Version="7.2.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\NPoco\NPoco.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit ce374c8

Please sign in to comment.