@@ -966,7 +966,46 @@ CREATE TABLE dbo.RequestLog (
966
966
967
967
# [ v2] ( #tab/python-v2 )
968
968
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
+ ```
970
1009
971
1010
# [ v1] ( #tab/python-v1 )
972
1011
0 commit comments