Skip to content

Commit

Permalink
Add initial work on async connections
Browse files Browse the repository at this point in the history
  • Loading branch information
schotime committed Dec 23, 2023
1 parent 162a46a commit 921a5dd
Show file tree
Hide file tree
Showing 7 changed files with 326 additions and 39 deletions.
41 changes: 41 additions & 0 deletions src/NPoco.Abstractions/IAsyncBaseDatabase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Data;
using System.Threading;
using System.Threading.Tasks;

namespace NPoco
{
public interface IAsyncBaseDatabase : IBaseDatabase
{
/// <summary>
/// Opens the DbConnection manually
/// </summary>
Task<IAsyncDatabase> OpenSharedConnectionAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Closes the DBConnection manually
/// </summary>
Task CloseSharedConnectionAsync();

#if NETSTANDARD2_1_OR_GREATER
/// <summary>
/// Manually begin a transaction. Recommended to use GetTransaction
/// </summary>
Task BeginTransactionAsync();

/// <summary>
/// Manually begin a transaction. Recommended to use GetTransaction
/// </summary>
Task BeginTransactionAsync(IsolationLevel isolationLevel);

/// <summary>
/// Manually abort/rollback a transaction
/// </summary>
Task AbortTransactionAsync();

/// <summary>
/// Manually commit a transaction
/// </summary>
Task CompleteTransactionAsync();
#endif
}
}
2 changes: 1 addition & 1 deletion src/NPoco.Abstractions/IAsyncDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public interface IAsyncDatabase : IAsyncQueryDatabase
Task SaveAsync<T>(T poco, CancellationToken cancellationToken = default);
}

public interface IAsyncQueryDatabase : IBaseDatabase
public interface IAsyncQueryDatabase : IAsyncBaseDatabase
{
/// <summary>
/// Fetch the only row of type T using the sql and parameters specified
Expand Down
9 changes: 0 additions & 9 deletions src/NPoco.Abstractions/NPoco - Backup.Abstractions.csproj

This file was deleted.

1 change: 0 additions & 1 deletion src/NPoco.Abstractions/NPoco.Abstractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<ItemGroup>
<PackageReference Condition="'$(TargetFramework)' == 'net461' " Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Condition="'$(TargetFramework)' == 'net461' or '$(TargetFramework)' == 'netstandard2.0' " Include="Microsoft.Bcl.AsyncInterfaces" Version="1.1.1" />
<!--<PackageReference Include="System.Linq.Async" Version="5.0.0" />-->
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.7.0" />
</ItemGroup>

Expand Down
2 changes: 0 additions & 2 deletions src/NPoco/AsyncDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
using NPoco.Expressions;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Threading.Tasks;
using NPoco.Extensions;
using NPoco.Linq;
using System.Threading;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices.ComTypes;

namespace NPoco
{
Expand Down
5 changes: 5 additions & 0 deletions src/NPoco/AsyncHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@ internal static T RunSync<T>(this Task<T> task)
{
return task.ConfigureAwait(false).GetAwaiter().GetResult();
}

internal static void RunSync(this Task task)
{
task.ConfigureAwait(false).GetAwaiter().GetResult();
}
}
}
Loading

0 comments on commit 921a5dd

Please sign in to comment.