using Connected.Data.Storage; using Connected.Entities.Storage; namespace Connected.Data.Sql; internal class DatabaseWriter : DatabaseCommand, IStorageWriter { public DatabaseWriter(IStorageOperation operation, IStorageConnection connection) : base(operation, connection) { } public async Task Execute() { if (Connection is null) return -1; try { var recordsAffected = await Connection.Execute(this); if (Connection.Behavior == StorageConnectionMode.Isolated) await Connection.Commit(); return recordsAffected; } finally { if (Connection.Behavior == StorageConnectionMode.Isolated) { await Connection.Close(); await Connection.DisposeAsync(); Connection = null; } } } }