Skip to content

Commit 5df7c7a

Browse files
committed
Change Package Name
0 parents  commit 5df7c7a

17 files changed

Lines changed: 810 additions & 0 deletions
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
namespace DbSyncKit.DB.Attributes
2+
{
3+
/// <summary>
4+
/// Specifies whether a property should be excluded from certain operations, such as data fetching and query generation.
5+
/// </summary>
6+
/// <remarks>
7+
/// This attribute can be applied to properties within a class to indicate that the marked property should
8+
/// be excluded from specific operations. For example, it can be used to exclude a property from data fetching
9+
/// and query generation.
10+
/// </remarks>
11+
[AttributeUsage(AttributeTargets.Property)]
12+
public class ExcludedPropertyAttribute : Attribute
13+
{
14+
/// <summary>
15+
/// Gets a value indicating whether the property should be excluded from operations.
16+
/// </summary>
17+
/// <value><c>true</c> if the property should be excluded; otherwise, <c>false</c>.</value>
18+
public bool Excluded { get; }
19+
20+
/// <summary>
21+
/// Initializes a new instance of the <see cref="ExcludedPropertyAttribute"/> class.
22+
/// </summary>
23+
/// <param name="excluded">Indicates whether the property should be excluded. Default is <c>true</c>.</param>
24+
public ExcludedPropertyAttribute(bool excluded = true)
25+
{
26+
Excluded = excluded;
27+
}
28+
}
29+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
namespace DbSyncKit.DB.Attributes
2+
{
3+
/// <summary>
4+
/// Specifies whether the insert query generation for a class should include the ID property or exclude it.
5+
/// </summary>
6+
/// <remarks>
7+
/// This attribute can be applied to classes to indicate whether the ID property's value should be included
8+
/// in the insert query generation. For example, it can be used to determine whether the ID property should be
9+
/// part of the generated insert query or excluded.
10+
/// </remarks>
11+
[AttributeUsage(AttributeTargets.Class)]
12+
public class GenerateInsertWithIDAttribute : Attribute
13+
{
14+
/// <summary>
15+
/// Gets a value indicating whether the insert query generation should include the ID property.
16+
/// </summary>
17+
/// <value><c>true</c> if the insert query should include the ID property; otherwise, <c>false</c>.</value>
18+
public bool GenerateWithID { get; }
19+
20+
/// <summary>
21+
/// Initializes a new instance of the <see cref="GenerateInsertWithIDAttribute"/> class.
22+
/// </summary>
23+
/// <param name="generateWithID">Indicates whether the insert query generation should include the ID property.
24+
/// Default is <c>true</c>.</param>
25+
public GenerateInsertWithIDAttribute(bool generateWithID = true)
26+
{
27+
GenerateWithID = generateWithID;
28+
}
29+
30+
31+
}
32+
}

Attributes/KeyPropertyAttribute.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
namespace DbSyncKit.DB.Attributes
2+
{
3+
/// <summary>
4+
/// Specifies whether a property should be considered as a key property.
5+
/// </summary>
6+
/// <remarks>
7+
/// This attribute can be applied to properties within a class to indicate that the marked property
8+
/// should be treated as a key property. It is typically used to identify properties that uniquely
9+
/// identify instances of the class in database operations such as insert, update, and delete.
10+
/// </remarks>
11+
[AttributeUsage(AttributeTargets.Property)]
12+
public class KeyPropertyAttribute : Attribute
13+
{
14+
/// <summary>
15+
/// Gets a value indicating whether the property should be considered as a key property.
16+
/// </summary>
17+
/// <value><c>true</c> if the property should be treated as a key property; otherwise, <c>false</c>.</value>
18+
public bool KeyProperty { get; }
19+
20+
/// <summary>
21+
/// Gets a value indicating whether the property is a primary key.
22+
/// </summary>
23+
/// <value><c>true</c> if the property is a primary key; otherwise, <c>false</c>.</value>
24+
public bool IsPrimaryKey { get; }
25+
26+
/// <summary>
27+
/// Initializes a new instance of the <see cref="KeyPropertyAttribute"/> class.
28+
/// </summary>
29+
/// <param name="keyProperty">Indicates whether the property should be considered as a key property.
30+
/// Default is <c>true</c>.</param>
31+
/// <param name="isPrimaryKey">Indicates whether the property is a primary key.
32+
/// Default is <c>false</c>.</param>
33+
public KeyPropertyAttribute(bool keyProperty = true, bool isPrimaryKey = false)
34+
{
35+
KeyProperty = keyProperty;
36+
IsPrimaryKey = isPrimaryKey;
37+
}
38+
}
39+
}

Attributes/TableNameAttribute.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace DbSyncKit.DB.Attributes
2+
{
3+
/// <summary>
4+
/// Specifies the name of the database table associated with a class.
5+
/// </summary>
6+
/// <remarks>
7+
/// This attribute can be applied to classes to indicate the name of the corresponding
8+
/// database table. It is used to associate a class with a specific table in database operations.
9+
/// </remarks>
10+
[AttributeUsage(AttributeTargets.Class)]
11+
public class TableNameAttribute : Attribute
12+
{
13+
/// <summary>
14+
/// Gets the name of the database table.
15+
/// </summary>
16+
public string TableName { get; }
17+
18+
/// <summary>
19+
/// Initializes a new instance of the <see cref="TableNameAttribute"/> class.
20+
/// </summary>
21+
/// <param name="tableName">The name of the database table associated with the class.</param>
22+
public TableNameAttribute(string tableName)
23+
{
24+
TableName = tableName ?? throw new ArgumentNullException(nameof(tableName)); ;
25+
}
26+
}
27+
}

Attributes/TableSchemaAttribute.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace DbSyncKit.DB.Attributes
2+
{
3+
/// <summary>
4+
/// Specifies the schema name of the database table associated with a class.
5+
/// </summary>
6+
/// <remarks>
7+
/// This attribute can be applied to classes to indicate the schema name of the corresponding
8+
/// database table. It is used to associate a class with a specific schema in database operations.
9+
/// </remarks>
10+
[AttributeUsage(AttributeTargets.Class)]
11+
public class TableSchemaAttribute : Attribute
12+
{
13+
/// <summary>
14+
/// Gets the schema name of the database table.
15+
/// </summary>
16+
public string SchemaName { get; }
17+
18+
/// <summary>
19+
/// Initializes a new instance of the <see cref="TableSchemaAttribute"/> class.
20+
/// </summary>
21+
/// <param name="schemaName">The schema name of the database table associated with the class.</param>
22+
public TableSchemaAttribute(string schemaName)
23+
{
24+
SchemaName = schemaName ?? throw new ArgumentNullException(nameof(schemaName));
25+
}
26+
}
27+
}

DatabaseManager.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using DbSyncKit.DB.Interface;
2+
using System.Data;
3+
4+
5+
namespace DbSyncKit.DB
6+
{
7+
/// <summary>
8+
/// Manages database operations for a specific database provider implementing the IDatabase interface.
9+
/// </summary>
10+
/// <typeparam name="T">Type of the database provider implementing IDatabase.</typeparam>
11+
public class DatabaseManager<T> : IDisposable where T : IDatabase
12+
{
13+
private readonly T _databaseProvider;
14+
15+
/// <summary>
16+
/// Initializes a new instance of the DatabaseManager class.
17+
/// </summary>
18+
/// <param name="databaseProvider">The instance of the database provider.</param>
19+
public DatabaseManager(T databaseProvider)
20+
{
21+
_databaseProvider = databaseProvider ?? throw new ArgumentNullException(nameof(databaseProvider));
22+
}
23+
24+
/// <summary>
25+
/// Executes a query against the database and returns a list of results for a specific data type.
26+
/// </summary>
27+
/// <typeparam name="TItem">The type of data to retrieve, constrained to be an instance of DataContractUtility.</typeparam>
28+
/// <param name="query">The SQL query to execute.</param>
29+
/// <param name="tableName">The name of the table associated with the query.</param>
30+
/// <returns>A list of results of type <typeparamref name="TItem"/>.</returns>
31+
public List<TItem> ExecuteQuery<TItem>(string query, string tableName) where TItem : IDataContractComparer
32+
{
33+
List<TItem> result = new List<TItem>();
34+
35+
var dataset = _databaseProvider.ExecuteQuery(query, tableName);
36+
37+
if (dataset.Tables.Contains(tableName))
38+
{
39+
foreach (DataRow row in dataset.Tables[tableName]!.Rows)
40+
{
41+
result.Add((TItem)Activator.CreateInstance(typeof(TItem), new object[] { row })!);
42+
}
43+
}
44+
45+
return result;
46+
}
47+
48+
/// <summary>
49+
/// Disposes of the DatabaseManager.
50+
/// </summary>
51+
public void Dispose()
52+
{
53+
// No additional cleanup required
54+
}
55+
}
56+
}

DbSyncKit.DB.csproj

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<GenerateDocumentationFile>True</GenerateDocumentationFile>
8+
<AssemblyVersion>0.1.0.0</AssemblyVersion>
9+
<FileVersion>0.1.0.0</FileVersion>
10+
<Version>0.1.0.0</Version>
11+
<PackageReadmeFile>README.md</PackageReadmeFile>
12+
<RepositoryUrl>https://github.com/RohitM-IN/DbSyncKit</RepositoryUrl>
13+
<PackageProjectUrl>https://github.com/RohitM-IN/DbSyncKit</PackageProjectUrl>
14+
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
15+
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
16+
</PropertyGroup>
17+
18+
<ItemGroup>
19+
<None Include="..\LICENSE.txt">
20+
<Pack>True</Pack>
21+
<PackagePath>\</PackagePath>
22+
</None>
23+
<None Include="..\README.md">
24+
<Pack>True</Pack>
25+
<PackagePath>\</PackagePath>
26+
</None>
27+
</ItemGroup>
28+
29+
</Project>

Enum/DatabaseProvider.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
namespace DbSyncKit.DB.Enum
2+
{
3+
/// <summary>
4+
/// Enumerates the supported database providers.
5+
/// </summary>
6+
public enum DatabaseProvider
7+
{
8+
/// <summary>
9+
/// Microsoft SQL Server.
10+
/// </summary>
11+
MSSQL,
12+
13+
/// <summary>
14+
/// SQLite database engine.
15+
/// </summary>
16+
SQLite,
17+
18+
/// <summary>
19+
/// MySQL database server.
20+
/// </summary>
21+
MySQL,
22+
23+
/// <summary>
24+
/// PostgreSQL database server.
25+
/// </summary>
26+
PostgreSQL
27+
}
28+
29+
}

Extensions/DataRowExtensions.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using DbSyncKit.DB.Utils;
2+
using System.Data;
3+
namespace DbSyncKit.DB.Extensions
4+
{
5+
/// <summary>
6+
/// Extension methods for DataRow to simplify retrieving values from columns.
7+
/// </summary>
8+
public static class DataRowExtensions
9+
{
10+
/// <summary>
11+
/// Gets the value of a specified column in the DataRow, converted to the specified type.
12+
/// </summary>
13+
/// <typeparam name="T">The type to which the column value should be converted.</typeparam>
14+
/// <param name="row">The DataRow from which to retrieve the value.</param>
15+
/// <param name="columnName">The name of the column.</param>
16+
/// <returns>The value of the specified column, converted to the specified type.</returns>
17+
/// <remarks>
18+
/// This extension method is intended for use with classes that inherit from <see cref="DataContractUtility{T}"/>.
19+
/// </remarks>
20+
public static T GetValue<T>(this DataRow row, string columnName)
21+
{
22+
// Check if the DataRow is null
23+
if (row == null)
24+
{
25+
throw new ArgumentNullException(nameof(row));
26+
}
27+
28+
// Check if the column exists in the DataRow's table
29+
if (row.Table.Columns.Contains(columnName))
30+
{
31+
// Retrieve the value from the specified column
32+
object value = row[columnName];
33+
34+
// Check if the value is not DBNull
35+
if (value != DBNull.Value)
36+
{
37+
// Convert the value to the specified type
38+
return (T)Convert.ChangeType(value, typeof(T));
39+
}
40+
}
41+
42+
// Handle the case when the column doesn't exist or the value is DBNull return a default value
43+
return default(T)!;
44+
}
45+
}
46+
}
47+

0 commit comments

Comments
 (0)