using Connected.Data.Storage; using Connected.Entities.Storage; using System.Collections.Immutable; using System.Data; namespace Connected.Data.Sql; internal class DatabaseReader : DatabaseCommand, IStorageReader { public DatabaseReader(IStorageOperation operation, IStorageConnection connection) : base(operation, connection) { } public async Task?> Query() { if (Connection is null) return default; try { var result = await Connection.Query(this); if (Connection.Behavior == StorageConnectionMode.Isolated) await Connection.Commit(); return result; } finally { if (Connection.Behavior == StorageConnectionMode.Isolated) { await Connection.Close(); await Connection.DisposeAsync(); Connection = null; } } } public async Task Select() { try { if (Connection is null) return default; var result = await Connection.Select(this); if (Connection.Behavior == StorageConnectionMode.Isolated) await Connection.Commit(); return result; } finally { if (Connection.Behavior == StorageConnectionMode.Isolated) { await Connection.Close(); await Connection.DisposeAsync(); Connection = null; } } } public async Task OpenReader() { if (Connection is null) return default; return await Connection.OpenReader(this); } }