diff --git a/src/DbSyncKit.Templates.csproj b/src/DbSyncKit.Templates.csproj index 60ff49e..457a6cd 100644 --- a/src/DbSyncKit.Templates.csproj +++ b/src/DbSyncKit.Templates.csproj @@ -6,9 +6,9 @@ enable True True - 1.0.0.0 - 1.0.0.0 - 1.0.0.0 + 1.1.0.0 + 1.1.0.0 + 1.1.0.0 https://dbsynckit.rohit-mahajan.in/ README.md https://github.com/RohitM-IN/DbSyncKit diff --git a/src/Interface/IQueryGenerator.cs b/src/Interface/IQueryGenerator.cs new file mode 100644 index 0000000..8277763 --- /dev/null +++ b/src/Interface/IQueryGenerator.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DbSyncKit.Templates.Interface +{ + /// + /// Defines methods for generating SQL queries and handling query-related operations. + /// + public interface IQueryGenerator : IDisposable + { + /// + /// Generates a SELECT query for retrieving data from a database table. + /// + /// The name of the database table. + /// The list of columns to be selected. + /// The schema name of the database table. + /// A string representing the generated SELECT query. + string GenerateSelectQuery(string tableName, List ListOfColumns, string schemaName); + + /// + /// Generates an UPDATE query for updating data in a database table. + /// + /// The entity with the updated data. + /// The list of key columns used for updating. + /// The list of columns to be excluded from the update. + /// A dictionary representing the properties and their new values to be updated. + /// A string representing the generated UPDATE query. + string GenerateUpdateQuery(T DataContract, List keyColumns, List excludedColumns, (string propName, object propValue)[] editedProperties); + + /// + /// Generates a DELETE query for deleting data from a database table. + /// + /// The entity representing the data to be deleted. + /// The list of key columns used for deletion. + /// A string representing the generated DELETE query. + string GenerateDeleteQuery(T entity, List keyColumns); + + /// + /// Generates an INSERT query for inserting data into a database table. + /// + /// The entity representing the data to be inserted. + /// The list of key columns used for insertion. + /// The list of columns to be excluded from the insertion. + /// A string representing the generated INSERT query. + string GenerateInsertQuery(T entity, List keyColumns, List excludedColumns); + + /// + /// Generates a SQL comment. + /// + /// The comment text. + /// A string representing the generated comment. + string GenerateComment(string comment); + + /// + /// Gets a condition for use in a SQL WHERE clause based on the entity and key columns. + /// + /// The entity for which the condition is generated. + /// The list of key columns used to create the condition. + /// A string representing the generated condition for a SQL WHERE clause. + List GetCondition(T entity, List keyColumns); + + /// + /// Escapes special characters in the input to make it SQL-safe. + /// + /// The input object or string to be escaped. + /// The escaped object or string. + object? EscapeValue(object? input); + + /// + /// Escapes the input column name to be used safely in SQL queries. + /// + /// The input column name to be escaped. + /// The escaped column name. + string EscapeColumn(string? input); + + /// + /// Generates a SQL batch separator ('GO' statement in SQL Server) used to execute batches of SQL statements. + /// + /// A string representing the generated batch separator. + string GenerateBatchSeparator(); + } +} diff --git a/src/QueryGenerationManager.cs b/src/QueryGenerationManager.cs new file mode 100644 index 0000000..620f35c --- /dev/null +++ b/src/QueryGenerationManager.cs @@ -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 +{ + /// + /// Manages the generation of SQL queries for data operations by delegating the query generation tasks + /// to an implementation of the interface. + /// + /// + /// This class acts as a wrapper around an instance of and forwards + /// query generation requests to the underlying implementation. + /// + public class QueryGenerationManager : IQueryGenerator + { + private readonly IQueryGenerator _querryGenerator; + + /// + /// The underlying query generator instance used for actual query generation. + /// + public QueryGenerationManager(IQueryGenerator querryGenerator) + { + _querryGenerator = querryGenerator; + } + + #region Public Methods + /// + public string GenerateSelectQuery(string tableName, List listOfColumns, string schemaName) + { + return _querryGenerator.GenerateSelectQuery(tableName, listOfColumns, schemaName); + } + + /// + public string GenerateUpdateQuery(T DataContract, List keyColumns, List excludedColumns, (string propName, object propValue)[] editedProperties) + { + return _querryGenerator.GenerateUpdateQuery(DataContract, keyColumns, excludedColumns, editedProperties); + } + + /// + public string GenerateDeleteQuery(T entity, List keyColumns) + { + return _querryGenerator.GenerateDeleteQuery(entity, keyColumns); + } + + /// + public string GenerateInsertQuery(T entity, List keyColumns, List excludedColumns) + { + return _querryGenerator.GenerateInsertQuery(entity, keyColumns, excludedColumns); + } + + /// + public string GenerateComment(string comment) + { + return _querryGenerator.GenerateComment(comment); + } + + /// + public List GetCondition(T entity, List keyColumns) + { + return _querryGenerator.GetCondition(entity, keyColumns); + } + + /// + public object? EscapeValue(object? input) + { + return _querryGenerator.EscapeValue(input); + } + + /// + public string EscapeColumn(string? input) + { + return _querryGenerator.EscapeColumn(input); + } + + /// + public string GenerateBatchSeparator() + { + return _querryGenerator.GenerateBatchSeparator(); + } + + /// + public void Dispose() + { + _querryGenerator.Dispose(); + } + + #endregion + } + +}