diff --git a/MySqlPlus/MySqlPlus.csproj b/MySqlPlus/MySqlPlus.csproj
index 99113f0..c1a3996 100644
--- a/MySqlPlus/MySqlPlus.csproj
+++ b/MySqlPlus/MySqlPlus.csproj
@@ -7,7 +7,7 @@
MontoyaTech.MySqlPlus
MontoyaTech.MySqlPlus
MontoyaTech.MySqlPlus
- 1.1.5
+ 1.1.6
MontoyaTech
A simple C# library to help work with MySql.
MontoyaTech 2023
diff --git a/MySqlPlus/MySqlRow.cs b/MySqlPlus/MySqlRow.cs
index 3405b38..a9436bc 100644
--- a/MySqlPlus/MySqlRow.cs
+++ b/MySqlPlus/MySqlRow.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Reflection;
using System.Text;
using System.Threading.Tasks;
@@ -31,5 +32,21 @@ namespace MontoyaTech.MySqlPlus
{
this.Name = name;
}
+
+ ///
+ /// Attempts to return the table name of a Type that
+ /// has a MySqlRow attribute.
+ ///
+ ///
+ ///
+ public static string GetName()
+ {
+ var row = typeof(T).GetCustomAttribute();
+
+ if (row == null)
+ throw new InvalidOperationException("Type is not a MySqlRow.");
+
+ return row.Name;
+ }
}
}
diff --git a/MySqlPlus/MySqlSession.cs b/MySqlPlus/MySqlSession.cs
index 086df96..05c015c 100644
--- a/MySqlPlus/MySqlSession.cs
+++ b/MySqlPlus/MySqlSession.cs
@@ -112,6 +112,21 @@ namespace MontoyaTech.MySqlPlus
return instance;
}
+ ///
+ /// Gets a row in the db by it's id.
+ ///
+ ///
+ ///
+ ///
+ public T Get(string id)
+ {
+ var instance = typeof(T).CreateInstance();
+
+ this.Get(instance, id);
+
+ return instance;
+ }
+
///
/// Gets a row in the db by it's id and populates an existing instance of the row.
///
@@ -129,6 +144,23 @@ namespace MontoyaTech.MySqlPlus
}
}
+ ///
+ /// Gets a row in the db by it's id and populates an existing instance of the row.
+ ///
+ ///
+ ///
+ ///
+ public void Get(T row, string id)
+ {
+ using (var command = new MySqlCommand())
+ {
+ command.Get(id);
+
+ using (var reader = this.Connection.ExecuteReader(command))
+ reader.Read(row);
+ }
+ }
+
///
/// Gets all the rows of a given type in the db.
///
@@ -215,6 +247,21 @@ namespace MontoyaTech.MySqlPlus
}
}
+ ///
+ /// Deletes a row in the db by it's id.
+ ///
+ ///
+ ///
+ public void Delete(string id)
+ {
+ using (var command = new MySqlCommand())
+ {
+ command.Delete(id);
+
+ this.Connection.ExecuteNonQuery(command);
+ }
+ }
+
///
/// Deletes all the rows of a given type in the db.
///
@@ -288,6 +335,16 @@ namespace MontoyaTech.MySqlPlus
}
}
+ ///
+ /// Returns the name of the table for a given row type.
+ ///
+ ///
+ ///
+ public string GetTable()
+ {
+ return MySqlRow.GetName();
+ }
+
///
/// Executes a data reader for a command and retrys if the database goes away or glitches.
///