internal/functions/Get-ConnectionManager.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function Get-ConnectionManager {
    # Returns a connection manager object
    Param (
        [Parameter(ParameterSetName = 'ConnString')]
        [string]$ConnectionString,
        [Parameter(ParameterSetName = 'Config', Mandatory)]
        [DBOpsConfig]$Configuration,
        [DBOps.ConnectionType]$Type
    )
    if ($Configuration) {
        $ConnectionString = Get-ConnectionString -Configuration $Configuration -Type $Type
    }
    if ($Type -eq [DBOps.ConnectionType]::SqlServer) {
        return [DbUp.SqlServer.SqlConnectionManager]::new($ConnectionString)
    }
    elseif ($Type -eq [DBOps.ConnectionType]::Oracle) {
        return [DbUp.Oracle.OracleConnectionManager]::new($ConnectionString)
    }
    elseif ($Type -eq [DBOps.ConnectionType]::MySQL) {
        return [DbUp.MySql.MySqlConnectionManager]::new($ConnectionString)
    }
    elseif ($Type -eq [DBOps.ConnectionType]::PostgreSQL) {
        return [DbUp.Postgresql.PostgresqlConnectionManager]::new($ConnectionString)
    }
    else {
        Stop-PSFFunction -Message "Unknown type $Type" -EnableException $true
        return
    }
}