Skip to content

Commit

Permalink
query
Browse files Browse the repository at this point in the history
  • Loading branch information
KSemenenko committed Sep 5, 2022
1 parent ec8dcc2 commit a76b2c4
Show file tree
Hide file tree
Showing 33 changed files with 211 additions and 699 deletions.
353 changes: 2 additions & 351 deletions ManagedCode.Database.Core/BaseDBCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using ManagedCode.Database.Core.Queries;

namespace ManagedCode.Database.Core;

Expand Down Expand Up @@ -180,337 +181,7 @@ public Task<TItem> GetAsync(TId id, CancellationToken token = default)
return GetAsyncInternal(id, token);
}

public Task<TItem> GetAsync(Expression<Func<TItem, bool>> predicate, CancellationToken token = default)
{

if (predicate == null)
{
throw new ArgumentNullException(nameof(predicate));
}

return GetAsyncInternal(predicate, token);
}

public IAsyncEnumerable<TItem> GetAllAsync(int? take = null, int skip = 0, CancellationToken token = default)
{
return GetAllAsyncInternal(take, skip, token);
}

public IAsyncEnumerable<TItem> GetAllAsync(Expression<Func<TItem, object>> orderBy, int? take = null, int skip = 0, CancellationToken token = default)
{

if (orderBy == null)
{
throw new ArgumentNullException(nameof(orderBy));
}

return GetAllAsyncInternal(orderBy, Order.By, take, skip, token);
}

public IAsyncEnumerable<TItem> GetAllAsync(Expression<Func<TItem, object>> orderBy,
Order orderType,
int? take = null,
int skip = 0,
CancellationToken token = default)
{

if (orderBy == null)
{
throw new ArgumentNullException(nameof(orderBy));
}

return GetAllAsyncInternal(orderBy, orderType, take, skip, token);
}

protected abstract Task<TItem> GetAsyncInternal(TId id, CancellationToken token = default);
protected abstract Task<TItem> GetAsyncInternal(Expression<Func<TItem, bool>> predicate, CancellationToken token = default);

protected abstract IAsyncEnumerable<TItem> GetAllAsyncInternal(int? take = null, int skip = 0, CancellationToken token = default);

protected abstract IAsyncEnumerable<TItem> GetAllAsyncInternal(Expression<Func<TItem, object>> orderBy,
Order orderType,
int? take = null,
int skip = 0,
CancellationToken token = default);

#endregion

#region Find

public IAsyncEnumerable<TItem> FindAsync(Expression<Func<TItem, bool>> predicate, int? take = null, int skip = 0, CancellationToken token = default)
{
if (predicate == null)
{
throw new ArgumentNullException(nameof(predicate));
}

return FindAsyncInternal(new[] { predicate }, take, skip, token);
}

public IAsyncEnumerable<TItem> FindAsync(Expression<Func<TItem, bool>> predicate,
Expression<Func<TItem, object>> orderBy,
int? take = null,
int skip = 0,
CancellationToken token = default)
{
if (predicate == null)
{
throw new ArgumentNullException(nameof(predicate));
}

if (orderBy == null)
{
throw new ArgumentNullException(nameof(orderBy));
}

return FindAsyncInternal(new[] { predicate }, orderBy, Order.By, take, skip, token);
}

public IAsyncEnumerable<TItem> FindAsync(Expression<Func<TItem, bool>> predicate,
Expression<Func<TItem, object>> orderBy,
Order orderType,
int? take = null,
int skip = 0,
CancellationToken token = default)
{
if (predicate == null)
{
throw new ArgumentNullException(nameof(predicate));
}

if (orderBy == null)
{
throw new ArgumentNullException(nameof(orderBy));
}

return FindAsyncInternal(new[] { predicate }, orderBy, orderType, take, skip, token);
}

public IAsyncEnumerable<TItem> FindAsync(Expression<Func<TItem, bool>> predicate,
Expression<Func<TItem, object>> orderBy,
Expression<Func<TItem, object>> thenBy,
int? take = null,
int skip = 0,
CancellationToken token = default)
{

if (predicate == null)
{
throw new ArgumentNullException(nameof(predicate));
}

if (orderBy == null)
{
throw new ArgumentNullException(nameof(orderBy));
}

if (thenBy == null)
{
throw new ArgumentNullException(nameof(thenBy));
}

return FindAsyncInternal(new[] { predicate }, orderBy, Order.By, thenBy, Order.By, take, skip, token);
}

public IAsyncEnumerable<TItem> FindAsync(Expression<Func<TItem, bool>> predicate,
Expression<Func<TItem, object>> orderBy,
Order orderType,
Expression<Func<TItem, object>> thenBy,
int? take = null,
int skip = 0,
CancellationToken token = default)
{
if (predicate == null)
{
throw new ArgumentNullException(nameof(predicate));
}

if (orderBy == null)
{
throw new ArgumentNullException(nameof(orderBy));
}

if (thenBy == null)
{
throw new ArgumentNullException(nameof(thenBy));
}

return FindAsyncInternal(new[] { predicate }, orderBy, orderType, thenBy, Order.By, take, skip, token);
}

public IAsyncEnumerable<TItem> FindAsync(Expression<Func<TItem, bool>> predicate,
Expression<Func<TItem, object>> orderBy,
Order orderType,
Expression<Func<TItem, object>> thenBy,
Order thenType,
int? take = null,
int skip = 0,
CancellationToken token = default)
{

if (predicate == null)
{
throw new ArgumentNullException(nameof(predicate));
}

if (orderBy == null)
{
throw new ArgumentNullException(nameof(orderBy));
}

if (thenBy == null)
{
throw new ArgumentNullException(nameof(thenBy));
}

return FindAsyncInternal(new[] { predicate }, orderBy, orderType, thenBy, thenType, take, skip, token);
}

public IAsyncEnumerable<TItem> FindAsync(IEnumerable<Expression<Func<TItem, bool>>> predicates,
int? take = null,
int skip = 0,
CancellationToken token = default)
{
return FindAsyncInternal(predicates, take, skip, token);
}

public IAsyncEnumerable<TItem> FindAsync(IEnumerable<Expression<Func<TItem, bool>>> predicates,
Expression<Func<TItem, object>> orderBy,
int? take = null,
int skip = 0,
CancellationToken token = default)
{
if (predicates == null)
{
throw new ArgumentNullException(nameof(predicates));
}

if (orderBy == null)
{
throw new ArgumentNullException(nameof(orderBy));
}

return FindAsyncInternal(predicates, orderBy, Order.By, take, skip, token);
}

public IAsyncEnumerable<TItem> FindAsync(IEnumerable<Expression<Func<TItem, bool>>> predicates,
Expression<Func<TItem, object>> orderBy,
Order orderType,
int? take = null,
int skip = 0,
CancellationToken token = default)
{
if (predicates == null)
{
throw new ArgumentNullException(nameof(predicates));
}

if (orderBy == null)
{
throw new ArgumentNullException(nameof(orderBy));
}

return FindAsyncInternal(predicates, orderBy, orderType, take, skip, token);
}

public IAsyncEnumerable<TItem> FindAsync(IEnumerable<Expression<Func<TItem, bool>>> predicates,
Expression<Func<TItem, object>> orderBy,
Expression<Func<TItem, object>> thenBy,
int? take = null,
int skip = 0,
CancellationToken token = default)
{
if (predicates == null)
{
throw new ArgumentNullException(nameof(predicates));
}

if (orderBy == null)
{
throw new ArgumentNullException(nameof(orderBy));
}

if (thenBy == null)
{
throw new ArgumentNullException(nameof(thenBy));
}

return FindAsyncInternal(predicates, orderBy, Order.By, thenBy, Order.By, take, skip, token);
}

public IAsyncEnumerable<TItem> FindAsync(IEnumerable<Expression<Func<TItem, bool>>> predicates,
Expression<Func<TItem, object>> orderBy,
Order orderType,
Expression<Func<TItem, object>> thenBy,
int? take = null,
int skip = 0,
CancellationToken token = default)
{
if (predicates == null)
{
throw new ArgumentNullException(nameof(predicates));
}

if (orderBy == null)
{
throw new ArgumentNullException(nameof(orderBy));
}

if (thenBy == null)
{
throw new ArgumentNullException(nameof(thenBy));
}

return FindAsyncInternal(predicates, orderBy, orderType, thenBy, Order.By, take, skip, token);
}

public IAsyncEnumerable<TItem> FindAsync(IEnumerable<Expression<Func<TItem, bool>>> predicates,
Expression<Func<TItem, object>> orderBy,
Order orderType,
Expression<Func<TItem, object>> thenBy,
Order thenType,
int? take = null,
int skip = 0,
CancellationToken token = default)
{
if (predicates == null)
{
throw new ArgumentNullException(nameof(predicates));
}

if (orderBy == null)
{
throw new ArgumentNullException(nameof(orderBy));
}

if (thenBy == null)
{
throw new ArgumentNullException(nameof(thenBy));
}

return FindAsyncInternal(predicates, orderBy, orderType, thenBy, thenType, take, skip, token);
}

protected abstract IAsyncEnumerable<TItem> FindAsyncInternal(IEnumerable<Expression<Func<TItem, bool>>> predicates,
int? take = null,
int skip = 0,
CancellationToken token = default);

protected abstract IAsyncEnumerable<TItem> FindAsyncInternal(IEnumerable<Expression<Func<TItem, bool>>> predicates,
Expression<Func<TItem, object>> orderBy,
Order orderType,
int? take = null,
int skip = 0,
CancellationToken token = default);

protected abstract IAsyncEnumerable<TItem> FindAsyncInternal(IEnumerable<Expression<Func<TItem, bool>>> predicates,
Expression<Func<TItem, object>> orderBy,
Order orderType,
Expression<Func<TItem, object>> thenBy,
Order thenType,
int? take = null,
int skip = 0,
CancellationToken token = default);

#endregion

Expand All @@ -521,29 +192,9 @@ public Task<long> CountAsync(CancellationToken token = default)
return CountAsyncInternal(token);
}

public Task<long> CountAsync(Expression<Func<TItem, bool>> predicate, CancellationToken token = default)
{
if (predicate == null)
{
throw new ArgumentNullException(nameof(predicate));
}

return CountAsyncInternal(new[] { predicate }, token);
}

public Task<long> CountAsync(IEnumerable<Expression<Func<TItem, bool>>> predicates, CancellationToken token = default)
{
if (predicates == null)
{
throw new ArgumentNullException(nameof(predicates));
}

return CountAsyncInternal(predicates, token);
}
public abstract IDBCollectionQueryable<TItem> Query();

protected abstract Task<long> CountAsyncInternal(CancellationToken token = default);

protected abstract Task<long> CountAsyncInternal(IEnumerable<Expression<Func<TItem, bool>>> predicates, CancellationToken token = default);

#endregion
}
Loading

0 comments on commit a76b2c4

Please sign in to comment.