From d72a2cd57b8146f228762e18b2e9f798299f9863 Mon Sep 17 00:00:00 2001 From: Vasu Bhog Date: Sat, 11 Feb 2023 19:53:40 -0800 Subject: [PATCH 1/2] update PS docs todos --- docs/SetupGuide_PowerShell.md | 20 +++++-------- .../samples-powershell/GetProducts/run.ps1 | 4 +++ .../GetProductsNameEmpty/run.ps1 | 1 + .../GetProductsNameNull/function.json | 29 +++++++++++++++++++ .../GetProductsNameNull/run.ps1 | 20 +++++++++++++ .../GetProductsStoredProcedure/run.ps1 | 3 ++ 6 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 samples/samples-powershell/GetProductsNameNull/function.json create mode 100644 samples/samples-powershell/GetProductsNameNull/run.ps1 diff --git a/docs/SetupGuide_PowerShell.md b/docs/SetupGuide_PowerShell.md index 9bcda39f1..9fa6a4b07 100644 --- a/docs/SetupGuide_PowerShell.md +++ b/docs/SetupGuide_PowerShell.md @@ -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\/IAsyncCollector\](#icollectortiasynccollectort) - [Array](#array) - [Single Row](#single-row) - [Trigger Binding](#trigger-binding) @@ -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 @@ -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. @@ -205,17 +204,14 @@ Note: This tutorial requires that a SQL database is setup as shown in [Create a ### Samples for Output Bindings -#### ICollector<T>/IAsyncCollector<T> - -_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/AddProducte) sample + ## Trigger Binding diff --git a/samples/samples-powershell/GetProducts/run.ps1 b/samples/samples-powershell/GetProducts/run.ps1 index a4da2c312..39cb9ae61 100644 --- a/samples/samples-powershell/GetProducts/run.ps1 +++ b/samples/samples-powershell/GetProducts/run.ps1 @@ -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. diff --git a/samples/samples-powershell/GetProductsNameEmpty/run.ps1 b/samples/samples-powershell/GetProductsNameEmpty/run.ps1 index a4da2c312..1df7bc28a 100644 --- a/samples/samples-powershell/GetProductsNameEmpty/run.ps1 +++ b/samples/samples-powershell/GetProductsNameEmpty/run.ps1 @@ -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. diff --git a/samples/samples-powershell/GetProductsNameNull/function.json b/samples/samples-powershell/GetProductsNameNull/function.json new file mode 100644 index 000000000..0dc2748f0 --- /dev/null +++ b/samples/samples-powershell/GetProductsNameNull/function.json @@ -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 +} \ No newline at end of file diff --git a/samples/samples-powershell/GetProductsNameNull/run.ps1 b/samples/samples-powershell/GetProductsNameNull/run.ps1 new file mode 100644 index 000000000..6f394973c --- /dev/null +++ b/samples/samples-powershell/GetProductsNameNull/run.ps1 @@ -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 +}) \ No newline at end of file diff --git a/samples/samples-powershell/GetProductsStoredProcedure/run.ps1 b/samples/samples-powershell/GetProductsStoredProcedure/run.ps1 index a4da2c312..91c3507a5 100644 --- a/samples/samples-powershell/GetProductsStoredProcedure/run.ps1 +++ b/samples/samples-powershell/GetProductsStoredProcedure/run.ps1 @@ -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. From 93887d0cd74915e4ecf44044a5fed7ee54b34fd6 Mon Sep 17 00:00:00 2001 From: Vasu Bhog Date: Tue, 14 Feb 2023 12:33:16 -0800 Subject: [PATCH 2/2] Update SetupGuide_PowerShell.md extra e --- docs/SetupGuide_PowerShell.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/SetupGuide_PowerShell.md b/docs/SetupGuide_PowerShell.md index 9fa6a4b07..d21b77e27 100644 --- a/docs/SetupGuide_PowerShell.md +++ b/docs/SetupGuide_PowerShell.md @@ -210,7 +210,7 @@ See the [AddProductsArray](https://github.com/Azure/azure-functions-sql-extensio #### Single Row -See the [AddProduct](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-powershell/AddProducte) sample +See the [AddProduct](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-powershell/AddProduct) sample ## Trigger Binding