Skip to content

Commit 552a0ed

Browse files
authored
Update SetupGuide_Python.md (#849)
1 parent 89bb479 commit 552a0ed

File tree

1 file changed

+58
-5
lines changed

1 file changed

+58
-5
lines changed

docs/SetupGuide_Python.md

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
- [Samples for Output Bindings](#samples-for-output-bindings)
2020
- [Array](#array)
2121
- [Single Row](#single-row)
22-
- [Python V2 Model](#python-v2-model)
2322
- [Trigger Binding](#trigger-binding)
23+
- [function.json Properties for Trigger Bindings](#functionjson-properties-for-trigger-bindings)
24+
- [Setup for Trigger Bindings](#setup-for-trigger-bindings)
25+
- [Python V2 Model](#python-v2-model)
2426

2527
## Setup Function Project
2628

@@ -201,10 +203,61 @@ See the [AddProductsArray](https://github.com/Azure/azure-functions-sql-extensio
201203
202204
See the [AddProduct](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-python/AddProduct) sample
203205
204-
## Python V2 Model
206+
## Trigger Binding
205207
206-
See the Python V2 Model samples [here](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-python-v2/). More information about the Python V2 Model can be found [here](https://learn.microsoft.com/azure/azure-functions/functions-reference-python?tabs=asgi%2Capplication-level&pivots=python-mode-decorators).
208+
See [Trigger Binding Overview](./BindingsOverview.md#trigger-binding) for general information about the Azure SQL Trigger binding.
207209
208-
## Trigger Binding
210+
### function.json Properties for Trigger Bindings
211+
212+
The following table explains the binding configuration properties that you set in the *function.json* file.
213+
214+
|function.json property | Description|
215+
|---------|----------------------|
216+
| **name** | Required. The name of the parameter that the trigger binds to. |
217+
| **type** | Required. Must be set to `sqlTrigger`.|
218+
| **direction** | Required. Must be set to `in`. |
219+
| **commandText** | Required. The name of the table being monitored by the trigger. |
220+
| **connectionStringSetting** | Required. The name of an app setting that contains the connection string for the database containing the table monitored for changes. This isn't the actual connection string and must instead resolve to an environment variable. Optional keywords in the connection string value are [available to refine SQL bindings connectivity](https://aka.ms/sqlbindings#sql-connection-string). |
221+
222+
### Setup for Trigger Bindings
223+
224+
Note: This tutorial requires that a SQL database is setup as shown in [Create a SQL Server](./GeneralSetup.md#create-a-sql-server).
225+
226+
- Create a new folder `EmployeeTrigger`
227+
- Inside `EmployeeTrigger` create a new file `function.json`
209228
210-
> Trigger binding support is only available for in-proc C# functions at present.
229+
```json
230+
{
231+
"bindings": [
232+
{
233+
"name": "changes",
234+
"type": "sqlTrigger",
235+
"direction": "in",
236+
"tableName": "dbo.Employees",
237+
"connectionStringSetting": "SqlConnectionString"
238+
}
239+
],
240+
"disabled": false
241+
}
242+
```
243+
244+
- Inside `EmployeeTrigger` create a new file `__init__.py`
245+
246+
```python
247+
import json
248+
import logging
249+
250+
def main(changes):
251+
logging.info("SQL Changes: %s", json.loads(changes))
252+
```
253+
254+
- *Skip these steps if you have not completed the output binding tutorial.*
255+
- Open your output binding file and modify some of the values. For example, change the value of Team column from 'Functions' to 'Azure SQL'.
256+
- Hit 'F5' to run your code. Click the link of the HTTP trigger from the output binding tutorial.
257+
- Update, insert, or delete rows in your SQL table while the function app is running and observe the function logs.
258+
- You should see the new log messages in the Visual Studio Code terminal containing the values of row-columns after the update operation.
259+
- Congratulations! You have successfully created your first SQL trigger binding!
260+
261+
## Python V2 Model
262+
263+
See the Python V2 Model samples [here](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-python-v2/). More information about the Python V2 Model can be found [here](https://learn.microsoft.com/azure/azure-functions/functions-reference-python?tabs=asgi%2Capplication-level&pivots=python-mode-decorators).

0 commit comments

Comments
 (0)