diff --git a/Directory.Build.props b/Directory.Build.props index 75f5a0da..d0b51139 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 6.0.0-alpha.2 + 6.0.0-alpha.3 11.0 enable enable diff --git a/src/Weasel.Core/CommandBuilderBase.cs b/src/Weasel.Core/CommandBuilderBase.cs index b9035aeb..e6cafaeb 100644 --- a/src/Weasel.Core/CommandBuilderBase.cs +++ b/src/Weasel.Core/CommandBuilderBase.cs @@ -136,7 +136,7 @@ public async Task> FetchList(TConnection conn, Func(); - using var reader = await cmd.ExecuteReaderAsync(cancellation).ConfigureAwait(false); + await using var reader = await cmd.ExecuteReaderAsync(cancellation).ConfigureAwait(false); while (await reader.ReadAsync(cancellation).ConfigureAwait(false)) { list.Add(await transform(reader).ConfigureAwait(false)); diff --git a/src/Weasel.Core/CommandExtensions.cs b/src/Weasel.Core/CommandExtensions.cs index be209cba..bb77b848 100644 --- a/src/Weasel.Core/CommandExtensions.cs +++ b/src/Weasel.Core/CommandExtensions.cs @@ -124,7 +124,7 @@ public static async Task> FetchList(this DbCommand cmd, Func { var list = new List(); - using var reader = await cmd.ExecuteReaderAsync(cancellation).ConfigureAwait(false); + await using var reader = await cmd.ExecuteReaderAsync(cancellation).ConfigureAwait(false); while (await reader.ReadAsync(cancellation).ConfigureAwait(false)) { list.Add(await transform(reader).ConfigureAwait(false)); @@ -164,7 +164,7 @@ public static async Task> FetchList(this DbCommand cmd, Func /// public static async Task FetchOne(this DbCommand cmd, CancellationToken cancellation = default) { - using var reader = await cmd.ExecuteReaderAsync(cancellation).ConfigureAwait(false); + await using var reader = await cmd.ExecuteReaderAsync(cancellation).ConfigureAwait(false); if (await reader.ReadAsync(cancellation).ConfigureAwait(false)) { if (await reader.IsDBNullAsync(0, cancellation).ConfigureAwait(false)) diff --git a/src/Weasel.Core/ConnectionSourceExtensions.cs b/src/Weasel.Core/ConnectionSourceExtensions.cs index 6df31568..2e64af6e 100644 --- a/src/Weasel.Core/ConnectionSourceExtensions.cs +++ b/src/Weasel.Core/ConnectionSourceExtensions.cs @@ -37,7 +37,7 @@ public static void RunSql(this IConnectionSource source, string sql) where /// public static async Task RunSqlAsync(this IConnectionSource source, string sql) where T : DbConnection { - using var conn = source.CreateConnection(); + await using var conn = source.CreateConnection(); await conn.OpenAsync().ConfigureAwait(false); try diff --git a/src/Weasel.Core/Migrations/Database.cs b/src/Weasel.Core/Migrations/Database.cs index 8e32bb41..f0a13615 100644 --- a/src/Weasel.Core/Migrations/Database.cs +++ b/src/Weasel.Core/Migrations/Database.cs @@ -104,7 +104,7 @@ public Task CreateMigrationAsync(Type featureType) public async Task AssertConnectivity() { - using var conn = CreateConnection(); + await using var conn = CreateConnection(); await conn.OpenAsync().ConfigureAwait(false); await conn.CloseAsync().ConfigureAwait(false); } diff --git a/src/Weasel.Core/Migrations/TimedLock.cs b/src/Weasel.Core/Migrations/TimedLock.cs index b06521f8..03b88f3a 100644 --- a/src/Weasel.Core/Migrations/TimedLock.cs +++ b/src/Weasel.Core/Migrations/TimedLock.cs @@ -22,7 +22,7 @@ public async Task Lock(TimeSpan timeout) throw new TimeoutException(); } - public struct LockReleaser : IDisposable + public readonly struct LockReleaser : IDisposable { private readonly SemaphoreSlim toRelease; diff --git a/src/Weasel.Core/Migrator.cs b/src/Weasel.Core/Migrator.cs index 0d53aa69..c0367a50 100644 --- a/src/Weasel.Core/Migrator.cs +++ b/src/Weasel.Core/Migrator.cs @@ -96,7 +96,7 @@ public void ReadTemplates() /// public async Task WriteTemplatedFile(string filename, Action writeStep) { - using var stream = new FileStream(filename, FileMode.Create); + await using var stream = new FileStream(filename, FileMode.Create); var writer = new StreamWriter(stream) { AutoFlush = true }; WriteScript(writer, writeStep); diff --git a/src/Weasel.Core/SchemaMigration.cs b/src/Weasel.Core/SchemaMigration.cs index 96a21d2e..f0f20c72 100644 --- a/src/Weasel.Core/SchemaMigration.cs +++ b/src/Weasel.Core/SchemaMigration.cs @@ -39,7 +39,7 @@ public static async Task Determine(DbConnection conn, params IS schemaObject.ConfigureQueryCommand(builder); } - using var reader = await builder.ExecuteReaderAsync(conn).ConfigureAwait(false); + await using var reader = await builder.ExecuteReaderAsync(conn).ConfigureAwait(false); deltas.Add(await schemaObjects[0].CreateDelta(reader).ConfigureAwait(false)); diff --git a/src/Weasel.Postgresql.Tests/CommandBuilderIntegrationTests.cs b/src/Weasel.Postgresql.Tests/CommandBuilderIntegrationTests.cs index e0c4a3b4..3d051184 100644 --- a/src/Weasel.Postgresql.Tests/CommandBuilderIntegrationTests.cs +++ b/src/Weasel.Postgresql.Tests/CommandBuilderIntegrationTests.cs @@ -37,7 +37,7 @@ public async Task use_parameters_to_query_by_anonymous_type() await builder.ExecuteNonQueryAsync(theConnection); - using var reader = await theConnection.CreateCommand("select id, tag, age from integration.thing") + await using var reader = await theConnection.CreateCommand("select id, tag, age from integration.thing") .ExecuteReaderAsync(); await reader.ReadAsync(); @@ -70,7 +70,7 @@ public async Task use_parameters_to_query_by_anonymous_type_by_generic_command_b await builder.ExecuteNonQueryAsync(theConnection); - using var reader = await theConnection.CreateCommand("select id, tag, age from integration.thing") + await using var reader = await theConnection.CreateCommand("select id, tag, age from integration.thing") .ExecuteReaderAsync(); await reader.ReadAsync(); @@ -162,7 +162,7 @@ public async Task add_named_parameter() await builder.ExecuteNonQueryAsync(theConnection); - using var reader = await theConnection.CreateCommand("select id, tag, age, rate, sequence, is_done from integration.thing") + await using var reader = await theConnection.CreateCommand("select id, tag, age, rate, sequence, is_done from integration.thing") .ExecuteReaderAsync(); await reader.ReadAsync(); diff --git a/src/Weasel.Postgresql.Tests/advisory_lock_usage.cs b/src/Weasel.Postgresql.Tests/advisory_lock_usage.cs index 49a3fd30..0451f650 100644 --- a/src/Weasel.Postgresql.Tests/advisory_lock_usage.cs +++ b/src/Weasel.Postgresql.Tests/advisory_lock_usage.cs @@ -13,9 +13,9 @@ public class advisory_lock_usage [Fact] public async Task explicitly_release_global_session_locks() { - using (var conn1 = new NpgsqlConnection(ConnectionSource.ConnectionString)) - using (var conn2 = new NpgsqlConnection(ConnectionSource.ConnectionString)) - using (var conn3 = new NpgsqlConnection(ConnectionSource.ConnectionString)) + await using (var conn1 = new NpgsqlConnection(ConnectionSource.ConnectionString)) + await using (var conn2 = new NpgsqlConnection(ConnectionSource.ConnectionString)) + await using (var conn3 = new NpgsqlConnection(ConnectionSource.ConnectionString)) { await conn1.OpenAsync(); await conn2.OpenAsync(); @@ -46,9 +46,9 @@ public async Task explicitly_release_global_session_locks() [Fact] public async Task explicitly_release_global_tx_session_locks() { - using (var conn1 = new NpgsqlConnection(ConnectionSource.ConnectionString)) - using (var conn2 = new NpgsqlConnection(ConnectionSource.ConnectionString)) - using (var conn3 = new NpgsqlConnection(ConnectionSource.ConnectionString)) + await using (var conn1 = new NpgsqlConnection(ConnectionSource.ConnectionString)) + await using (var conn2 = new NpgsqlConnection(ConnectionSource.ConnectionString)) + await using (var conn3 = new NpgsqlConnection(ConnectionSource.ConnectionString)) { await conn1.OpenAsync(); await conn2.OpenAsync(); @@ -84,9 +84,9 @@ public async Task explicitly_release_global_tx_session_locks() [Fact] // - too slow public async Task global_session_locks() { - using (var conn1 = new NpgsqlConnection(ConnectionSource.ConnectionString)) - using (var conn2 = new NpgsqlConnection(ConnectionSource.ConnectionString)) - using (var conn3 = new NpgsqlConnection(ConnectionSource.ConnectionString)) + await using (var conn1 = new NpgsqlConnection(ConnectionSource.ConnectionString)) + await using (var conn2 = new NpgsqlConnection(ConnectionSource.ConnectionString)) + await using (var conn3 = new NpgsqlConnection(ConnectionSource.ConnectionString)) { await conn1.OpenAsync(); await conn2.OpenAsync(); @@ -117,9 +117,9 @@ public async Task global_session_locks() [Fact] // -- too slow public async Task tx_session_locks() { - using (var conn1 = new NpgsqlConnection(ConnectionSource.ConnectionString)) - using (var conn2 = new NpgsqlConnection(ConnectionSource.ConnectionString)) - using (var conn3 = new NpgsqlConnection(ConnectionSource.ConnectionString)) + await using (var conn1 = new NpgsqlConnection(ConnectionSource.ConnectionString)) + await using (var conn2 = new NpgsqlConnection(ConnectionSource.ConnectionString)) + await using (var conn3 = new NpgsqlConnection(ConnectionSource.ConnectionString)) { await conn1.OpenAsync(); await conn2.OpenAsync(); diff --git a/src/Weasel.Postgresql.Tests/command_extensions_integrated_test.cs b/src/Weasel.Postgresql.Tests/command_extensions_integrated_test.cs index 46538b69..71ba9935 100644 --- a/src/Weasel.Postgresql.Tests/command_extensions_integrated_test.cs +++ b/src/Weasel.Postgresql.Tests/command_extensions_integrated_test.cs @@ -34,9 +34,9 @@ public async Task execute_once() .With("id", 3).With("tag", "Toodles").With("age", 5); await command.ExecuteOnce(); - - - using var reader = await theConnection.CreateCommand("select id, tag, age from general.thing") + + + await using var reader = await theConnection.CreateCommand("select id, tag, age from general.thing") .ExecuteReaderAsync(); await reader.ReadAsync(); diff --git a/src/Weasel.Postgresql/Functions/Function.cs b/src/Weasel.Postgresql/Functions/Function.cs index 3bdc8dc4..3d55a63e 100644 --- a/src/Weasel.Postgresql/Functions/Function.cs +++ b/src/Weasel.Postgresql/Functions/Function.cs @@ -105,7 +105,7 @@ FROM pg_proc p ConfigureQueryCommand(builder); - using var reader = await builder.ExecuteReaderAsync(conn).ConfigureAwait(false); + await using var reader = await builder.ExecuteReaderAsync(conn).ConfigureAwait(false); return await readExisting(reader).ConfigureAwait(false); } diff --git a/src/Weasel.Postgresql/Migrations/SingleServerDatabaseCollection.cs b/src/Weasel.Postgresql/Migrations/SingleServerDatabaseCollection.cs index d8ea5925..30c59737 100644 --- a/src/Weasel.Postgresql/Migrations/SingleServerDatabaseCollection.cs +++ b/src/Weasel.Postgresql/Migrations/SingleServerDatabaseCollection.cs @@ -19,12 +19,12 @@ public abstract class SingleServerDatabaseCollection where T : PostgresqlData private ImHashMap _databases = ImHashMap.Empty; private readonly TimedLock _lock = new TimedLock(); - public SingleServerDatabaseCollection(string masterConnectionString) + protected SingleServerDatabaseCollection(string masterConnectionString) { _masterConnectionString = masterConnectionString; } - public DatabaseSpecification Specification { get; } = new DatabaseSpecification(); + private DatabaseSpecification Specification { get; } = new(); public IReadOnlyList AllDatabases() { @@ -38,7 +38,7 @@ public IReadOnlyList AllDatabases() protected abstract T buildDatabase(string databaseName, string connectionString); - public async ValueTask FindOrCreateDatabase(string databaseName) + public virtual async ValueTask FindOrCreateDatabase(string databaseName) { if (_databases.TryFind(databaseName, out var database)) { diff --git a/src/Weasel.Postgresql/SchemaObjectsExtensions.cs b/src/Weasel.Postgresql/SchemaObjectsExtensions.cs index 467092bc..4567cfea 100644 --- a/src/Weasel.Postgresql/SchemaObjectsExtensions.cs +++ b/src/Weasel.Postgresql/SchemaObjectsExtensions.cs @@ -115,7 +115,7 @@ public static async Task FunctionExists(this NpgsqlConnection conn, DbObje var sql = "SELECT specific_schema, routine_name FROM information_schema.routines WHERE type_udt_name != 'trigger' and routine_name like :name and specific_schema = :schema;"; - using var reader = await conn.CreateCommand(sql) + await using var reader = await conn.CreateCommand(sql) .With("name", functionIdentifier.Name) .With("schema", functionIdentifier.Schema) diff --git a/src/Weasel.Postgresql/Sequence.cs b/src/Weasel.Postgresql/Sequence.cs index d33b684b..9087fd67 100644 --- a/src/Weasel.Postgresql/Sequence.cs +++ b/src/Weasel.Postgresql/Sequence.cs @@ -76,7 +76,7 @@ public async Task FindDelta(NpgsqlConnection conn) ConfigureQueryCommand(builder); - using var reader = await builder.ExecuteReaderAsync(conn).ConfigureAwait(false); + await using var reader = await builder.ExecuteReaderAsync(conn).ConfigureAwait(false); return await CreateDelta(reader).ConfigureAwait(false); } diff --git a/src/Weasel.Postgresql/Tables/Table.FetchExisting.cs b/src/Weasel.Postgresql/Tables/Table.FetchExisting.cs index 1fc0a1f2..a13a101a 100644 --- a/src/Weasel.Postgresql/Tables/Table.FetchExisting.cs +++ b/src/Weasel.Postgresql/Tables/Table.FetchExisting.cs @@ -123,7 +123,7 @@ information_schema.columns col ConfigureQueryCommand(builder); - using var reader = await builder.ExecuteReaderAsync(conn).ConfigureAwait(false); + await using var reader = await builder.ExecuteReaderAsync(conn).ConfigureAwait(false); return await readExisting(reader).ConfigureAwait(false); } diff --git a/src/Weasel.Postgresql/Tables/Table.cs b/src/Weasel.Postgresql/Tables/Table.cs index d6f9beee..c5188c51 100644 --- a/src/Weasel.Postgresql/Tables/Table.cs +++ b/src/Weasel.Postgresql/Tables/Table.cs @@ -262,7 +262,7 @@ public async Task ExistsInDatabase(NpgsqlConnection conn) .With("table", Identifier.Name) .With("schema", Identifier.Schema); - using var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(false); + await using var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(false); var any = await reader.ReadAsync().ConfigureAwait(false); return any; } diff --git a/src/Weasel.SqlServer.Tests/CommandBuilderIntegrationTests.cs b/src/Weasel.SqlServer.Tests/CommandBuilderIntegrationTests.cs index ffff06f1..f73bbd5e 100644 --- a/src/Weasel.SqlServer.Tests/CommandBuilderIntegrationTests.cs +++ b/src/Weasel.SqlServer.Tests/CommandBuilderIntegrationTests.cs @@ -36,7 +36,7 @@ public async Task use_parameters_to_query_by_anonymous_type() await builder.ExecuteNonQueryAsync(theConnection); - using var reader = await theConnection.CreateCommand("select id, tag, age from integration.thing") + await using var reader = await theConnection.CreateCommand("select id, tag, age from integration.thing") .ExecuteReaderAsync(); await reader.ReadAsync(); @@ -69,7 +69,7 @@ public async Task use_parameters_to_query_by_anonymous_type_generic_db_builder() await builder.ExecuteNonQueryAsync(theConnection); - using var reader = await theConnection.CreateCommand("select id, tag, age from integration.thing") + await using var reader = await theConnection.CreateCommand("select id, tag, age from integration.thing") .ExecuteReaderAsync(); await reader.ReadAsync(); @@ -210,7 +210,7 @@ public async Task add_named_parameter() await builder.ExecuteNonQueryAsync(theConnection); - using var reader = await theConnection.CreateCommand("select id, tag, age, rate, sequence, is_done from integration.thing") + await using var reader = await theConnection.CreateCommand("select id, tag, age, rate, sequence, is_done from integration.thing") .ExecuteReaderAsync(); await reader.ReadAsync(); diff --git a/src/Weasel.SqlServer.Tests/advisory_lock_usage.cs b/src/Weasel.SqlServer.Tests/advisory_lock_usage.cs index 63cbce3d..a8e9b331 100644 --- a/src/Weasel.SqlServer.Tests/advisory_lock_usage.cs +++ b/src/Weasel.SqlServer.Tests/advisory_lock_usage.cs @@ -12,9 +12,9 @@ public class advisory_lock_usage [Fact] public async Task explicitly_release_global_session_locks() { - using (var conn1 = new SqlConnection(ConnectionSource.ConnectionString)) - using (var conn2 = new SqlConnection(ConnectionSource.ConnectionString)) - using (var conn3 = new SqlConnection(ConnectionSource.ConnectionString)) + await using (var conn1 = new SqlConnection(ConnectionSource.ConnectionString)) + await using (var conn2 = new SqlConnection(ConnectionSource.ConnectionString)) + await using (var conn3 = new SqlConnection(ConnectionSource.ConnectionString)) { await conn1.OpenAsync(); await conn2.OpenAsync(); @@ -45,9 +45,9 @@ public async Task explicitly_release_global_session_locks() [Fact] public async Task explicitly_release_global_tx_session_locks() { - using (var conn1 = new SqlConnection(ConnectionSource.ConnectionString)) - using (var conn2 = new SqlConnection(ConnectionSource.ConnectionString)) - using (var conn3 = new SqlConnection(ConnectionSource.ConnectionString)) + await using (var conn1 = new SqlConnection(ConnectionSource.ConnectionString)) + await using (var conn2 = new SqlConnection(ConnectionSource.ConnectionString)) + await using (var conn3 = new SqlConnection(ConnectionSource.ConnectionString)) { await conn1.OpenAsync(); await conn2.OpenAsync(); @@ -83,9 +83,9 @@ public async Task explicitly_release_global_tx_session_locks() [Fact] // - too slow public async Task global_session_locks() { - using (var conn1 = new SqlConnection(ConnectionSource.ConnectionString)) - using (var conn2 = new SqlConnection(ConnectionSource.ConnectionString)) - using (var conn3 = new SqlConnection(ConnectionSource.ConnectionString)) + await using (var conn1 = new SqlConnection(ConnectionSource.ConnectionString)) + await using (var conn2 = new SqlConnection(ConnectionSource.ConnectionString)) + await using (var conn3 = new SqlConnection(ConnectionSource.ConnectionString)) { await conn1.OpenAsync(); await conn2.OpenAsync(); @@ -116,9 +116,9 @@ public async Task global_session_locks() [Fact] // -- too slow public async Task tx_session_locks() { - using (var conn1 = new SqlConnection(ConnectionSource.ConnectionString)) - using (var conn2 = new SqlConnection(ConnectionSource.ConnectionString)) - using (var conn3 = new SqlConnection(ConnectionSource.ConnectionString)) + await using (var conn1 = new SqlConnection(ConnectionSource.ConnectionString)) + await using (var conn2 = new SqlConnection(ConnectionSource.ConnectionString)) + await using (var conn3 = new SqlConnection(ConnectionSource.ConnectionString)) { await conn1.OpenAsync(); await conn2.OpenAsync(); diff --git a/src/Weasel.SqlServer/Procedures/StoredProcedure.cs b/src/Weasel.SqlServer/Procedures/StoredProcedure.cs index 39eb1f12..a11bfc48 100644 --- a/src/Weasel.SqlServer/Procedures/StoredProcedure.cs +++ b/src/Weasel.SqlServer/Procedures/StoredProcedure.cs @@ -127,7 +127,7 @@ public string CanonicizeSql() ConfigureQueryCommand(builder); - using var reader = await builder.ExecuteReaderAsync(conn).ConfigureAwait(false); + await using var reader = await builder.ExecuteReaderAsync(conn).ConfigureAwait(false); return await readExisting(reader).ConfigureAwait(false); } diff --git a/src/Weasel.SqlServer/SchemaObjectsExtensions.cs b/src/Weasel.SqlServer/SchemaObjectsExtensions.cs index aa62c88c..bb141ac2 100644 --- a/src/Weasel.SqlServer/SchemaObjectsExtensions.cs +++ b/src/Weasel.SqlServer/SchemaObjectsExtensions.cs @@ -163,7 +163,7 @@ public static async Task FunctionExists(this SqlConnection conn, DbObjectN var sql = "SELECT specific_schema, routine_name FROM information_schema.routines WHERE type_udt_name != 'trigger' and routine_name like :name and specific_schema = :schema;"; - using var reader = await conn.CreateCommand(sql) + await using var reader = await conn.CreateCommand(sql) .With("name", functionIdentifier.Name) .With("schema", functionIdentifier.Schema) .ExecuteReaderAsync().ConfigureAwait(false); diff --git a/src/Weasel.SqlServer/Sequence.cs b/src/Weasel.SqlServer/Sequence.cs index 5362f387..6026bd7e 100644 --- a/src/Weasel.SqlServer/Sequence.cs +++ b/src/Weasel.SqlServer/Sequence.cs @@ -79,7 +79,7 @@ public async Task FindDelta(SqlConnection conn) ConfigureQueryCommand(builder); - using var reader = await builder.ExecuteReaderAsync(conn).ConfigureAwait(false); + await using var reader = await builder.ExecuteReaderAsync(conn).ConfigureAwait(false); return await CreateDelta(reader).ConfigureAwait(false); } diff --git a/src/Weasel.SqlServer/Tables/Table.FetchExisting.cs b/src/Weasel.SqlServer/Tables/Table.FetchExisting.cs index 30d73f74..4c9b0e22 100644 --- a/src/Weasel.SqlServer/Tables/Table.FetchExisting.cs +++ b/src/Weasel.SqlServer/Tables/Table.FetchExisting.cs @@ -103,7 +103,7 @@ order by ConfigureQueryCommand(builder); - using var reader = await builder.ExecuteReaderAsync(conn).ConfigureAwait(false); + await using var reader = await builder.ExecuteReaderAsync(conn).ConfigureAwait(false); return await readExisting(reader).ConfigureAwait(false); } diff --git a/src/Weasel.SqlServer/Tables/TableType.cs b/src/Weasel.SqlServer/Tables/TableType.cs index ea23f69b..46a4b239 100644 --- a/src/Weasel.SqlServer/Tables/TableType.cs +++ b/src/Weasel.SqlServer/Tables/TableType.cs @@ -151,6 +151,10 @@ public override bool Equals(object? obj) return Equals((TableTypeColumn) obj); } + public override int GetHashCode() + { + return HashCode.Combine(Name, DatabaseType, AllowNulls); + } } public async Task FetchExisting(SqlConnection conn) @@ -159,7 +163,7 @@ public override bool Equals(object? obj) ConfigureQueryCommand(builder); - using var reader = await builder.ExecuteReaderAsync(conn).ConfigureAwait(false); + await using var reader = await builder.ExecuteReaderAsync(conn).ConfigureAwait(false); return await readExisting(reader).ConfigureAwait(false); }