Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V6 #695

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open

V6 #695

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
162a46a
Add NPoco.Abstractions project and add CancellationToken's to the asy…
schotime Dec 21, 2023
921a5dd
Add initial work on async connections
schotime Dec 23, 2023
8730b9c
Add changeable default ForceToUtc flag on PocoColumn #655
schotime Dec 26, 2023
eee75eb
Only change data type for rows on their first iteration #684
schotime Dec 26, 2023
89b87bf
Use the async connection opening/closing methods in async implementat…
schotime Dec 26, 2023
7c8d0a9
Fix nullability suggestions and warnings
schotime Dec 27, 2023
16d6234
Update dependencies and version
schotime Dec 27, 2023
81e80e7
Add tests for cancellation token from Lars
schotime Dec 29, 2023
1600540
Allow certain types to not participate in IEnumerable expansion #636
schotime Dec 29, 2023
0eb27fe
More missing cancellation tokens
schotime Dec 29, 2023
9b29ce1
Add more async transaction methods
schotime Dec 29, 2023
2309ab2
Add DisposeAsync
schotime Jan 2, 2024
304766d
Add Abstractions package to build
schotime Jan 2, 2024
2f1a807
Allow ability to OpenSharedConnection lazily but not auto close
schotime Jan 10, 2024
fb92b02
Update SqlClient dependencies
schotime Jan 20, 2024
513a634
Fix ambiguous OpenSharedConnectionAsync
schotime Jan 22, 2024
a908604
Reorganise namespaces
schotime Feb 19, 2024
c433418
Implement AlterStatementHooks
schotime Mar 15, 2024
4c0ba55
Add support for DateOnly
schotime Nov 19, 2024
be85d53
Wrap WhereSql with brackets
schotime Dec 19, 2024
1d3f059
Update ValueTupleRowMapper to cache the sql query types also
schotime Dec 19, 2024
6c0604b
Fix format command and upgrade packages
schotime Feb 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion NPoco.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NPoco.JsonNet", "src\NPoco.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NPoco.SqlServer", "src\NPoco.SqlServer\NPoco.SqlServer.csproj", "{15554441-8CF4-4B7B-A6D3-914463BFFF42}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NPoco.SqlServer.SystemData", "src\NPoco.SqlServer.SystemData\NPoco.SqlServer.SystemData.csproj", "{0FC90AC0-5127-4114-8360-C8FB4CFA608E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NPoco.SqlServer.SystemData", "src\NPoco.SqlServer.SystemData\NPoco.SqlServer.SystemData.csproj", "{0FC90AC0-5127-4114-8360-C8FB4CFA608E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NPoco.Abstractions", "src\NPoco.Abstractions\NPoco.Abstractions.csproj", "{424ABBFC-43CC-40CA-B76E-9D8B72554B04}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -48,6 +50,10 @@ Global
{0FC90AC0-5127-4114-8360-C8FB4CFA608E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0FC90AC0-5127-4114-8360-C8FB4CFA608E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0FC90AC0-5127-4114-8360-C8FB4CFA608E}.Release|Any CPU.Build.0 = Release|Any CPU
{424ABBFC-43CC-40CA-B76E-9D8B72554B04}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{424ABBFC-43CC-40CA-B76E-9D8B72554B04}.Debug|Any CPU.Build.0 = Debug|Any CPU
{424ABBFC-43CC-40CA-B76E-9D8B72554B04}.Release|Any CPU.ActiveCfg = Release|Any CPU
{424ABBFC-43CC-40CA-B76E-9D8B72554B04}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -58,6 +64,7 @@ Global
{8DCCBC0A-36D4-4F3C-9B16-39B23AAFD726} = {C7A94BA4-5689-4651-872D-7D7711D2DEDF}
{15554441-8CF4-4B7B-A6D3-914463BFFF42} = {C7A94BA4-5689-4651-872D-7D7711D2DEDF}
{0FC90AC0-5127-4114-8360-C8FB4CFA608E} = {C7A94BA4-5689-4651-872D-7D7711D2DEDF}
{424ABBFC-43CC-40CA-B76E-9D8B72554B04} = {C7A94BA4-5689-4651-872D-7D7711D2DEDF}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {75EBE34D-2D61-4748-A383-DB920088B393}
Expand Down
3 changes: 3 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Properties {
$jsonnet = "$build_dir\src\NPoco.JsonNet"
$sqlserver = "$build_dir\src\NPoco.SqlServer"
$sqlserversysdata = "$build_dir\src\NPoco.SqlServer.SystemData"
$abstractions = "$build_dir\src\NPoco.Abstractions"
}

FormatTaskName (("-" * 25) + "[{0}]" + ("-" * 25))
Expand All @@ -31,6 +32,8 @@ Task Build -depends Clean {
Exec { dotnet pack --configuration release --output $build_artifacts_dir $suffix }
Set-Location "$sqlserversysdata"
Exec { dotnet pack --configuration release --output $build_artifacts_dir $suffix }
Set-Location "$abstractions"
Exec { dotnet pack --configuration release --output $build_artifacts_dir $suffix }
}

Task Clean {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
30 changes: 30 additions & 0 deletions src/NPoco.Abstractions/ColumnInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace NPoco
{
public class ColumnInfo
{
public string ColumnName { get; set; }
public string ColumnAlias { get; set; }
public bool ResultColumn { get; set; }
public bool ComputedColumn { get; set; }
public ComputedColumnType ComputedColumnType { get; set; }
public bool IgnoreColumn { get; set; }
public bool VersionColumn { get; set; }
public VersionColumnType VersionColumnType { get; set; }
public bool ForceToUtc { get; set; } = true;
public Type ColumnType { get; set; }
public bool ComplexMapping { get; set; }
public bool ValueObjectColumn { get; set; }
public string ComplexPrefix { get; set; }
public bool SerializedColumn { get; set; }
public ReferenceType ReferenceType { get; set; }
public string ReferenceMemberName { get; set; }
public MemberInfo MemberInfo { get; internal set; }
public bool ExactColumnNameMatch { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,4 @@ public ComputedColumnAttribute(string name, ComputedColumnType computedColumnTyp
ComputedColumnType = computedColumnType;
}
}

public enum ComputedColumnType
{
/// <summary>
/// Always considered as a computed column
/// </summary>
Always,
/// <summary>
/// Only considered a Computed column for inserts, Updates will not consider this column to be computed
/// </summary>
ComputedOnInsert,
/// <summary>
/// Only considered a Computed column for updates, Inserts will not consider this column to be computed
/// </summary>
ComputedOnUpdate
}
}
18 changes: 18 additions & 0 deletions src/NPoco.Abstractions/ComputedColumnType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace NPoco
{
public enum ComputedColumnType
{
/// <summary>
/// Always considered as a computed column
/// </summary>
Always,
/// <summary>
/// Only considered a Computed column for inserts, Updates will not consider this column to be computed
/// </summary>
ComputedOnInsert,
/// <summary>
/// Only considered a Computed column for updates, Inserts will not consider this column to be computed
/// </summary>
ComputedOnUpdate
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace NPoco.DbSpecific.Postgresql
{
public class OnConflictDoNothingAttribute : StatementPreparationHookAttribute
{
public override IAlterStatementHook AlterStatementHook => new OnConflictDoNothingStatementHook();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace NPoco.DbSpecific.Postgresql
{
public class OnConflictDoNothingStatementHook : AlterStatementHook
{
public override PreparedInsertStatement AlterInsert(IDatabase database, PreparedInsertStatement preparedInsertStatement)
{
preparedInsertStatement.Sql += " ON CONFLICT DO NOTHING";
return preparedInsertStatement;
}
}
}
File renamed without changes.
16 changes: 16 additions & 0 deletions src/NPoco.Abstractions/Expressions/GeneralMember.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NPoco.Expressions
{

public class GeneralMember
{
public Type EntityType { get; set; }
public PocoColumn PocoColumn { get; set; }
public PocoColumn[] PocoColumns { get; set; }
}
}
57 changes: 57 additions & 0 deletions src/NPoco.Abstractions/Expressions/ISqlExpression.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
using NPoco.Linq;

namespace NPoco.Expressions
{
public interface ISqlExpression
{
List<OrderByMember> OrderByMembers { get; }
int? Rows { get; }
int? Skip { get; }
string WhereSql { get; }
object[] Params { get; }
Type Type { get; }
List<SelectMember> SelectMembers { get; }
List<GeneralMember> GeneralMembers { get; }
string ApplyPaging(string sql, IEnumerable<PocoColumn[]> columns, Dictionary<string, JoinData> joinSqlExpressions);
string TableHint { get; }
}

public interface ISqlExpression<T> : ISqlExpression
{
ISqlExpressionContext Context { get; }

ISqlExpression<T> GroupBy<TKey>(Expression<Func<T, TKey>> keySelector);
ISqlExpression<T> Limit(int rows);
ISqlExpression<T> Limit(int skip, int rows);
string On<T2>(Expression<Func<T, T2, bool>> predicate);
ISqlExpression<T> OrderBy<TKey>(Expression<Func<T, TKey>> keySelector);
ISqlExpression<T> OrderByDescending<TKey>(Expression<Func<T, TKey>> keySelector);
ISqlExpression<T> Select<TKey>(Expression<Func<T, TKey>> fields);
List<SelectMember> SelectDistinct<TKey>(Expression<Func<T, TKey>> fields);
List<SelectMember> SelectProjection<TKey>(Expression<Func<T, TKey>> fields);
void Hint(string hint);
ISqlExpression<T> ThenBy<TKey>(Expression<Func<T, TKey>> keySelector);
ISqlExpression<T> ThenByDescending<TKey>(Expression<Func<T, TKey>> keySelector);
ISqlExpression<T> Update<TKey>(Expression<Func<T, TKey>> fields);
ISqlExpression<T> Where(Expression<Func<T, bool>> predicate);
ISqlExpression<T> Where(string sqlFilter, params object[] filterParams);

public interface ISqlExpressionContext
{
object[] Params { get; }
List<string> UpdateFields { get; set; }

string ToDeleteStatement();
string ToSelectStatement();
string ToSelectStatement(bool applyPaging, bool distinct);
string ToUpdateStatement(T item);
string ToUpdateStatement(T item, bool excludeDefaults);
string ToUpdateStatement(T item, bool excludeDefaults, bool allFields);
string ToWhereStatement();
}
}
}
12 changes: 12 additions & 0 deletions src/NPoco.Abstractions/Expressions/OrderByMember.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace NPoco.Expressions
{
public class OrderByMember
{
public Type EntityType { get; set; }
public PocoColumn PocoColumn { get; set; }
public PocoColumn[] PocoColumns { get; set; }
public string AscDesc { get; set; }
}
}
35 changes: 35 additions & 0 deletions src/NPoco.Abstractions/Expressions/SelectMember.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;

namespace NPoco.Expressions
{
public class SelectMember : IEquatable<SelectMember>
{
public Type EntityType { get; set; }
public string SelectSql { get; set; }
public PocoColumn PocoColumn { get; set; }
public PocoColumn[] PocoColumns { get; set; }

public bool Equals(SelectMember other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Equals(EntityType, other.EntityType) && Equals(PocoColumn, other.PocoColumn);
}

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((SelectMember)obj);
}

public override int GetHashCode()
{
unchecked
{
return ((EntityType != null ? EntityType.GetHashCode() : 0) * 397) ^ (PocoColumn != null ? PocoColumn.GetHashCode() : 0);
}
}
}
}
14 changes: 14 additions & 0 deletions src/NPoco.Abstractions/IAlterStatementHook.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace NPoco
{
public interface IAlterStatementHook
{
PreparedInsertStatement AlterInsert(IDatabase database, PreparedInsertStatement preparedInsertStatement);
PreparedUpdateStatement AlterUpdate(IDatabase database, PreparedUpdateStatement preparedUpdateStatement);
}

public abstract class AlterStatementHook : IAlterStatementHook
{
public virtual PreparedInsertStatement AlterInsert(IDatabase database, PreparedInsertStatement preparedInsertStatement) => preparedInsertStatement;
public virtual PreparedUpdateStatement AlterUpdate(IDatabase database, PreparedUpdateStatement preparedUpdateStatement) => preparedUpdateStatement;
}
}
55 changes: 55 additions & 0 deletions src/NPoco.Abstractions/IAsyncBaseDatabase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Data;
using System.Threading;
using System.Threading.Tasks;

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

/// <summary>
/// Opens the DbConnection manually
/// </summary>
Task<IAsyncDatabase> OpenSharedConnectionAsync(OpenConnectionOptions options, CancellationToken cancellationToken = default);

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

/// <summary>
/// Begins a new transaction and returns ITransaction which can be used in a using statement
/// </summary>
Task<IAsyncTransaction> GetTransactionAsync();

/// <summary>
/// Begins a new transaction and returns ITransaction which can be used in a using statement
/// </summary>
Task<IAsyncTransaction> GetTransactionAsync(IsolationLevel isolationLevel);

/// <summary>
/// Manually begin a transaction. Recommended to use GetTransaction
/// </summary>
Task BeginTransactionAsync(CancellationToken cancellationToken = default);

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

/// <summary>
/// Manually abort/rollback a transaction
/// </summary>
Task AbortTransactionAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Manually commit a transaction
/// </summary>
Task CompleteTransactionAsync(CancellationToken cancellationToken = default);
}
}
Loading