Skip to content

Commit 8f6209c

Browse files
committed
Refactor SQL Database functions to use combined capability in Invoke-FabricRestMethod. Used splatting for params.
1 parent 03d567f commit 8f6209c

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

source/Public/SQL Database/Get-FabricSQLDatabase.ps1

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,26 @@ function Get-FabricSQLDatabase
101101
{
102102
$uri = "$uri/$SQLDatabaseId"
103103
}
104-
$response = Invoke-FabricRestMethod -Uri $uri
105104

106-
# Step: Validate the response code
107-
Test-FabricApiResponse -Response $response -ObjectIdOrName $SQLDatabaseId -TypeName "SQL Database"
105+
# Make the API request and validate the response code
106+
$apiParams = @{
107+
Uri = $uri
108+
Method = 'GET'
109+
TypeName = 'SQL Database'
110+
ObjectIdOrName = $SQLDatabaseName
111+
HandleResponse = $true
112+
ExtractValue = 'True'
113+
}
114+
115+
$response = Invoke-FabricRestMethod @apiParams
108116

109-
$response = $response.value
110117
if ($SQLDatabaseName)
111118
{
112119
# Filter the SQLDatabase by name
113120
$response = $response | Where-Object { $_.displayName -eq $SQLDatabaseName }
114121
}
115-
if ($response)
116-
{
117-
$return += $response
118-
}
122+
$response
119123
}
120124

121-
End
122-
{
123-
$return
124-
}
125+
End {}
125126
}

source/Public/SQL Database/New-FabricSQLDatabase.ps1

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,17 @@ function New-FabricSQLDatabase
7373
# Step 4: Make the API request
7474
if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Create SQL Database"))
7575
{
76-
$response = Invoke-FabricRestMethod -Uri $apiEndpointUrl -Method Post -Body $bodyJson
76+
$apiParams = @{
77+
Uri = $apiEndpointUrl
78+
Method = 'POST'
79+
Body = $bodyJson
80+
TypeName = 'SQL Database'
81+
NoWait = $NoWait
82+
HandleResponse = $true
83+
}
84+
$response = Invoke-FabricRestMethod @apiParams
85+
$response
7786
}
78-
# Step 5: Handle and log the response
79-
Test-FabricApiResponse -Response $response -ObjectIdOrName $Name -TypeName 'SQL Database' -NoWait:$NoWait
8087
}
8188
catch
8289
{

source/Public/SQL Database/Remove-FabricSQLDatabase.ps1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,17 @@ function Remove-FabricSQLDatabase
4848
if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Delete SQL Database"))
4949
{
5050
# Step 3: Make the API request
51-
$response = Invoke-FabricRestMethod -Uri $apiEndpointUrl -Method Delete
51+
$apiParams = @{
52+
Uri = $apiEndpointUrl
53+
Method = 'DELETE'
54+
TypeName = 'SQL Database'
55+
ObjectIdOrName = $SQLDatabaseId
56+
HandleResponse = $true
57+
}
58+
$response = Invoke-FabricRestMethod @apiParams
59+
$response
5260
}
5361

54-
# Step 4: Validate the response code
55-
Test-FabricApiResponse -Response $response -ObjectIdOrName $SQLDatabaseId -TypeName "SQL Database"
5662
}
5763
catch
5864
{

0 commit comments

Comments
 (0)