/// <summary> /// Determines if something exists. /// </summary> /// <param name="command">The command.</param> /// <param name="value">The value.</param> /// <param name="source">The source.</param> /// <returns>True if it does, false otherwise.</returns> private async Task <bool> ExistsAsync(string command, string value, IConnection source) { if (source is null || value is null || command is null) { return(false); } return((await OneOffQueries.CreateBatch(source.Factory, source.ConnectionString) .AddQuery(CommandType.Text, command, value) .ExecuteAsync().ConfigureAwait(false))[0] .Count > 0); }
/// <summary> /// Sets up the specified source. /// </summary> /// <param name="schemaChanges">The schema changes.</param> /// <param name="connection">The connection.</param> public async Task SetupAsync(string[] schemaChanges, IConnection connection) { if (connection is null || schemaChanges is null) { return; } var DatabaseConnectionString = connection.ConnectionString.RemoveInitialCatalog(); Batch.CreateBatch(connection); for (var x = 0; x < schemaChanges.Length; ++x) { if (schemaChanges[x].IndexOf("CREATE DATABASE", System.StringComparison.InvariantCultureIgnoreCase) >= 0) { await OneOffQueries.CreateBatch(connection.Factory, DatabaseConnectionString) .AddQuery(CommandType.Text, schemaChanges[x]) .ExecuteAsync().ConfigureAwait(false); } else if (schemaChanges[x].IndexOf("CREATE TRIGGER", System.StringComparison.InvariantCultureIgnoreCase) >= 0 || schemaChanges[x].IndexOf("CREATE FUNCTION", System.StringComparison.InvariantCultureIgnoreCase) >= 0 || schemaChanges[x].IndexOf("CREATE SCHEMA", System.StringComparison.InvariantCultureIgnoreCase) >= 0) { if (Batch.Count > 0) { await Batch.ExecuteAsync().ConfigureAwait(false); Batch.CreateBatch(); } Batch.AddQuery(CommandType.Text, schemaChanges[x]); if (x < schemaChanges.Length - 1) { await Batch.ExecuteAsync().ConfigureAwait(false); Batch.CreateBatch(); } } else { Batch.AddQuery(CommandType.Text, schemaChanges[x]); } } await Batch.ExecuteAsync().ConfigureAwait(false); }