PlusEMU icon indicating copy to clipboard operation
PlusEMU copied to clipboard

Replace QueryReactor with Dapper

Open 80O opened this issue 3 years ago • 2 comments

The current database query mechanism feels bloated. By using dapper we can simplify querying objects from the database. Dapper is simple enough to replace older queries. https://www.learndapper.com/

Generally there are 5 things required to query the data:

  • DbClient
  • Executing the statement
  • Looping over each result
  • Creating a new instance
  • Converting the parameters to the right type

Utilizing dapper we can simplify the last 3 steps:

using var connection = _database.Connection();
var data = await connection.QueryAsync<DataObject>("SELECT id, name, description FROM table WHERE id => @id", new { id = 3});

This is a good first issue to get familiar with parts of the emulator as the queries can be changed one by one. Make sure to test them when you submit your PR!

Note: Do not use async calls without awaiting them. Note: Do not create async voids! Note: Use the non async method call (The one without -Async appended to the method name) in a non async context.

80O avatar Apr 23 '22 19:04 80O

This is a continous issue and should be done in small pull requests.

80O avatar Aug 10 '22 15:08 80O

Most queries are simple RunQuery calls that can easily be replaced with ExecuteAsync equivalent for dapper. Note: Do not forget to change the parameters from string interpolation to an dynamic object passed.

80O avatar Jan 31 '23 12:01 80O