refactor(db): Update SqlQueryBuilder references + Various refactors
Consolidates the creation of SQL query builders across multiple classes to ensure a unified approach for database operations. Replaces manual type checks and specific query creators with a generic method for better maintainability and to prevent errors. Improves code readability and reduces duplication, facilitating easier updates in the future.
This commit is contained in:
parent
27fde1f9ac
commit
084411f847
15 changed files with 399 additions and 488 deletions
|
|
@ -23,6 +23,7 @@ using System.Diagnostics.CodeAnalysis;
|
|||
using Microsoft.Data.Sqlite;
|
||||
using MySql.Data.MySqlClient;
|
||||
using Npgsql;
|
||||
using TShockAPI.DB.Queries;
|
||||
|
||||
namespace TShockAPI.DB
|
||||
{
|
||||
|
|
@ -154,6 +155,14 @@ namespace TShockAPI.DB
|
|||
_ => SqlType.Unknown
|
||||
};
|
||||
|
||||
public static IQueryBuilder GetSqlQueryBuilder(this IDbConnection db) => db.GetSqlType() switch
|
||||
{
|
||||
SqlType.Sqlite => new SqliteQueryCreator(),
|
||||
SqlType.Mysql => new MysqlQueryCreator(),
|
||||
SqlType.Postgres => new PostgresQueryCreator(),
|
||||
_ => throw new NotSupportedException("Database type not supported.")
|
||||
};
|
||||
|
||||
private static readonly Dictionary<Type, Func<IDataReader, int, object>> ReadFuncs = new Dictionary
|
||||
<Type, Func<IDataReader, int, object>>
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue