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
24 changes: 7 additions & 17 deletions docs/SetupGuide_Python.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
- [Empty Parameter Value](#empty-parameter-value)
- [Null Parameter Value](#null-parameter-value)
- [Stored Procedure](#stored-procedure)
- [IAsyncEnumerable](#iasyncenumerable)
- [Output Binding](#output-binding)
- [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 @@ -115,23 +113,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-python/GetProducts) sample

#### Empty Parameter Value

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

#### Null Parameter Value

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

#### Stored Procedure

_TODO_

#### IAsyncEnumerable

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

## Output Binding

Expand All @@ -153,7 +147,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 (`__init__.py`), replace the `def main(req: func.HttpRequest) -> func.HttpResponse:` block with the below code. Note that the casing of the Object field names and the table column names must match.
Expand Down Expand Up @@ -198,17 +192,13 @@ 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-python/AddProductsArray) sample

#### Single Row

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

## Trigger Binding

Expand Down
4 changes: 4 additions & 0 deletions samples/samples-python/GetProducts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import json
import azure.functions as func

# The input binding executes the `SELECT * FROM Products WHERE Cost = @Cost` query.
# 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.
def main(req: func.HttpRequest, products: func.SqlRowList) -> func.HttpResponse:
rows = list(map(lambda r: json.loads(r.to_json()), products))

Expand Down
1 change: 1 addition & 0 deletions samples/samples-python/GetProductsNameEmpty/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import azure.functions as func

# The parameter value of the `@Name` parameter is an empty string.
def main(req: func.HttpRequest, products: func.SqlRowList) -> func.HttpResponse:
rows = list(map(lambda r: json.loads(r.to_json()), products))

Expand Down
17 changes: 17 additions & 0 deletions samples/samples-python/GetProductsNameNull/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import json
import azure.functions as func

# 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}`
def main(req: func.HttpRequest, products: func.SqlRowList) -> func.HttpResponse:
rows = list(map(lambda r: json.loads(r.to_json()), products))

return func.HttpResponse(
json.dumps(rows),
status_code=200,
mimetype="application/json"
)
29 changes: 29 additions & 0 deletions samples/samples-python/GetProductsNameNull/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"bindings": [
{
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"methods": [
"get"
],
"route":"getproducts-namenull/{name}"
},
{
"name": "$return",
"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
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import json
import azure.functions as func

# `SelectProductsCost` is the name of a procedure stored in the user's database.
# The CommandType is `StoredProcedure`. The parameter value of the `@Cost` parameter in the
# procedure is the `{cost}` specified in the `getproducts-storedprocedure/{cost}` URL.
def main(req: func.HttpRequest, products: func.SqlRowList) -> func.HttpResponse:
rows = list(map(lambda r: json.loads(r.to_json()), products))

Expand Down