DbSyncKit.DB 0.1.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package DbSyncKit.DB --version 0.1.2
NuGet\Install-Package DbSyncKit.DB -Version 0.1.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DbSyncKit.DB" Version="0.1.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DbSyncKit.DB --version 0.1.2
#r "nuget: DbSyncKit.DB, 0.1.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DbSyncKit.DB as a Cake Addin
#addin nuget:?package=DbSyncKit.DB&version=0.1.2

// Install DbSyncKit.DB as a Cake Tool
#tool nuget:?package=DbSyncKit.DB&version=0.1.2

DbSyncKit: Database Synchronization Library

The Sync library is a comprehensive suite of packages designed to simplify and streamline the process of data synchronization across multiple database platforms. It offers a range of tools, utilities, and interfaces to facilitate efficient and consistent data synchronization operations.

Introduction

Welcome to the Sync Library documentation! This comprehensive guide offers insights into the functionalities and usage of the Sync Library, a collection of packages designed to streamline and simplify the process of data synchronization across diverse database systems.

Overview of the Sync Library

The Sync Library comprises three primary packages: DbSyncKit.Core, DbSyncKit.DB, and DbSyncKit.MSSQL, each serving distinct roles in enabling efficient data synchronization. Additionally, it anticipates future expansion with forthcoming packages, including DbSyncKit.MySQL and DbSyncKit.PostgreSQL, which are under development.

Package Descriptions

  • DbSyncKit.Core: This package forms the core functionality of the Sync Library, providing a robust set of tools and utilities for data synchronization tasks. It aims to optimize synchronization processes for efficiency and speed.

  • DbSyncKit.DB: As a foundational package, DbSyncKit.DB defines a set of interfaces and contracts to establish a consistent interaction layer across various database systems. It ensures a unified approach to database operations for seamless integration.

  • DbSyncKit.MSSQL: This specialized package offers tailored functionalities specifically for Microsoft SQL Server databases. It includes tools for query generation, connection management, and error handling optimized for MSSQL environments.

  • Future Packages: DbSyncKit.MySQL and DbSyncKit.PostgreSQL: These upcoming packages are dedicated to providing similar synchronization capabilities for MySQL and PostgreSQL databases, respectively. Although currently under development, they aim to align with the principles and features of the existing Sync Library packages.

Continue exploring this documentation to learn about installation procedures, usage examples, advanced configurations, FAQs, and more to leverage the Sync Library effectively in your projects.

Configuration and Setup

.NET Core Dependency Injection (DI)

To incorporate the synchronization functionalities provided by DbSyncKit.Core into your application, you can establish Dependency Injection (DI) within your project's Startup class.

  1. Dependency Injection Setup:

    Open your Startup.cs file and configure the DI container to register the Synchronization and QueryGenerator services:

    services.AddScoped<QueryGenerator>();
    services.AddScoped<Synchronization>();
    

    Utilizing services.AddScoped registers these services, allowing them to be injected into your application components as needed.

  2. Usage Example:

    After registering in the DI container, you can inject these services into your classes or controllers:

    using DbSyncKit.Core;
    
    private readonly Synchronization _sync;
    
    public YourServiceOrController(Synchronization sync)
    {
        _sync = sync;
    }
    
    

    Incorporating these services via DI enables seamless integration of DbSyncKit.Core's synchronization features within your application architecture.

Usage Guide

Basic Synchronization

To perform basic data synchronization using the DbSyncKit.Core package, follow these steps:

  1. Instantiate Synchronization:

    using DbSyncKit.Core;
    
    // Instantiate the Synchronization class
    Synchronization _sync = new Synchronization(new QueryGenerator());
    

    or with DI

    using DbSyncKit.Core;
    
    private readonly Synchronization _sync;
    
    public YourServiceOrController(Synchronization sync)
    {
        _sync = sync;
    }
    
    

    This creates an instance of the Synchronization class with a QueryGenerator necessary for generating SQL queries.

  2. Create Database Instances:

    using DbSyncKit.Core;
    
    // Instantiate source database connection
    IDatabase sourceDatabase = new Connection("(localdb)\\MSSQLLocalDB", "SourceChinook", true);
    
    // Instantiate destination database connection
    IDatabase destinationDatabase = new Connection("(localdb)\\MSSQLLocalDB", "DestinationChinook", true);
    

    Replace "(localdb)\\MSSQLLocalDB" with your specific server address, and "SourceChinook" and "DestinationChinook" with the names of your source and destination databases, respectively. The last parameter true indicates the usage of integrated security for authentication. Adjust the parameters based on your authentication requirements.

  3. Entity Configuration Example (Album Entity):

    To configure entities like the Album entity, apply attributes from the DbSyncKit.DB.Attributes namespace to the entity class.

    using DbSyncKit.DB.Attributes;
    using DbSyncKit.DB.Extensions;
    using DbSyncKit.DB.Utils;
    using System.Data;
    
    [TableName("Album"), TableSchema("dbo")]
    public class Album : DataContractUtility<Album>
    {
        [KeyProperty(isPrimaryKey: true)]
        public int AlbumId { get; set; }
        public string Title { get; set; }
        public int ArtistId { get; set; }
    
        public Album(DataRow albumInfo)
        {
            // Initialization code for Album properties from DataRow
        }
    }
    
    • [TableName]: Specifies the name of the table corresponding to this entity in the database.
    • [TableSchema]: Specifies the schema of the table.
    • [KeyProperty]: Defines a property as the primary key for the entity.
  4. Available Attributes for Configuration:

    • [TableName]: Specifies the name of the table.
    • [TableSchema]: Specifies the schema of the table.
    • [KeyProperty]: Defines a property as a key property.
    • [ExcludedProperty]: Excludes a property from specific operations.
    • [GenerateInsertWithID]: Controls the inclusion of the ID property in the insert query generation, allowing fine-tuning of insertion behavior.
      • GenerateWithID: Determines whether the ID property should be included in the insert query generation. Possible values are true (to include the ID property) or false (to exclude the ID property).
      • IncludeIdentityInsert: Indicates whether to include database-specific SQL statements during insert query generation affecting identity insert behavior. Default value is true.
  5. Perform Synchronization for Specific Entity:

    // Example: Synchronize data for a specific entity
    var entityData = _sync.SyncData<YourEntity>(sourceDatabase, destinationDatabase);
    

    Replace <YourEntity> with the specific entity type you want to synchronize. sourceDatabase and destinationDatabase should be instances of the IDatabase interface representing your source and destination databases.

  6. Access Synchronization Results:

    // Example: Access synchronization results for added, edited, and deleted records
    Console.WriteLine($"Added: {entityData.Added.Count} Edited: {entityData.Edited.Count} Deleted: {entityData.Deleted.Count}");
    Console.WriteLine($"Total Source Data: {entityData.SourceDataCount}");
    Console.WriteLine($"Total Destination Data: {entityData.DestinaionDataCount}");
    
    // Retrieve SQL query generated during synchronization
    var query = sync.GetSqlQueryForSyncData(entityData);
    Console.WriteLine(query);
    

    This snippet showcases how to access statistics related to added, edited, and deleted records, as well as the total counts of source and destination data. Additionally, it retrieves the SQL query generated during synchronization.

  7. Repeat for Other Entities:

    Repeat the synchronization process (steps 3-4) for other entity types as needed by replacing <YourEntity> with the desired entity type.

  8. Handle Errors:

    Ensure to handle any exceptions that might occur during the synchronization process using appropriate error handling mechanisms.

Great! Here's the revised information:

Contribution Guidelines

Contributions to the DbSyncKit.Core, DbSyncKit.DB, and DbSyncKit.MSSQL packages are welcome! To contribute, follow these steps:

  1. Fork the Repository: Fork the repository to your GitHub account.

  2. Clone the Repository: Clone the forked repository to your local machine:

    git clone https://github.com/RohitM-IN/DbSyncKit.git
    
  3. Create a Branch: Create a new branch for your changes:

    git checkout -b feature/your-feature-name
    
  4. Make Changes: Make necessary changes in the codebase.

  5. Commit Changes: Commit your changes and provide descriptive commit messages:

    git commit -m "Add your descriptive message here"
    
  6. Push Changes: Push your changes to your forked repository:

    git push origin feature/your-feature-name
    
  7. Create Pull Request: Create a Pull Request (PR) from your forked repository to the original repository.

Support and Contact Information

For any support, queries, or feedback regarding the DbSyncKit.Core, DbSyncKit.DB, and DbSyncKit.MSSQL packages, feel free to contact us:

License Information

DbSyncKit.Core, DbSyncKit.DB, and DbSyncKit.MSSQL packages are licensed under the MIT License. For detailed information, refer to the LICENSE file in the repository.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on DbSyncKit.DB:

Package Downloads
DbSyncKit.Core

The core framework of DbSyncKit, offering essential functionalities for seamless data synchronization. Built with extensibility and flexibility in mind, DbSyncKit.Core forms the foundation for all DbSyncKit packages, ensuring a robust synchronization experience.

DbSyncKit.MSSQL

Enhance MSSQL database interactions with DbSyncKit.MSSQL. This package extends DbSyncKit.DB, offering specialized features tailored for Microsoft SQL Server. Explore the package documentation for detailed functionalities and usage guidelines.

DbSyncKit.MySQL

DbSyncKit.MySQL extends DbSyncKit.DB, offering MySQL-specific features for efficient data synchronization. Streamline your MySQL database interactions with DbSyncKit.MySQL. Explore its functionalities in the package documentation.

DbSyncKit.PostgreSQL

Specialized package for PostgreSQL database integration in DbSyncKit. Enables efficient data synchronization tailored for PostgreSQL environments.

DbSyncKit.SQLite

Enhance your SQLite database queries with DbSyncKit.Templates.SQLite. This package delivers templates for SELECT, INSERT, UPDATE, DELETE, and COMMENT queries, simplifying SQL operations for improved readability and efficiency.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.4.0.1 113 6/8/2024
1.4.0 103 4/28/2024
1.3.0 142 3/5/2024
1.2.1 153 2/8/2024
1.2.0 167 1/13/2024
1.1.0.1 146 1/6/2024
1.1.0 111 1/6/2024
1.0.1 109 1/2/2024
1.0.0 172 12/31/2023
0.4.0 131 12/25/2023
0.3.0 120 12/24/2023
0.2.1 147 12/23/2023
0.2.0 130 12/18/2023
0.1.2 122 12/12/2023
0.1.1 115 12/12/2023
0.1.0.2 112 12/11/2023
0.1.0 118 12/11/2023

### Feature
- Added Batching for running scripts now will include GO for MSSQL or similar statements for MYSQL or Postgres