Massively simplified QueryBuilder

This commit is contained in:
2020-06-28 00:08:39 +01:00
parent de5bc19590
commit ae69181119
+12 -33
View File
@@ -1,47 +1,26 @@
public static class QueryBuilder
{
private static string NewQueryFromCommand(string select, string from, string where, string query, bool modalRecord, bool exactMatch)
{
string _query = string.Empty;
_query += ($"SELECT \"{select}\"");
if (modalRecord == true)
{
_query += ",* ";
}
else
{
_query += " ";
}
_query += ($"FROM \"main\".\"{from}\"" +
$"WHERE \"{where}\" ");
if (exactMatch == true)
{
_query += ($"LIKE '{query}'");
}
else
{
_query += ($"LIKE '%{query}%'");
}
return _query;
}
public static string GameByName(string name)
{
return NewQueryFromCommand("GameName", "GameEntry", "GameName", name, true, false);
return $"SELECT \"GameName\",*" +
$"FROM \"main\".\"GameEntry\"" +
$"WHERE \"GameName\"" +
$"LIKE \"%{name}%\"";
}
public static string GameById(string id)
{
return NewQueryFromCommand("GameName", "GameEntry", "id", id, true, true);
return $"SELECT \"GameName\",*" +
$"FROM \"main\".\"GameEntry\"" +
$"WHERE \"id\"" +
$"LIKE \"{id}\"";
}
public static string DirectoryById(string id)
{
return NewQueryFromCommand("Path", "Directories", "GameID", id, true, true);
return $"SELECT \"Path\",*" +
$"FROM \"main\".\"Directories\"" +
$"WHERE \"GameID\"" +
$"LIKE \"{id}\"";
}
}