Skip to content

Commit bbb9080

Browse files
authored
Update SetupGuide_Python doc (#677)
* update python setup doc * update comment * fix toc
1 parent e2c1d03 commit bbb9080

File tree

6 files changed

+61
-17
lines changed

6 files changed

+61
-17
lines changed

docs/SetupGuide_Python.md

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@
1313
- [Empty Parameter Value](#empty-parameter-value)
1414
- [Null Parameter Value](#null-parameter-value)
1515
- [Stored Procedure](#stored-procedure)
16-
- [IAsyncEnumerable](#iasyncenumerable)
1716
- [Output Binding](#output-binding)
1817
- [function.json Properties for Output Bindings](#functionjson-properties-for-output-bindings)
1918
- [Setup for Output Bindings](#setup-for-output-bindings)
2019
- [Samples for Output Bindings](#samples-for-output-bindings)
21-
- [ICollector\<T\>/IAsyncCollector\<T\>](#icollectortiasynccollectort)
2220
- [Array](#array)
2321
- [Single Row](#single-row)
2422
- [Trigger Binding](#trigger-binding)
@@ -115,23 +113,19 @@ Note: This tutorial requires that a SQL database is setup as shown in [Create a
115113
116114
#### Query String
117115
118-
_TODO_
116+
See the [GetProducts](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-python/GetProducts) sample
119117
120118
#### Empty Parameter Value
121119
122-
_TODO_
120+
See the [GetProductsNameEmpty](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-python/GetProductsNameEmpty) sample
123121
124122
#### Null Parameter Value
125123
126-
_TODO_
124+
See the [GetProductsNameNull](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-python/GetProductsNameNull) sample
127125
128126
#### Stored Procedure
129127
130-
_TODO_
131-
132-
#### IAsyncEnumerable
133-
134-
_TODO_
128+
See the [GetProductsStoredProcedure](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-python/GetProductsStoredProcedure) sample
135129
136130
## Output Binding
137131
@@ -153,7 +147,7 @@ The following table explains the binding configuration properties that you set i
153147
154148
Note: This tutorial requires that a SQL database is setup as shown in [Create a SQL Server](./GeneralSetup.md#create-a-sql-server).
155149
156-
- Open your app in VS Code
150+
- Open your project in VS Code
157151
- Press 'F1' and search for 'Azure Functions: Create Function'
158152
- Choose HttpTrigger -> (Provide a function name) -> anonymous
159153
- 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.
@@ -198,17 +192,13 @@ Note: This tutorial requires that a SQL database is setup as shown in [Create a
198192
199193
### Samples for Output Bindings
200194
201-
#### ICollector&lt;T&gt;/IAsyncCollector&lt;T&gt;
202-
203-
_TODO_
204-
205195
#### Array
206196
207-
_TODO_
197+
See the [AddProductsArray](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-python/AddProductsArray) sample
208198
209199
#### Single Row
210200
211-
_TODO_
201+
See the [AddProduct](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-python/AddProduct) sample
212202
213203
## Trigger Binding
214204

samples/samples-python/GetProducts/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
import json
55
import azure.functions as func
66

7+
# The input binding executes the `SELECT * FROM Products WHERE Cost = @Cost` query.
8+
# The Parameters argument passes the `{cost}` specified in the URL that triggers the function,
9+
# `getproducts/{cost}`, as the value of the `@Cost` parameter in the query.
10+
# CommandType is set to `Text`, since the constructor argument of the binding is a raw query.
711
def main(req: func.HttpRequest, products: func.SqlRowList) -> func.HttpResponse:
812
rows = list(map(lambda r: json.loads(r.to_json()), products))
913

samples/samples-python/GetProductsNameEmpty/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import json
55
import azure.functions as func
66

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import json
5+
import azure.functions as func
6+
7+
# If the `{name}` specified in the `getproducts-namenull/{name}` URL is "null", the
8+
# query returns all rows for which the Name column is `NULL`. Otherwise, it returns
9+
# all rows for which the value of the Name column matches the string passed in `{name}`
10+
def main(req: func.HttpRequest, products: func.SqlRowList) -> func.HttpResponse:
11+
rows = list(map(lambda r: json.loads(r.to_json()), products))
12+
13+
return func.HttpResponse(
14+
json.dumps(rows),
15+
status_code=200,
16+
mimetype="application/json"
17+
)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"bindings": [
3+
{
4+
"authLevel": "function",
5+
"name": "req",
6+
"type": "httpTrigger",
7+
"direction": "in",
8+
"methods": [
9+
"get"
10+
],
11+
"route":"getproducts-namenull/{name}"
12+
},
13+
{
14+
"name": "$return",
15+
"type": "http",
16+
"direction": "out"
17+
},
18+
{
19+
"name": "products",
20+
"type": "sql",
21+
"direction": "in",
22+
"commandText": "if @Name is null select * from Products where Name is null else select * from Products where @Name = name",
23+
"commandType": "Text",
24+
"parameters": "@Name={name}",
25+
"connectionStringSetting": "SqlConnectionString"
26+
}
27+
],
28+
"disabled": false
29+
}

samples/samples-python/GetProductsStoredProcedure/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import json
55
import azure.functions as func
66

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

0 commit comments

Comments
 (0)