Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions docs/SetupGuide_PowerShell.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
- [function.json Properties for Output Bindings](#functionjson-properties-for-output-bindings)
- [Setup for Output Bindings](#setup-for-output-bindings)
- [Samples for Output Bindings](#samples-for-output-bindings)
- [ICollector\<T\>/IAsyncCollector\<T\>](#icollectortiasynccollectort)
- [Array](#array)
- [Single Row](#single-row)
- [Trigger Binding](#trigger-binding)
Expand Down Expand Up @@ -113,19 +112,19 @@ Note: This tutorial requires that a SQL database is setup as shown in [Create a

#### Query String

_TODO_
See the [GetProducts](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-powershell/GetProducts) sample

#### Empty Parameter Value

_TODO_
See the [GetProductsNameEmpty](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-powershell/GetProductsNameEmpty) sample

#### Null Parameter Value

_TODO_
See the [GetProductsNameNull](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-powershell/GetProductsNameNull) sample

#### Stored Procedure

_TODO_
See the [GetProductsStoredProcedure](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-powershell/GetProductsStoredProcedure) sample

## Output Binding

Expand All @@ -147,7 +146,7 @@ The following table explains the binding configuration properties that you set i

Note: This tutorial requires that a SQL database is setup as shown in [Create a SQL Server](./GeneralSetup.md#create-a-sql-server).

- Open your app in VS Code
- Open your project in VS Code
- Press 'F1' and search for 'Azure Functions: Create Function'
- Choose HttpTrigger -> (Provide a function name) -> anonymous
- In the file that opens (`run.ps1`), replace the code within the file the below code. Note that the casing of the Object field names and the table column names must match.
Expand Down Expand Up @@ -205,17 +204,14 @@ Note: This tutorial requires that a SQL database is setup as shown in [Create a

### Samples for Output Bindings

#### ICollector&lt;T&gt;/IAsyncCollector&lt;T&gt;

_TODO_

#### Array

_TODO_
See the [AddProductsArray](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-powershell/AddProductsArray) sample

#### Single Row

_TODO_
See the [AddProduct](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-powershell/AddProduct) sample


## Trigger Binding

Expand Down
4 changes: 4 additions & 0 deletions samples/samples-powershell/GetProducts/run.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.

# The input binding executes the `select * from Products where Cost = @Cost` query, returning the result as json object in the body.
# The *parameters* argument passes the `{cost}` specified in the URL that triggers the function,
# `getproducts/{cost}`, as the value of the `@Cost` parameter in the query.
# *commandType* is set to `Text`, since the constructor argument of the binding is a raw query.
using namespace System.Net

# Trigger and input binding data are passed in via the param block.
Expand Down
1 change: 1 addition & 0 deletions samples/samples-powershell/GetProductsNameEmpty/run.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.

# The parameter value of the `@Name` parameter is an empty string in the parameters arguments.
using namespace System.Net

# Trigger and input binding data are passed in via the param block.
Expand Down
29 changes: 29 additions & 0 deletions samples/samples-powershell/GetProductsNameNull/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"bindings": [
{
"authLevel": "function",
"name": "Request",
"type": "httpTrigger",
"direction": "in",
"methods": [
"get"
],
"route": "getproducts-namenull/{name}"
},
{
"name": "response",
"type": "http",
"direction": "out"
},
{
"name": "products",
"type": "sql",
"direction": "in",
"commandText": "if @Name is null select * from Products where Name is null else select * from Products where @Name = name",
"commandType": "Text",
"parameters": "@Name={name}",
"connectionStringSetting": "SqlConnectionString"
}
],
"disabled": false
}
20 changes: 20 additions & 0 deletions samples/samples-powershell/GetProductsNameNull/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.

# If the `{name}` specified in the `getproducts-namenull/{name}` URL is "null",
# the query returns all rows for which the Name column is `NULL`. Otherwise, it returns
# all rows for which the value of the Name column matches the string passed in `{name}`
using namespace System.Net

# Trigger and input binding data are passed in via the param block.
param($Request, $TriggerMetadata, $products)

# Write to the Azure Functions log stream.
Write-Host "PowerShell function with SQL Input Binding processed a request."

# Assign the value to return as the HTTP response.
# The -Name value matches the name property in the function.json for the binding
Push-OutputBinding -Name response -Value ([HttpResponseContext]@{
StatusCode = [System.Net.HttpStatusCode]::OK
Body = $products
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.

# `SelectsProductCost` is the name of a procedure stored in the user's database.
# In this case, *CommandType* is `StoredProcedure`.
# The parameter value of the `@Cost` parameter in the procedure is once again the `{cost}` specified in the `getproducts-storedprocedure/{cost}` URL.
using namespace System.Net

# Trigger and input binding data are passed in via the param block.
Expand Down