Skip to content

Commit

Permalink
Merge pull request #17 from B3zaleel/extract-schema
Browse files Browse the repository at this point in the history
Add support for extracting schema from a connection string
  • Loading branch information
fsergiojr authored Sep 19, 2024
2 parents 3537047 + a8d1563 commit f7a5828
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions SnowflakeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@ public static class SnowflakeExtensions
/// A builder for a database upgrader designed for Snowflake databases.
/// </returns>
public static UpgradeEngineBuilder SnowflakeDatabase(this SupportedDatabases supported, string connectionString)
=> SnowflakeDatabase(supported, connectionString, null);
{
var connectionStringFields = connectionString.Split(';');
var schema = connectionStringFields
.FirstOrDefault(x => x.StartsWith("schema", StringComparison.InvariantCultureIgnoreCase))
?.Split('=').Last();
var database = connectionStringFields
.First(x => x.StartsWith("database", StringComparison.InvariantCultureIgnoreCase) || x.StartsWith("db", StringComparison.InvariantCultureIgnoreCase))
.Split('=').Last();
return SnowflakeDatabase(new SnowflakeConnectionManager(connectionString), schema, database);
}

/// <summary>
/// Creates an upgrade engine builder for Snowflake databases.
Expand All @@ -35,7 +44,9 @@ public static UpgradeEngineBuilder SnowflakeDatabase(this SupportedDatabases sup
/// </returns>
public static UpgradeEngineBuilder SnowflakeDatabase(this SupportedDatabases supported, string connectionString, string schema)
{
var database = connectionString.Split(';').First(x => x.StartsWith("database", StringComparison.InvariantCultureIgnoreCase)).Split('=').Last();
var database = connectionString.Split(';')
.First(x => x.StartsWith("database", StringComparison.InvariantCultureIgnoreCase) || x.StartsWith("db", StringComparison.InvariantCultureIgnoreCase))
.Split('=').Last();
return SnowflakeDatabase(new SnowflakeConnectionManager(connectionString), schema, database);
}

Expand Down

0 comments on commit f7a5828

Please sign in to comment.