-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/cli
- Loading branch information
Showing
3 changed files
with
182 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} |