Adds SQL Queries for Update, Read and Insert
This commit is contained in:
parent
7af6f7fae6
commit
2c4625e426
4 changed files with 197 additions and 1 deletions
53
TShockAPI/DB/SqlValue.cs
Normal file
53
TShockAPI/DB/SqlValue.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
using System.Data;
|
||||
using MySql.Data.MySqlClient;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace TShockAPI.DB
|
||||
{
|
||||
public class SqlValue
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public object Value { get; set; }
|
||||
|
||||
public SqlValue(string name, object value)
|
||||
{
|
||||
Name = name;
|
||||
Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public class SqlTableEditor
|
||||
{
|
||||
IDbConnection database;
|
||||
IQueryBuilder creator;
|
||||
|
||||
public SqlTableEditor(IDbConnection db, IQueryBuilder provider)
|
||||
{
|
||||
database = db;
|
||||
creator = provider;
|
||||
}
|
||||
|
||||
public void UpdateValues(string table, List<SqlValue> values, List<SqlValue> wheres)
|
||||
{
|
||||
database.Query(creator.UpdateValue(table, values, wheres));
|
||||
}
|
||||
|
||||
public void InsertValues(string table, List<SqlValue> values)
|
||||
{
|
||||
database.Query(creator.InsertValues(table, values));
|
||||
}
|
||||
|
||||
public List<object> ReadColumn(string table, string column, List<SqlValue> wheres)
|
||||
{
|
||||
List<object> values = new List<object>();
|
||||
|
||||
using (var reader = database.QueryReader(creator.ReadColumn(table, wheres)))
|
||||
{
|
||||
while (reader.Read())
|
||||
values.Add(reader.Reader.Get<object>(column));
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue