Skip to content

Commit 89c4a71

Browse files
Update functions-bindings-azure-sql-output.md
1 parent 6180ebb commit 89c4a71

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

articles/azure-functions/functions-bindings-azure-sql-output.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,46 @@ CREATE TABLE dbo.RequestLog (
966966

967967
# [v2](#tab/python-v2)
968968

969-
No equivalent sample for v2 at this time.
969+
```python
970+
from datetime import datetime
971+
import json
972+
import logging
973+
import azure.functions as func
974+
975+
@app.function_name(name="PostToDo")
976+
@app.route(route="posttodo")
977+
@app.sql_output(arg_name="todoItems",
978+
command_text="[dbo].[ToDo]",
979+
connection_string_setting="SqlConnectionString")
980+
@app.sql_output(arg_name="requestLog",
981+
command_text="[dbo].[RequestLog]",
982+
connection_string_setting="SqlConnectionString")
983+
def add_todo(req: func.HttpRequest, todoItems: func.Out[func.SqlRow], requestLog: func.Out[func.SqlRow]) -> func.HttpResponse:
984+
logging.info('Python HTTP trigger and SQL output binding function processed a request.')
985+
try:
986+
req_body = req.get_json()
987+
rows = func.SqlRowList(map(lambda r: func.SqlRow.from_dict(r), req_body))
988+
except ValueError:
989+
pass
990+
991+
requestLog.set(func.SqlRow({
992+
"RequestTimeStamp": datetime.now().isoformat(),
993+
"ItemCount": 1
994+
}))
995+
996+
if req_body:
997+
todoItems.set(rows)
998+
return func.HttpResponse(
999+
"OK",
1000+
status_code=201,
1001+
mimetype="application/json"
1002+
)
1003+
else:
1004+
return func.HttpResponse(
1005+
"Error accessing request body",
1006+
status_code=400
1007+
)
1008+
```
9701009

9711010
# [v1](#tab/python-v1)
9721011

0 commit comments

Comments
 (0)