Refactored GsmDB
This commit is contained in:
+2
-20
@@ -1,16 +1,13 @@
|
||||
using Microsoft.Data.Sqlite;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Dapper;
|
||||
using FireLance.Interfaces;
|
||||
using FireLance.Models;
|
||||
|
||||
namespace Gsm
|
||||
{
|
||||
public class GsmDB : IDatabaseConnection
|
||||
public abstract class GsmDB : IDatabaseConnection
|
||||
{
|
||||
private SqliteConnection DBConnection = new SqliteConnection();
|
||||
internal SqliteConnection DBConnection = new SqliteConnection();
|
||||
|
||||
public void OpenConnection(string dbLocation, int port)
|
||||
{
|
||||
@@ -32,20 +29,5 @@ namespace Gsm
|
||||
{
|
||||
return Convert.ToBoolean(DBConnection.State);
|
||||
}
|
||||
|
||||
public List<GameEntryModel> QueryGameById(string id)
|
||||
{
|
||||
return (List<GameEntryModel>) DBConnection.Query<GameEntryModel>(QueryBuilder.GameEntryByGameId(id), new DynamicParameters());
|
||||
}
|
||||
|
||||
public List<DirectoriesModel> QueryDirectoryById(string id)
|
||||
{
|
||||
return (List<DirectoriesModel>) DBConnection.Query<DirectoriesModel>(QueryBuilder.DirectoryByGameId(id), new DynamicParameters());
|
||||
}
|
||||
|
||||
public List<GameEntryModel> QueryGameByName(string name)
|
||||
{
|
||||
return (List<GameEntryModel>) DBConnection.Query<GameEntryModel>(QueryBuilder.GameEntryByName(name), new DynamicParameters());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
using Dapper;
|
||||
using FireLance.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Gsm
|
||||
{
|
||||
public class GsmRO : GsmDB
|
||||
{
|
||||
public List<T> LoadRecords<T>(string select, string from, string column, string query, bool exactMatch)
|
||||
{
|
||||
string command = $"SELECT \"{select}\",*" +
|
||||
$"FROM \"main\".\"{from}\"" +
|
||||
$"WHERE \"{column}\"";
|
||||
|
||||
if (exactMatch == true)
|
||||
{
|
||||
command += $"LIKE \"{query}\"";
|
||||
}
|
||||
else
|
||||
{
|
||||
command += $"LIKE \"%{query}%\"";
|
||||
}
|
||||
|
||||
return (List<T>) DBConnection.Query<T>(command, new DynamicParameters());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace Gsm
|
||||
{
|
||||
public struct GsmStruct
|
||||
{
|
||||
public static class Tables
|
||||
{
|
||||
public static string Directories { get { return "Directories"; } }
|
||||
public static string GameEntry { get { return "GameEntry"; } }
|
||||
public static string RegistryList { get { return "RegistryList"; } }
|
||||
}
|
||||
|
||||
public static class DirectoryColumns
|
||||
{
|
||||
public static string GameID { get { return "GameID"; } }
|
||||
}
|
||||
|
||||
public static class GameEntries
|
||||
{
|
||||
public static string GameID { get { return "id"; } }
|
||||
public static string GameName { get { return "GameName"; } }
|
||||
}
|
||||
|
||||
public static class RegistryColumns
|
||||
{
|
||||
public static string GameID { get { return "GameID"; } }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
public static class QueryBuilder
|
||||
{
|
||||
public static string GameEntryByName(string name)
|
||||
{
|
||||
return $"SELECT \"GameName\",*" +
|
||||
$"FROM \"main\".\"GameEntry\"" +
|
||||
$"WHERE \"GameName\"" +
|
||||
$"LIKE \"%{name}%\"";
|
||||
}
|
||||
|
||||
public static string GameEntryByGameId(string id)
|
||||
{
|
||||
return $"SELECT \"GameName\",*" +
|
||||
$"FROM \"main\".\"GameEntry\"" +
|
||||
$"WHERE \"id\"" +
|
||||
$"LIKE \"{id}\"";
|
||||
}
|
||||
|
||||
public static string DirectoryByGameId(string id)
|
||||
{
|
||||
return $"SELECT \"Path\",*" +
|
||||
$"FROM \"main\".\"Directories\"" +
|
||||
$"WHERE \"GameID\"" +
|
||||
$"LIKE \"{id}\"";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user