Переделал хранилище диагнозов
This commit is contained in:
parent
048945c173
commit
db2b7ef24e
@ -8,66 +8,18 @@ namespace MedicalPostgresqlDatabase.Storages
|
||||
public class DiagnosesStorage : AbstractPostgresqlStorage<Diagnose>
|
||||
{
|
||||
private ILogger _logger;
|
||||
public DiagnosesStorage(ILogger<DiagnosesStorage> logger)
|
||||
public DiagnosesStorage(ILogger<DiagnosesStorage> logger) : base("diagnoses", "diagnose_id")
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public override void Delete(int id, out long elapsedMilliseconds)
|
||||
protected override Diagnose CreateEntityFromReader(NpgsqlDataReader reader)
|
||||
{
|
||||
using var connection = GetConnection();
|
||||
connection.Open();
|
||||
using var cmd = new NpgsqlCommand("DELETE FROM diagnoses WHERE diagnose_id = @id", connection);
|
||||
cmd.Parameters.AddWithValue("@id", id);
|
||||
Stopwatch stopwatch = new();
|
||||
stopwatch.Start();
|
||||
cmd.ExecuteNonQuery();
|
||||
stopwatch.Stop();
|
||||
elapsedMilliseconds = stopwatch.ElapsedMilliseconds;
|
||||
}
|
||||
|
||||
public override Diagnose? Get(int id, out long elapsedMilliseconds)
|
||||
{
|
||||
using var connection = GetConnection();
|
||||
connection.Open();
|
||||
using var cmd = new NpgsqlCommand("SELECT * FROM diagnoses WHERE diagnose_id = @id", connection);
|
||||
cmd.Parameters.AddWithValue("@id", id);
|
||||
Stopwatch stopwatch = new();
|
||||
stopwatch.Start();
|
||||
using var reader = cmd.ExecuteReader();
|
||||
stopwatch.Stop();
|
||||
elapsedMilliseconds = stopwatch.ElapsedMilliseconds;
|
||||
if (reader.Read())
|
||||
return new Diagnose
|
||||
{
|
||||
return new Diagnose
|
||||
{
|
||||
Id = reader.GetInt32(0),
|
||||
Name = reader.GetString(1),
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override List<Diagnose> GetAll(out long elapsedMilliseconds)
|
||||
{
|
||||
var items = new List<Diagnose>();
|
||||
using var connection = GetConnection();
|
||||
connection.Open();
|
||||
using var cmd = new NpgsqlCommand("SELECT * FROM diagnoses ORDER BY diagnose_id", connection);
|
||||
Stopwatch stopwatch = new();
|
||||
stopwatch.Start();
|
||||
using var reader = cmd.ExecuteReader();
|
||||
stopwatch.Stop();
|
||||
elapsedMilliseconds = stopwatch.ElapsedMilliseconds;
|
||||
while (reader.Read())
|
||||
{
|
||||
items.Add(new Diagnose
|
||||
{
|
||||
Id = reader.GetInt32(0),
|
||||
Name = reader.GetString(1),
|
||||
});
|
||||
}
|
||||
return items;
|
||||
Id = reader.GetInt32(0),
|
||||
Name = reader.GetString(1),
|
||||
};
|
||||
}
|
||||
|
||||
public override void Insert(Diagnose item, out long elapsedMilliseconds)
|
||||
|
Loading…
x
Reference in New Issue
Block a user