Added missing functions needed to support string based ids for a few MySqlSession functions. Added the ability to get the name of a table from a row type. Bumped package version to 1.1.6
This commit is contained in:
		| @@ -7,7 +7,7 @@ | ||||
|     <AssemblyName>MontoyaTech.MySqlPlus</AssemblyName> | ||||
|     <RootNamespace>MontoyaTech.MySqlPlus</RootNamespace> | ||||
|     <Title>MontoyaTech.MySqlPlus</Title> | ||||
|     <Version>1.1.5</Version> | ||||
|     <Version>1.1.6</Version> | ||||
|     <Company>MontoyaTech</Company> | ||||
|     <Description>A simple C# library to help work with MySql.</Description> | ||||
|     <Copyright>MontoyaTech 2023</Copyright> | ||||
|   | ||||
| @@ -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; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Attempts to return the table name of a Type that | ||||
|         /// has a MySqlRow attribute. | ||||
|         /// </summary> | ||||
|         /// <typeparam name="T"></typeparam> | ||||
|         /// <returns></returns> | ||||
|         public static string GetName<T>() | ||||
|         { | ||||
|             var row = typeof(T).GetCustomAttribute<MySqlRow>(); | ||||
|  | ||||
|             if (row == null) | ||||
|                 throw new InvalidOperationException("Type is not a MySqlRow."); | ||||
|  | ||||
|             return row.Name; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -112,6 +112,21 @@ namespace MontoyaTech.MySqlPlus | ||||
|             return instance; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets a row in the db by it's id. | ||||
|         /// </summary> | ||||
|         /// <typeparam name="T"></typeparam> | ||||
|         /// <param name="id"></param> | ||||
|         /// <returns></returns> | ||||
|         public T Get<T>(string id) | ||||
|         { | ||||
|             var instance = typeof(T).CreateInstance<T>(); | ||||
|  | ||||
|             this.Get<T>(instance, id); | ||||
|  | ||||
|             return instance; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets a row in the db by it's id and populates an existing instance of the row. | ||||
|         /// </summary> | ||||
| @@ -129,6 +144,23 @@ namespace MontoyaTech.MySqlPlus | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets a row in the db by it's id and populates an existing instance of the row. | ||||
|         /// </summary> | ||||
|         /// <typeparam name="T"></typeparam> | ||||
|         /// <param name="row"></param> | ||||
|         /// <param name="id"></param> | ||||
|         public void Get<T>(T row, string id) | ||||
|         { | ||||
|             using (var command = new MySqlCommand()) | ||||
|             { | ||||
|                 command.Get<T>(id); | ||||
|  | ||||
|                 using (var reader = this.Connection.ExecuteReader(command)) | ||||
|                     reader.Read(row); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the rows of a given type in the db. | ||||
|         /// </summary> | ||||
| @@ -215,6 +247,21 @@ namespace MontoyaTech.MySqlPlus | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Deletes a row in the db by it's id. | ||||
|         /// </summary> | ||||
|         /// <typeparam name="T"></typeparam> | ||||
|         /// <param name="id"></param> | ||||
|         public void Delete<T>(string id) | ||||
|         { | ||||
|             using (var command = new MySqlCommand()) | ||||
|             { | ||||
|                 command.Delete<T>(id); | ||||
|  | ||||
|                 this.Connection.ExecuteNonQuery(command); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Deletes all the rows of a given type in the db. | ||||
|         /// </summary> | ||||
| @@ -288,6 +335,16 @@ namespace MontoyaTech.MySqlPlus | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Returns the name of the table for a given row type. | ||||
|         /// </summary> | ||||
|         /// <typeparam name="T"></typeparam> | ||||
|         /// <returns></returns> | ||||
|         public string GetTable<T>() | ||||
|         { | ||||
|             return MySqlRow.GetName<T>(); | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Executes a data reader for a command and retrys if the database goes away or glitches. | ||||
|         /// </summary> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user