-
Notifications
You must be signed in to change notification settings - Fork 6
SQL Manager
In the Manager folder, and separated by group of data they managed.
You must create a class that inherits from DatabaseManager<T> by replacing the T by the class, then override the method Initialize and add a Initilization attribute over it through the parameters you should pass the InitializationPass value when it will be executed because you can choose the order of the execution of the initilization methods.
I store usually the datas from the database on a dictionary.
To retrieve the data from a table you should do a Database.Query<T>(SQLQuery).
-
Tis the class that represent the sql table. -
SQLQueryis a string of a hardcoded SQL command.
The data is returned by the method as IEnumerable<T> where T is the sql table class.
public class BreedManager : DatabaseManager<BreedManager>
{
Dictionary<byte, BreedRecord> m_breeds = new Dictionary<byte, BreedRecord>();
[Initialization(InitializationPass.First)]
public override void Initialize()
{
m_breeds = Database.Query<BreedRecord>(BreedRecordRelator.FetchQuery).ToDictionary(x => x.Job);
}
public BreedRecord GetBreedByJobId(byte jobId)
{
if(m_breeds.ContainsKey(jobId))
{
return m_breeds[jobId];
}
return null;
}
}To have an access to the methods contained in the class call the singleton like this
Singleton<T>.Instance.GetMethod()
where T is the manager class and GetMethod is the method that you want to call