Skip to content

Commit

Permalink
Merge branch 'main' into feature/cli
Browse files Browse the repository at this point in the history
  • Loading branch information
RohitM-IN committed Mar 5, 2024
2 parents 6c2cdf7 + d7c0074 commit 4b767ab
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/DbSyncKit.Templates.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<Nullable>enable</Nullable>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
<Version>1.0.0.0</Version>
<AssemblyVersion>1.1.0.0</AssemblyVersion>
<FileVersion>1.1.0.0</FileVersion>
<Version>1.1.0.0</Version>
<PackageProjectUrl>https://dbsynckit.rohit-mahajan.in/</PackageProjectUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/RohitM-IN/DbSyncKit</RepositoryUrl>
Expand Down
85 changes: 85 additions & 0 deletions src/Interface/IQueryGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DbSyncKit.Templates.Interface
{
/// <summary>
/// Defines methods for generating SQL queries and handling query-related operations.
/// </summary>
public interface IQueryGenerator : IDisposable
{
/// <summary>
/// Generates a SELECT query for retrieving data from a database table.
/// </summary>
/// <param name="tableName">The name of the database table.</param>
/// <param name="ListOfColumns">The list of columns to be selected.</param>
/// <param name="schemaName">The schema name of the database table.</param>
/// <returns>A string representing the generated SELECT query.</returns>
string GenerateSelectQuery<T>(string tableName, List<string> ListOfColumns, string schemaName);

/// <summary>
/// Generates an UPDATE query for updating data in a database table.
/// </summary>
/// <param name="DataContract">The entity with the updated data.</param>
/// <param name="keyColumns">The list of key columns used for updating.</param>
/// <param name="excludedColumns">The list of columns to be excluded from the update.</param>
/// <param name="editedProperties">A dictionary representing the properties and their new values to be updated.</param>
/// <returns>A string representing the generated UPDATE query.</returns>
string GenerateUpdateQuery<T>(T DataContract, List<string> keyColumns, List<string> excludedColumns, (string propName, object propValue)[] editedProperties);

/// <summary>
/// Generates a DELETE query for deleting data from a database table.
/// </summary>
/// <param name="entity">The entity representing the data to be deleted.</param>
/// <param name="keyColumns">The list of key columns used for deletion.</param>
/// <returns>A string representing the generated DELETE query.</returns>
string GenerateDeleteQuery<T>(T entity, List<string> keyColumns);

/// <summary>
/// Generates an INSERT query for inserting data into a database table.
/// </summary>
/// <param name="entity">The entity representing the data to be inserted.</param>
/// <param name="keyColumns">The list of key columns used for insertion.</param>
/// <param name="excludedColumns">The list of columns to be excluded from the insertion.</param>
/// <returns>A string representing the generated INSERT query.</returns>
string GenerateInsertQuery<T>(T entity, List<string> keyColumns, List<string> excludedColumns);

/// <summary>
/// Generates a SQL comment.
/// </summary>
/// <param name="comment">The comment text.</param>
/// <returns>A string representing the generated comment.</returns>
string GenerateComment(string comment);

/// <summary>
/// Gets a condition for use in a SQL WHERE clause based on the entity and key columns.
/// </summary>
/// <param name="entity">The entity for which the condition is generated.</param>
/// <param name="keyColumns">The list of key columns used to create the condition.</param>
/// <returns>A string representing the generated condition for a SQL WHERE clause.</returns>
List<string> GetCondition<T>(T entity, List<string> keyColumns);

/// <summary>
/// Escapes special characters in the input to make it SQL-safe.
/// </summary>
/// <param name="input">The input object or string to be escaped.</param>
/// <returns>The escaped object or string.</returns>
object? EscapeValue(object? input);

/// <summary>
/// Escapes the input column name to be used safely in SQL queries.
/// </summary>
/// <param name="input">The input column name to be escaped.</param>
/// <returns>The escaped column name.</returns>
string EscapeColumn(string? input);

/// <summary>
/// Generates a SQL batch separator ('GO' statement in SQL Server) used to execute batches of SQL statements.
/// </summary>
/// <returns>A string representing the generated batch separator.</returns>
string GenerateBatchSeparator();
}
}
94 changes: 94 additions & 0 deletions src/QueryGenerationManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using DbSyncKit.Templates.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DbSyncKit.Templates
{
/// <summary>
/// Manages the generation of SQL queries for data operations by delegating the query generation tasks
/// to an implementation of the <see cref="IQueryGenerator"/> interface.
/// </summary>
/// <remarks>
/// This class acts as a wrapper around an instance of <see cref="IQueryGenerator"/> and forwards
/// query generation requests to the underlying implementation.
/// </remarks>
public class QueryGenerationManager : IQueryGenerator
{
private readonly IQueryGenerator _querryGenerator;

/// <summary>
/// The underlying query generator instance used for actual query generation.
/// </summary>
public QueryGenerationManager(IQueryGenerator querryGenerator)
{
_querryGenerator = querryGenerator;
}

#region Public Methods
/// <inheritdoc />
public string GenerateSelectQuery<T>(string tableName, List<string> listOfColumns, string schemaName)
{
return _querryGenerator.GenerateSelectQuery<T>(tableName, listOfColumns, schemaName);
}

/// <inheritdoc />
public string GenerateUpdateQuery<T>(T DataContract, List<string> keyColumns, List<string> excludedColumns, (string propName, object propValue)[] editedProperties)
{
return _querryGenerator.GenerateUpdateQuery<T>(DataContract, keyColumns, excludedColumns, editedProperties);
}

/// <inheritdoc />
public string GenerateDeleteQuery<T>(T entity, List<string> keyColumns)
{
return _querryGenerator.GenerateDeleteQuery<T>(entity, keyColumns);
}

/// <inheritdoc />
public string GenerateInsertQuery<T>(T entity, List<string> keyColumns, List<string> excludedColumns)
{
return _querryGenerator.GenerateInsertQuery<T>(entity, keyColumns, excludedColumns);
}

/// <inheritdoc />
public string GenerateComment(string comment)
{
return _querryGenerator.GenerateComment(comment);
}

/// <inheritdoc />
public List<string> GetCondition<T>(T entity, List<string> keyColumns)
{
return _querryGenerator.GetCondition<T>(entity, keyColumns);
}

/// <inheritdoc />
public object? EscapeValue(object? input)
{
return _querryGenerator.EscapeValue(input);
}

/// <inheritdoc />
public string EscapeColumn(string? input)
{
return _querryGenerator.EscapeColumn(input);
}

/// <inheritdoc />
public string GenerateBatchSeparator()
{
return _querryGenerator.GenerateBatchSeparator();
}

/// <inheritdoc />
public void Dispose()
{
_querryGenerator.Dispose();
}

#endregion
}

}

0 comments on commit 4b767ab

Please sign in to comment.