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

Main v2 #1

Merged
merged 5 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Json Struct
  • Loading branch information
Mikarsoft committed Sep 23, 2024
commit b3c2a5815aaa66faba104206b8b86cedc007b645
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Mikarsoft.BlackHoleCore.Entities
using System.Text.Json.Serialization;

namespace Mikarsoft.BlackHoleCore.Entities
{
/// <summary>
///
Expand Down Expand Up @@ -178,4 +180,30 @@ public static implicit operator Guid(Uid number)
return number.Value;
}
}

public struct Json<T> where T : class
{
[JsonPropertyName("value")]
public T Value { get; set; }

// Constructor
public Json(T value)
{
Value = value;
}

public static implicit operator Json<T>(T value)
{
return new Json<T>(value);
}

/// <summary>
///
/// </summary>
/// <param name="number"></param>
public static implicit operator T(Json<T> jObject)
{
return jObject.Value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public interface IJoinConfig<Dto, TSource, TOther> : IBHQuery<Dto> where Dto : B
/// <param name="predicate"></param>
/// <param name="castOnDto"></param>
/// <returns></returns>
IJoinOptions<Dto, TSource, TOther> CastColumnOfFirst<TKey, TOtherKey>(Expression<Func<TSource, TKey?>> predicate, Expression<Func<Dto, TOtherKey?>> castOnDto);
IJoinOptions<Dto, TSource, TOther> CastColumnOfFirst<TKey, TOtherKey>(Expression<Func<TSource, TKey?>> key, Expression<Func<Dto, TOtherKey?>> otherKey);

/// <summary>
///
Expand All @@ -117,19 +117,13 @@ public interface IJoinConfig<Dto, TSource, TOther> : IBHQuery<Dto> where Dto : B
/// <param name="predicate"></param>
/// <param name="castOnDto"></param>
/// <returns></returns>
IJoinOptions<Dto, TSource, TOther> CastColumnOfSecond<TKey, TOtherKey>(Expression<Func<TOther, TKey?>> predicate, Expression<Func<Dto, TOtherKey?>> castOnDto);
IJoinOptions<Dto, TSource, TOther> CastColumnOfSecond<TKey, TOtherKey>(Expression<Func<TOther, TKey?>> key, Expression<Func<Dto, TOtherKey?>> otherKey);

/// <summary>
///
/// </summary>
/// <returns></returns>
IBHJoinsProcess<Dto> Then();

/// <summary>
///
/// </summary>
/// <returns></returns>
IJoinComplete<Dto> Finally();
}

/// <summary>
Expand Down Expand Up @@ -162,7 +156,7 @@ public interface IJoinOptions<Dto, TSource, TOther> : IBHQuery<Dto> where Dto :
/// <param name="predicate"></param>
/// <param name="castOnDto"></param>
/// <returns></returns>
IJoinOptions<Dto, TSource, TOther> CastColumnOfFirst<TKey, TOtherKey>(Expression<Func<TSource, TKey?>> predicate, Expression<Func<Dto, TOtherKey?>> castOnDto);
IJoinOptions<Dto, TSource, TOther> CastColumnOfFirst<TKey, TOtherKey>(Expression<Func<TSource, TKey?>> key, Expression<Func<Dto, TOtherKey?>> otherKey);

/// <summary>
///
Expand All @@ -172,37 +166,12 @@ public interface IJoinOptions<Dto, TSource, TOther> : IBHQuery<Dto> where Dto :
/// <param name="predicate"></param>
/// <param name="castOnDto"></param>
/// <returns></returns>
IJoinOptions<Dto, TSource, TOther> CastColumnOfSecond<TKey, TOtherKey>(Expression<Func<TOther, TKey?>> predicate, Expression<Func<Dto, TOtherKey?>> castOnDto);
IJoinOptions<Dto, TSource, TOther> CastColumnOfSecond<TKey, TOtherKey>(Expression<Func<TOther, TKey?>> key, Expression<Func<Dto, TOtherKey?>> otherKey);

/// <summary>
///
/// </summary>
/// <returns></returns>
IBHJoinsProcess<Dto> Then();

/// <summary>
///
/// </summary>
/// <returns></returns>
IJoinComplete<Dto> Finally();
}

/// <summary>
///
/// </summary>
/// <typeparam name="Dto"></typeparam>
public interface IJoinComplete<Dto> where Dto : BHDto
{
/// <summary>
///
/// </summary>
/// <returns></returns>
List<Dto> ExecuteQuery();

/// <summary>
///
/// </summary>
/// <returns></returns>
Task<List<Dto>> ExecuteQueryAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,6 @@ public interface IBHQuery<T> where T : class
/// <returns></returns>
Task<List<T>> ToListAsync();

/// <summary>
///
/// </summary>
/// <returns></returns>
List<T> ToList(Expression<Func<T, bool>> predicate);

/// <summary>
///
/// </summary>
/// <returns></returns>
Task<List<T>> ToListAsync(Expression<Func<T, bool>> predicate);

/// <summary>
///
/// </summary>
Expand All @@ -223,18 +211,6 @@ public interface IBHQuery<T> where T : class
/// </summary>
/// <returns></returns>
Task<T?> FirstOrDefaultAsync();

/// <summary>
///
/// </summary>
/// <returns></returns>
T? FirstOrDefault(Expression<Func<T, bool>> predicate);

/// <summary>
///
/// </summary>
/// <returns></returns>
Task<T?> FirstOrDefaultAsync(Expression<Func<T, bool>> predicate);
}

/// <summary>
Expand Down
88 changes: 28 additions & 60 deletions Mikarsoft.BlackHoleCore/Mikarsoft.BlackHoleCore/BHJoins.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Mikarsoft.BlackHoleCore.Abstractions.Tools;
using Mikarsoft.BlackHoleCore.Connector.Enums;
using Mikarsoft.BlackHoleCore.Connector.Enums;
using Mikarsoft.BlackHoleCore.Entities;
using Mikarsoft.BlackHoleCore.Tools;
using System.Linq.Expressions;
Expand Down Expand Up @@ -62,57 +61,51 @@ internal PreJoin(BHStatementBuilder statement, byte[] tableLetters)
TableDCode = tableLetters[1];
}

public IJoinConfig<Dto, TSource, TOther> On<TKey>(Expression<Func<TSource, TKey?>> key, Expression<Func<TOther, TKey?>> otherKey)
public IJoinConfig<Dto, TSource, TOther> On<TKey>(Expression<Func<TSource, TKey?>> key,
Expression<Func<TOther, TKey?>> otherKey)
{
string first = key.MemberParse();
string second = otherKey.MemberParse();
StatementBuilder.AddJoinPoint(first, second);
StatementBuilder.AddJoinPoint(key, otherKey);
return new JoinConfig<Dto, TSource, TOther>(StatementBuilder, TableACode, TableDCode);
}
}

internal class JoinConfig<Dto, TSource, TOther> : BHQuery<Dto>, IJoinConfig<Dto, TSource, TOther>
where Dto : BHDto where TSource : BHEntity<TSource> where TOther : BHEntity<TOther>
{
private readonly BHStatementBuilder StatementBuilder;
private readonly byte TableACode;
private readonly byte TableDCode;

internal JoinConfig(BHStatementBuilder statement, byte tableACode, byte tableDCode)
internal JoinConfig(BHStatementBuilder statement, byte tableACode, byte tableDCode) : base(statement)
{
StatementBuilder = statement;
TableACode = tableACode;
TableDCode = tableDCode;
}

public IJoinConfig<Dto, TSource, TOther> And<TKey>(Expression<Func<TSource, TKey?>> key, Expression<Func<TOther, TKey?>> otherKey)
public IJoinConfig<Dto, TSource, TOther> And<TKey>(Expression<Func<TSource, TKey?>> key,
Expression<Func<TOther, TKey?>> otherKey)
{
string first = key.MemberParse();
string second = otherKey.MemberParse();
StatementBuilder.AddJoinPoint(first, second, OuterPairType.And);
StatementBuilder.AddJoinPoint(key, otherKey, OuterPairType.And);
return new JoinConfig<Dto, TSource, TOther>(StatementBuilder, TableACode, TableDCode);
}

public IJoinOptions<Dto, TSource, TOther> CastColumnOfFirst<TKey, TOtherKey>(Expression<Func<TSource, TKey?>> predicate, Expression<Func<Dto, TOtherKey?>> castOnDto)
public IJoinOptions<Dto, TSource, TOther> CastColumnOfFirst<TKey, TOtherKey>(Expression<Func<TSource, TKey?>> key,
Expression<Func<Dto, TOtherKey?>> otherKey)
{
throw new NotImplementedException();
}

public IJoinOptions<Dto, TSource, TOther> CastColumnOfSecond<TKey, TOtherKey>(Expression<Func<TOther, TKey?>> predicate, Expression<Func<Dto, TOtherKey?>> castOnDto)
{
throw new NotImplementedException();
StatementBuilder.AddCastCase(key, otherKey, TableACode);
return new JoinOptions<Dto, TSource, TOther>(StatementBuilder, TableACode, TableDCode);
}

public IJoinComplete<Dto> Finally()
public IJoinOptions<Dto, TSource, TOther> CastColumnOfSecond<TKey, TOtherKey>(Expression<Func<TOther, TKey?>> key,
Expression<Func<Dto, TOtherKey?>> otherKey)
{
return new JoinComplete<Dto>(StatementBuilder);
StatementBuilder.AddCastCase(key, otherKey, TableDCode);
return new JoinOptions<Dto, TSource, TOther>(StatementBuilder, TableACode, TableDCode);
}

public IJoinConfig<Dto, TSource, TOther> Or<TKey>(Expression<Func<TSource, TKey?>> key, Expression<Func<TOther, TKey?>> otherKey)
public IJoinConfig<Dto, TSource, TOther> Or<TKey>(Expression<Func<TSource, TKey?>> key,
Expression<Func<TOther, TKey?>> otherKey)
{
string first = key.MemberParse();
string second = otherKey.MemberParse();
StatementBuilder.AddJoinPoint(first, second, OuterPairType.Or);
StatementBuilder.AddJoinPoint(key, otherKey, OuterPairType.Or);
return new JoinConfig<Dto, TSource, TOther>(StatementBuilder, TableACode, TableDCode);
}

Expand All @@ -136,32 +129,27 @@ public IJoinOptions<Dto, TSource, TOther> WhereSecond(Expression<Func<TOther, bo

internal class JoinOptions<Dto, TSource, TOther> : BHQuery<Dto>, IJoinOptions<Dto, TSource, TOther> where Dto : BHDto
{
private readonly BHStatementBuilder StatementBuilder;
private readonly byte TableACode;
private readonly byte TableDCode;

internal JoinOptions(BHStatementBuilder statement, byte tableACode, byte tableDCode)
internal JoinOptions(BHStatementBuilder statement, byte tableACode, byte tableDCode) : base(statement)
{
StatementBuilder = statement;
TableACode = tableACode;
TableDCode = tableDCode;
}

public IJoinOptions<Dto, TSource, TOther> CastColumnOfFirst<TKey, TOtherKey>(Expression<Func<TSource, TKey?>> predicate,
Expression<Func<Dto, TOtherKey?>> castOnDto)
public IJoinOptions<Dto, TSource, TOther> CastColumnOfFirst<TKey, TOtherKey>(Expression<Func<TSource, TKey?>> key,
Expression<Func<Dto, TOtherKey?>> otherKey)
{
throw new NotImplementedException();
}

public IJoinOptions<Dto, TSource, TOther> CastColumnOfSecond<TKey, TOtherKey>(Expression<Func<TOther, TKey?>> predicate,
Expression<Func<Dto, TOtherKey?>> castOnDto)
{
throw new NotImplementedException();
StatementBuilder.AddCastCase(key, otherKey, TableACode);
return new JoinOptions<Dto, TSource, TOther>(StatementBuilder, TableACode, TableDCode);
}

public IJoinComplete<Dto> Finally()
public IJoinOptions<Dto, TSource, TOther> CastColumnOfSecond<TKey, TOtherKey>(Expression<Func<TOther, TKey?>> key,
Expression<Func<Dto, TOtherKey?>> otherKey)
{
return new JoinComplete<Dto>(StatementBuilder);
StatementBuilder.AddCastCase(key, otherKey, TableDCode);
return new JoinOptions<Dto, TSource, TOther>(StatementBuilder, TableACode, TableDCode);
}

public IBHJoinsProcess<Dto> Then()
Expand All @@ -181,24 +169,4 @@ public IJoinOptions<Dto, TSource, TOther> WhereSecond(Expression<Func<TOther, bo
return new JoinOptions<Dto, TSource, TOther>(StatementBuilder, TableACode, TableDCode);
}
}

internal class JoinComplete<Dto> : IJoinComplete<Dto> where Dto : BHDto
{
private readonly BHStatementBuilder StatementBuilder;

internal JoinComplete(BHStatementBuilder statement)
{
StatementBuilder = statement;
}

public List<Dto> ExecuteQuery()
{
throw new NotImplementedException();
}

public Task<List<Dto>> ExecuteQueryAsync()
{
throw new NotImplementedException();
}
}
}
37 changes: 37 additions & 0 deletions Mikarsoft.BlackHoleCore/Mikarsoft.BlackHoleCore/BHMessanger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Mikarsoft.BlackHoleCore.Tools;

namespace Mikarsoft.BlackHoleCore
{
internal static class BHMessanger
{
internal static bool Execute(this BHStatementBuilder statement)
{
return true;
}

internal static async Task<bool> ExecuteAsync(this BHStatementBuilder statement)
{
return false;
}

internal static T? FirstOrDefault<T>(this BHStatementBuilder statement) where T : class
{
return default(T?);
}

internal static async Task<T?> FirstOrDefaultAsync<T>(this BHStatementBuilder statement) where T : class
{
return default(T?);
}

internal static List<T> ToList<T>(this BHStatementBuilder statement) where T : class
{
return new List<T>();
}

internal static async Task<List<T>> ToListAsync<T>(this BHStatementBuilder statement) where T: class
{
return new List<T>();
}
}
}
24 changes: 0 additions & 24 deletions Mikarsoft.BlackHoleCore/Mikarsoft.BlackHoleCore/BHQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,11 @@ internal BHQuery(BHStatementBuilder statement)
throw new NotImplementedException();
}

public T? FirstOrDefault(Expression<Func<T, bool>> predicate)
{
StatementBuilder.AddWhereCase(predicate);
throw new NotImplementedException();
}

public Task<T?> FirstOrDefaultAsync()
{
throw new NotImplementedException();
}

public Task<T?> FirstOrDefaultAsync(Expression<Func<T, bool>> predicate)
{
StatementBuilder.AddWhereCase(predicate);
throw new NotImplementedException();
}

public IBHEnumerable<IBHGroup<G, T>, T> GroupBy<G>(Expression<Func<T, G>> keySelectors)
{
throw new NotImplementedException();
Expand All @@ -184,22 +172,10 @@ public List<T> ToList()
throw new NotImplementedException();
}

public List<T> ToList(Expression<Func<T, bool>> predicate)
{
StatementBuilder.AddWhereCase(predicate);
throw new NotImplementedException();
}

public Task<List<T>> ToListAsync()
{
throw new NotImplementedException();
}

public Task<List<T>> ToListAsync(Expression<Func<T, bool>> predicate)
{
StatementBuilder.AddWhereCase(predicate);
throw new NotImplementedException();
}
}

internal class BHEnumerable<T, TResult> : IBHEnumerable<T, TResult> where TResult : class
Expand Down
Loading