Skip to content

SQL Manager

Imran J edited this page Dec 23, 2018 · 3 revisions

Location

In the Manager folder, and separated by group of data they managed.

How to retrieve data from Database

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).

  • T is the class that represent the sql table.
  • SQLQuery is a string of a hardcoded SQL command.

The data is returned by the method as IEnumerable<T> where T is the sql table class.

Example

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;
    }
}

How to call SQL Manager

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

Clone this wiki locally