Skip to content

Commit c7f0638

Browse files
Feature/small updates (#122)
* Fix function name in CHANGELOG and update examples Corrected the function name from Get-SqlDatabase to Get-FabricSqlDatabase in the CHANGELOG. Updated examples in the Get-FabricSQLDatabase function to improve clarity and consistency. Thank you! * Update Get-FabricSQLDatabase to improve parameter handling Refactor the function to return warnings instead of throwing errors when both SQLDatabaseName and SQLDatabaseId are provided. Update the synopsis and description for clarity. Ensure the return value is correctly handled in the End block. Thank you! * Update Get-FabricSQLDatabase documentation and URI Clarify the function's synopsis and description to enhance understanding. Corrected the spelling of "examples" and updated the URI to follow the correct casing for SQL databases. Thank you! * Update example in Get-FabricSQLDatabase documentation Changed the example command to use quotes around the workspace name for consistency and clarity. This helps users understand the correct syntax when using the function. Thank you! * Update example in Get-FabricSQLDatabase documentation Changed the workspace name in the example to 'MsLearn-dev' because thats important Thank you! * Refactor Get-FabricSQLDatabase to improve parameter handling This change restructures the function to ensure that the SQLDatabaseName and SQLDatabaseID parameters cannot be used together, enhancing the clarity of parameter usage. The process block has been properly defined to maintain code organization and readability. Thank you! * Refactor Get-FabricSQLDatabase for improved readability Reorganize function structure and enhance code clarity by adjusting the formatting of the function definition and control structures. This change aims to make the code more maintainable and easier to understand. Thank you! * Initialize return array in Get-FabricSQLDatabase This change introduces an initialization of the return array at the beginning of the Get-FabricSQLDatabase function. This will ensure that the function has a defined return structure, improving its reliability and maintainability. Thank you! * Add check for response before updating return array This change ensures that the return array is only updated if there is a valid response from the SQLDatabase filtering. This prevents potential errors when no matching databases are found. Thank you!
1 parent 40a4004 commit c7f0638

File tree

2 files changed

+52
-27
lines changed

2 files changed

+52
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
- Added credits for authors to all functions and Unit tests to verify the existence of such tags #89
1010

1111
### Changed
12-
- Get-SqlDatabase accepts Workspace as a pipeline, handles errors correctly and can filter by name (#117).
12+
- Get-FabricSqlDatabase accepts Workspace as a pipeline, handles errors correctly and can filter by name (#117).
1313

1414
### Fixed
1515
### Deprecated
Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
function Get-FabricSQLDatabase {
1+
function Get-FabricSQLDatabase
2+
{
23

34
<#
45
.SYNOPSIS
5-
Retrieves Fabric SQLDatabases
6+
Retrieves Fabric SQL Database details.
67
78
.DESCRIPTION
8-
Retrieves Fabric SQLDatabases. Without the SQLDatabaseName or SQLDatabaseID parameter,
9-
all SQLDatabases are returned. If you want to retrieve a specific SQLDatabase, you can
9+
Retrieves Fabric SQL Database details. Without the SQLDatabaseName or SQLDatabaseID parameter,
10+
all SQL Databases are returned. If you want to retrieve a specific SQLDatabase, you can
1011
use the SQLDatabaseName or SQLDatabaseID parameter. These parameters cannot be used together.
1112
1213
.PARAMETER WorkspaceId
13-
Id of the Fabric Workspace for which the SQLDatabases should be retrieved. The value for WorkspaceId is a GUID.
14+
Id of the Fabric Workspace for which the SQL Databases should be retrieved. The value for WorkspaceId is a GUID.
1415
An example of a GUID is '12345678-1234-1234-1234-123456789012'.
1516
1617
.PARAMETER Workspace
@@ -25,33 +26,37 @@ function Get-FabricSQLDatabase {
2526
The value for SQLDatabaseID is a GUID. An example of a GUID is '12345678-1234-1234-1234-123456789012'.
2627
2728
.EXAMPLE
28-
Get-FabricSQLDatabase `
29-
-WorkspaceId '12345678-1234-1234-1234-123456789012' `
30-
-SQLDatabaseName 'MySQLDatabase'
29+
$FabricSQLDatabaseConfig = @{
30+
WorkspaceId = '12345678-1234-1234-1234-123456789012'
31+
SQLDatabaseName = 'MySQLDatabase'
32+
}
33+
Get-FabricSQLDatabase @FabricSQLDatabaseConfig
3134
32-
This example will retrieve the SQLDatabase with the name 'MySQLDatabase'.
35+
Returns the details of the Fabric SQL Database with the name 'MySQLDatabase' in the workspace that is specified by the WorkspaceId.
3336
3437
.EXAMPLE
3538
Get-FabricSQLDatabase -WorkspaceId '12345678-1234-1234-1234-123456789012'
3639
37-
This example will retrieve all SQLDatabases in the workspace that is specified
38-
by the WorkspaceId.
40+
Returns the details of the Fabric SQL Databases in the workspace that is specified by the WorkspaceId.
3941
4042
.EXAMPLE
41-
Get-FabricSQLDatabase `
42-
-WorkspaceId '12345678-1234-1234-1234-123456789012' `
43-
-SQLDatabaseId '12345678-1234-1234-1234-123456789012'
43+
$FabricSQLDatabaseConfig = @{
44+
WorkspaceId = '12345678-1234-1234-1234-123456789012'
45+
-SQLDatabaseId = '12345678-1234-1234-1234-123456789012'
46+
}
47+
Get-FabricSQLDatabase @FabricSQLDatabaseConfig
4448
45-
This example will retrieve the SQLDatabase with the ID '12345678-1234-1234-1234-123456789012'.
49+
Returns the details of the Fabric SQL Database with the ID '12345678-1234-1234-1234-123456789012' from the workspace with the ID '12345678-1234-1234-1234-123456789012'.
4650
4751
.EXAMPLE
4852
Get-FabricWorkspace -WorkspaceName 'MsLearn-dev' | Get-FabricSQLDatabase
4953
50-
This example will retrieve all SQLDatabases from the workspace with the name 'MsLearn-dev' (using the pipeline).
54+
Returns the details of the Fabric SQL Databases in the MsLearn-dev workspace.
5155
5256
.NOTES
5357
Revision History:
5458
- 2025-03-06 - KNO: Init version of the function
59+
- 2025-06-14 - Update the examples to remove backticks
5560
5661
Author: Kamil Nowinski
5762
@@ -73,29 +78,40 @@ function Get-FabricSQLDatabase {
7378
[string]$SQLDatabaseId
7479
)
7580

76-
begin {
81+
begin
82+
{
83+
$return = @()
7784
Confirm-TokenState
7885

79-
if ($PSBoundParameters.ContainsKey("SQLDatabaseName") -and $PSBoundParameters.ContainsKey("SQLDatabaseId")) {
80-
throw "Parameters SQLDatabaseName and SQLDatabaseId cannot be used together"
86+
if ($PSBoundParameters.ContainsKey("SQLDatabaseName") -and $PSBoundParameters.ContainsKey("SQLDatabaseId"))
87+
{
88+
Write-Warning "The parameters SQLDatabaseName and SQLDatabaseId cannot be used together"
89+
return
8190
}
91+
92+
8293
}
8394

84-
process {
85-
if ($PSCmdlet.ParameterSetName -eq 'WorkspaceObject') {
95+
process
96+
{
97+
98+
if ($PSCmdlet.ParameterSetName -eq 'WorkspaceObject')
99+
{
86100
$WorkspaceId = $Workspace.id
87101
}
88102

89103
# Create SQLDatabase API
90-
$uri = "$($FabricSession.BaseApiUrl)/workspaces/$WorkspaceId/SqlDatabases"
91-
if ($SQLDatabaseId) {
104+
$uri = "$($FabricSession.BaseApiUrl)/workspaces/$WorkspaceId/sqlDatabases"
105+
if ($SQLDatabaseId)
106+
{
92107
$uri = "$uri/$SQLDatabaseId"
93108
}
94109
$response = Invoke-FabricRestMethod -Uri $uri
95110
##$databases.Where({$_.displayName -eq $body.displayName}).id
96111

97112
# Step: Validate the response code
98-
if ($statusCode -ne 200) {
113+
if ($statusCode -ne 200)
114+
{
99115
Write-Message -Message "Unexpected response code: $statusCode from the API." -Level Error
100116
Write-Message -Message "Error: $($response.message)" -Level Error
101117
Write-Message -Message "Error Details: $($response.moreDetails)" -Level Error
@@ -104,10 +120,19 @@ function Get-FabricSQLDatabase {
104120
}
105121

106122
$response = $response.value
107-
if ($SQLDatabaseName) {
123+
if ($SQLDatabaseName)
124+
{
108125
# Filter the SQLDatabase by name
109126
$response = $response | Where-Object { $_.displayName -eq $SQLDatabaseName }
110127
}
111-
return $response
128+
if ($response)
129+
{
130+
$return += $response
131+
}
132+
}
133+
134+
End
135+
{
136+
$return
112137
}
113138
}

0 commit comments

Comments
 (0)