Skip to content

Commit

Permalink
improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
pwelter34 committed Oct 25, 2023
1 parent 23a3a6d commit 0b342d8
Show file tree
Hide file tree
Showing 37 changed files with 1,801 additions and 23 deletions.
28 changes: 28 additions & 0 deletions src/FluentCommand/ConcurrencyToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,40 @@ public override int GetHashCode()
return Value.GetHashCode();
}

/// <summary>
/// Performs an implicit conversion from <see cref="ConcurrencyToken"/> to byte array.
/// </summary>
/// <param name="token">The concurrency token.</param>
/// <returns>
/// The result of the conversion.
/// </returns>
public static implicit operator byte[](ConcurrencyToken token) => token.Value;

/// <summary>
/// Performs an implicit conversion from <see cref="ConcurrencyToken"/> to <see cref="System.String"/>.
/// </summary>
/// <param name="token">The concurrency token.</param>
/// <returns>
/// The result of the conversion.
/// </returns>
public static implicit operator string(ConcurrencyToken token) => token.ToString();

/// <summary>
/// Performs an implicit conversion from byte array to <see cref="ConcurrencyToken"/>.
/// </summary>
/// <param name="token">The concurrency token.</param>
/// <returns>
/// The result of the conversion.
/// </returns>
public static implicit operator ConcurrencyToken(byte[] token) => new(token);

/// <summary>
/// Performs an implicit conversion from <see cref="System.String"/> to <see cref="ConcurrencyToken"/>.
/// </summary>
/// <param name="token">The concurrency token.</param>
/// <returns>
/// The result of the conversion.
/// </returns>
public static implicit operator ConcurrencyToken(string token) => new(token);


Expand Down
3 changes: 3 additions & 0 deletions src/FluentCommand/DataFieldConverterAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public DataFieldConverterAttribute(Type converterType)
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter)]
public class DataFieldConverterAttribute<TConverter> : DataFieldConverterAttribute
{
/// <summary>
/// Initializes a new instance of the <see cref="DataFieldConverterAttribute"/> class.
/// </summary>
public DataFieldConverterAttribute() : base(typeof(TConverter))
{
}
Expand Down
24 changes: 24 additions & 0 deletions src/FluentCommand/DataParameterHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

namespace FluentCommand;

/// <summary>
///
/// </summary>
public static class DataParameterHandlers
{
private static readonly ConcurrentDictionary<Type, IDataParameterHandler> _dataTypeHandlers;
Expand All @@ -22,25 +25,46 @@ static DataParameterHandlers()
#endif
}

/// <summary>
/// Adds the data type handler.
/// </summary>
/// <typeparam name="THandler">The type of the handler.</typeparam>
public static void AddTypeHandler<THandler>()
where THandler : IDataParameterHandler, new()
{
var handler = new THandler();
AddTypeHandler(handler);
}

/// <summary>
/// Adds the data type handler.
/// </summary>
/// <typeparam name="THandler">The type of the handler.</typeparam>
/// <param name="handler">The handler.</param>
public static void AddTypeHandler<THandler>(THandler handler)
where THandler : IDataParameterHandler
{
_dataTypeHandlers.TryAdd(handler.ValueType, handler);
}

/// <summary>
/// Gets the type handler for the specified <paramref name="type"/>.
/// </summary>
/// <param name="type">The type to get a handler for.</param>
/// <returns>The <see cref="IDataParameterHandler"/> for the specified type; otherwise null if not found</returns>
public static IDataParameterHandler GetTypeHandler(Type type)
{
var underlyingType = type.GetUnderlyingType();
return _dataTypeHandlers.TryGetValue(underlyingType, out var handler) ? handler : null;
}


/// <summary>
/// Sets the Value and DbType on the specified <paramref name="parameter"/> using the registered type handlers.
/// </summary>
/// <param name="parameter">The parameter to set the value on.</param>
/// <param name="value">The value to set.</param>
/// <param name="type">The data type to use.</param>
public static void SetValue(DbParameter parameter, object value, Type type)
{
var valueType = type.GetUnderlyingType();
Expand Down
8 changes: 3 additions & 5 deletions src/FluentCommand/DataQueryLogger.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using System.Data;

using FluentCommand.Internal;

using Microsoft.Extensions.Logging;

namespace FluentCommand;

/// <summary>
/// A class to log queries to string delegate
/// A class for logging queries
/// </summary>
/// <seealso cref="FluentCommand.IDataQueryLogger" />
public partial class DataQueryLogger : IDataQueryLogger
Expand Down Expand Up @@ -51,8 +49,8 @@ public virtual void LogCommand(IDbCommand command, TimeSpan duration, Exception
}

[LoggerMessage(0, LogLevel.Debug, "{output}")]
public partial void LogCommand(string output);
private partial void LogCommand(string output);

[LoggerMessage(1, LogLevel.Error, "{output}")]
public partial void LogError(string output, Exception exception);
private partial void LogError(string output, Exception exception);
}
3 changes: 2 additions & 1 deletion src/FluentCommand/DataReaderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Data;
using System.Data;
using System.Dynamic;

using FluentCommand.Reflection;
Expand All @@ -16,6 +16,7 @@ public static class DataReaderExtensions
/// <typeparam name="TEntity">The type of the entity.</typeparam>
/// <param name="reader">The open <see cref="IDataReader" /> to get the object from.</param>
/// <returns>A TEntity object having property names set that match the field names in the <see cref="IDataReader" />.</returns>
[Obsolete("Use generated data reader factory")]
public static TEntity EntityFactory<TEntity>(this IDataReader reader)
where TEntity : class, new()
{
Expand Down
7 changes: 5 additions & 2 deletions src/FluentCommand/Internal/HashCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,11 @@ public static int HashString(string text)

unchecked
{
foreach (char c in text)
hash = (hash * Multiplier) + c;
// ReSharper disable once LoopCanBeConvertedToQuery
// ReSharper disable once ForCanBeConvertedToForeach
for (var index = 0; index < text.Length; index++)
hash = (hash * Multiplier) + text[index];

}

return hash;
Expand Down
8 changes: 8 additions & 0 deletions src/FluentCommand/Query/AggregateFunctions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
namespace FluentCommand.Query;

/// <summary>
/// Query aggregate functions
/// </summary>
public enum AggregateFunctions
{
/// <summary>Average aggregate function</summary>
Average,
/// <summary>Count aggregate function</summary>
Count,
/// <summary>Max aggregate function</summary>
Max,
/// <summary>Min aggregate function</summary>
Min,
/// <summary>Sum aggregate function</summary>
Sum,
}
104 changes: 103 additions & 1 deletion src/FluentCommand/Query/DeleteBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@

namespace FluentCommand.Query;

/// <summary>
/// Delete query statement builder
/// </summary>
public class DeleteBuilder : DeleteBuilder<DeleteBuilder>
{
/// <summary>
/// Initializes a new instance of the <see cref="DeleteBuilder"/> class.
/// </summary>
/// <param name="queryGenerator">The query generator.</param>
/// <param name="parameters">The parameters.</param>
/// <param name="logicalOperator">The logical operator.</param>
public DeleteBuilder(
IQueryGenerator queryGenerator,
List<QueryParameter> parameters,
Expand All @@ -14,9 +23,19 @@ public DeleteBuilder(
}
}

/// <summary>
/// Delete query statement builder
/// </summary>
/// <typeparam name="TBuilder">The type of the builder.</typeparam>
public abstract class DeleteBuilder<TBuilder> : WhereBuilder<TBuilder>
where TBuilder : DeleteBuilder<TBuilder>
{
/// <summary>
/// Initializes a new instance of the <see cref="DeleteBuilder{TBuilder}"/> class.
/// </summary>
/// <param name="queryGenerator">The query generator.</param>
/// <param name="parameters">The parameters.</param>
/// <param name="logicalOperator">The logical operator.</param>
protected DeleteBuilder(
IQueryGenerator queryGenerator,
List<QueryParameter> parameters,
Expand All @@ -26,15 +45,48 @@ protected DeleteBuilder(
}


/// <summary>
/// Gets the output expressions.
/// </summary>
/// <value>
/// The output expressions.
/// </value>
protected HashSet<ColumnExpression> OutputExpressions { get; } = new();

/// <summary>
/// Gets from expressions.
/// </summary>
/// <value>
/// From expressions.
/// </value>
protected HashSet<TableExpression> FromExpressions { get; } = new();

/// <summary>
/// Gets the join expressions.
/// </summary>
/// <value>
/// The join expressions.
/// </value>
protected HashSet<JoinExpression> JoinExpressions { get; } = new();

/// <summary>
/// Gets the table expression.
/// </summary>
/// <value>
/// The table expression.
/// </value>
protected TableExpression TableExpression { get; private set; }


/// <summary>
/// Set the target table to delete from.
/// </summary>
/// <param name="tableName">Name of the table.</param>
/// <param name="tableSchema">The table schema.</param>
/// <param name="tableAlias">The table alias.</param>
/// <returns>
/// The same builder so that multiple calls can be chained.
/// </returns>
public TBuilder Table(
string tableName,
string tableSchema = null,
Expand All @@ -46,6 +98,14 @@ public TBuilder Table(
}


/// <summary>
/// Add an output clause for the specified column names.
/// </summary>
/// <param name="columnNames">The column names.</param>
/// <param name="tableAlias">The table alias.</param>
/// <returns>
/// The same builder so that multiple calls can be chained.
/// </returns>
public TBuilder Output(
IEnumerable<string> columnNames,
string tableAlias = "DELETED")
Expand All @@ -59,6 +119,15 @@ public TBuilder Output(
return (TBuilder)this;
}

/// <summary>
/// Add an output clause for the specified column name.
/// </summary>
/// <param name="columnName">Name of the column.</param>
/// <param name="tableAlias">The table alias.</param>
/// <param name="columnAlias">The column alias.</param>
/// <returns>
/// The same builder so that multiple calls can be chained.
/// </returns>
public TBuilder Output(
string columnName,
string tableAlias = "DELETED",
Expand All @@ -71,6 +140,16 @@ public TBuilder Output(
return (TBuilder)this;
}

/// <summary>
/// Conditionally add an output clause for the specified column name.
/// </summary>
/// <param name="columnName">Name of the column.</param>
/// <param name="tableAlias">The table alias.</param>
/// <param name="columnAlias">The column alias.</param>
/// <param name="condition">The condition.</param>
/// <returns>
/// The same builder so that multiple calls can be chained.
/// </returns>
public TBuilder OutputIf(
string columnName,
string tableAlias = "DELETED",
Expand All @@ -84,6 +163,15 @@ public TBuilder OutputIf(
}


/// <summary>
/// Add a from clause to the query.
/// </summary>
/// <param name="tableName">Name of the table.</param>
/// <param name="tableSchema">The table schema.</param>
/// <param name="tableAlias">The table alias.</param>
/// <returns>
/// The same builder so that multiple calls can be chained.
/// </returns>
public virtual TBuilder From(
string tableName,
string tableSchema = null,
Expand All @@ -96,6 +184,13 @@ public virtual TBuilder From(
return (TBuilder)this;
}

/// <summary>
/// Add a raw from clause to the query.
/// </summary>
/// <param name="fromClause">From clause.</param>
/// <returns>
/// The same builder so that multiple calls can be chained.
/// </returns>
public TBuilder FromRaw(string fromClause)
{
if (fromClause.HasValue())
Expand All @@ -104,6 +199,13 @@ public TBuilder FromRaw(string fromClause)
return (TBuilder)this;
}

/// <summary>
/// Add a join clause using the specified builder action
/// </summary>
/// <param name="builder">The builder.</param>
/// <returns>
/// The same builder so that multiple calls can be chained.
/// </returns>
public TBuilder Join(Action<JoinBuilder> builder)
{
var innerBuilder = new JoinBuilder(QueryGenerator, Parameters);
Expand All @@ -114,7 +216,7 @@ public TBuilder Join(Action<JoinBuilder> builder)
return (TBuilder)this;
}


/// <inheritdoc />
public override QueryStatement BuildStatement()
{
var deleteStatement = new DeleteStatement(
Expand Down
Loading

0 comments on commit 0b342d8

Please sign in to comment.