public async Task ExecuteAsync(string connection, string sql, object parameters) { using (var c = new MySqlData.MySqlConnection(connection)) { _log.LogTrace <MySqlQuery>($"EXECUTE: {sql}. Parameters: {JsonConvert.SerializeObject(parameters)}"); await c.OpenAsync(); await c.ExecuteAsync(sql, parameters); await c.CloseAsync(); } }
public async Task <T> ExecuteScalarAsync <T>(string connection, string sql, object parameters) { T result = default; using (var c = new MySqlData.MySqlConnection(connection)) { _log.LogTrace <MySqlQuery>($"EXECUTE: {sql}. Parameters: {JsonConvert.SerializeObject(parameters)}"); await c.OpenAsync(); result = await c.ExecuteScalarAsync <T>(sql, parameters); await c.CloseAsync(); } return(result); }
public async Task <List <T> > GetAsync <T>(string sql, object parameters) { var result = new List <T>(); using (var connection = new MySqlData.MySqlConnection(_connection)) { _log.LogTrace <MySqlQuery>($"SELECT: {sql}. Parameters: {JsonConvert.SerializeObject(parameters)}"); await connection.OpenAsync(); var query = await connection.QueryAsync <T>(sql, parameters); result = query.ToList(); await connection.CloseAsync(); } return(result.ToList()); }