|
5 | 5 | - [Table of Contents](#table-of-contents) |
6 | 6 | - [Setup Function Project](#setup-function-project) |
7 | 7 | - [Input Binding](#input-binding) |
8 | | - - [SQLInput Attribute](#sqlinput-attribute) |
| 8 | + - [SQLInput Annotation](#sqlinput-annotation) |
9 | 9 | - [Setup for Input Bindings](#setup-for-input-bindings) |
10 | 10 | - [Samples for Input Bindings](#samples-for-input-bindings) |
11 | 11 | - [Query String](#query-string) |
12 | 12 | - [Empty Parameter Value](#empty-parameter-value) |
13 | 13 | - [Null Parameter Value](#null-parameter-value) |
14 | 14 | - [Stored Procedure](#stored-procedure) |
15 | 15 | - [Output Binding](#output-binding) |
16 | | - - [SQLOutput Attribute](#sqloutput-attribute) |
| 16 | + - [SQLOutput Annotation](#sqloutput-annotation) |
17 | 17 | - [Setup for Output Bindings](#setup-for-output-bindings) |
18 | 18 | - [Samples for Output Bindings](#samples-for-output-bindings) |
19 | 19 | - [Array](#array) |
20 | 20 | - [Single Row](#single-row) |
21 | 21 | - [Trigger Binding](#trigger-binding) |
| 22 | + - [SqlTrigger Annotation](#sqltriggerbinding-annotation) |
| 23 | + - [Setup for Trigger Binding](#setup-for-trigger-bindings) |
22 | 24 | - [Known Issues](#known-issues) |
23 | 25 |
|
24 | 26 | ## Setup Function Project |
@@ -60,7 +62,7 @@ These instructions will guide you through creating your Function Project and add |
60 | 62 |
|
61 | 63 | See [Input Binding Overview](./BindingsOverview.md#input-binding) for general information about the Azure SQL Input binding. |
62 | 64 |
|
63 | | -### SQLInput Attribute |
| 65 | +### SQLInput Annotation |
64 | 66 |
|
65 | 67 | In the Java functions runtime library, use the @SQLInput annotation (com.microsoft.azure.functions.sql.annotation.SQLInput) on parameters whose value comes from the query specified by commandText. This annotation supports the following elements: |
66 | 68 |
|
@@ -101,7 +103,7 @@ Note: This tutorial requires that a SQL database is setup as shown in [Create a |
101 | 103 | } |
102 | 104 | ``` |
103 | 105 |
|
104 | | - *In the above, `select * from Employees` is the SQL script run by the input binding. The CommandType on the line below specifies whether the first line is a query or a stored procedure. On the next line, the ConnectionStringSetting specifies that the app setting that contains the SQL connection string used to connect to the database is "SqlConnectionString." For more information on this, see the [SQLInput Attribute](#sqlinput-attribute) section* |
| 106 | + *In the above, `select * from Employees` is the SQL script run by the input binding. The CommandType on the line below specifies whether the first line is a query or a stored procedure. On the next line, the ConnectionStringSetting specifies that the app setting that contains the SQL connection string used to connect to the database is "SqlConnectionString." For more information on this, see the [SQLInput Annotation](#sqlinput-annotation) section* |
105 | 107 |
|
106 | 108 | - Add `import com.microsoft.azure.functions.sql.annotation.SQLInput;` |
107 | 109 | - Create a new file and call it `Employee.java` |
@@ -321,7 +323,7 @@ If the `{name}` specified in the `getproducts-namenull/{name}` URL is "null", th |
321 | 323 |
|
322 | 324 | See [Output Binding Overview](./BindingsOverview.md#output-binding) for general information about the Azure SQL Output binding. |
323 | 325 |
|
324 | | -### SQLOutput Attribute |
| 326 | +### SQLOutput Annotation |
325 | 327 |
|
326 | 328 | In the Java functions runtime library, use the @SQLOutput annotation (com.microsoft.azure.functions.sql.annotation.SQLOutput) on parameters whose values you want to upsert into the target table. This annotation supports the following elements: |
327 | 329 |
|
@@ -365,7 +367,7 @@ Note: This tutorial requires that a SQL database is setup as shown in [Create a |
365 | 367 | } |
366 | 368 | ``` |
367 | 369 |
|
368 | | - *In the above, "dbo.Employees" is the name of the table our output binding is upserting into. The line below is similar to the input binding and specifies where our SqlConnectionString is. For more information on this, see the [SQLOutput Attribute](#sqloutput-attribute) section* |
| 370 | + *In the above, "dbo.Employees" is the name of the table our output binding is upserting into. The line below is similar to the input binding and specifies where our SqlConnectionString is. For more information on this, see the [SQLOutput Annotation](#sqloutput-annotation) section* |
369 | 371 |
|
370 | 372 | - Hit 'F5' to run your code. Click the link to upsert the output array values in your SQL table. Your upserted values should launch in the browser. |
371 | 373 | - Congratulations! You have successfully created your first SQL output binding! |
@@ -426,7 +428,91 @@ Note: This tutorial requires that a SQL database is setup as shown in [Create a |
426 | 428 |
|
427 | 429 | ## Trigger Binding |
428 | 430 |
|
429 | | -> Trigger binding support is only available for in-proc C# functions at present. |
| 431 | +See [Trigger Binding Overview](./BindingsOverview.md#trigger-binding) for general information about the Azure SQL Trigger binding. |
| 432 | +
|
| 433 | +### SqlTrigger Annotation |
| 434 | +
|
| 435 | +In the Java functions runtime library, use the @SQLTrigger annotation (com.microsoft.azure.functions.sql.annotation.SQLTrigger) on parameters whose values would come from Azure SQL. This annotation supports the following elements: |
| 436 | +
|
| 437 | +| Element |Description| |
| 438 | +|---------|---------| |
| 439 | +| **name** | Required. The name of the parameter that the trigger binds to. | |
| 440 | +| **tableName** | Required. The name of the table monitored by the trigger. | |
| 441 | +| **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). | |
| 442 | +
|
| 443 | +When you're developing locally, add your application settings in the local.settings.json file in the Values collection. |
| 444 | +### Setup for Trigger Bindings |
| 445 | +
|
| 446 | +Note: This tutorial requires that a SQL database is setup as shown in [Create a SQL Server](./GeneralSetup.md#create-a-sql-server), and that you have the 'Employee.java' file from the [Setup for Input Bindings](#setup-for-input-bindings) section. |
| 447 | +
|
| 448 | +- Create a new file `SqlChangeOperation.java` with the following content: |
| 449 | + ```java |
| 450 | + package com.function; |
| 451 | +
|
| 452 | + import com.google.gson.annotations.SerializedName; |
| 453 | +
|
| 454 | + public enum SqlChangeOperation { |
| 455 | + @SerializedName("0") |
| 456 | + Insert, |
| 457 | + @SerializedName("1") |
| 458 | + Update, |
| 459 | + @SerializedName("2") |
| 460 | + Delete; |
| 461 | + } |
| 462 | + ``` |
| 463 | +
|
| 464 | +- Create a new file `SqlChangeEmployee.java` with the following content: |
| 465 | + ```java |
| 466 | + package com.function; |
| 467 | +
|
| 468 | + public class SqlChangeEmployee { |
| 469 | + public Employee employee; |
| 470 | + public SqlChangeOperation operation; |
| 471 | +
|
| 472 | + public SqlChangeEmployee() { |
| 473 | + } |
| 474 | +
|
| 475 | + public SqlChangeEmployee(Employee employee, SqlChangeOperation operation) { |
| 476 | + this.employee = employee; |
| 477 | + this.operation = operation; |
| 478 | + } |
| 479 | + } |
| 480 | + ``` |
| 481 | + |
| 482 | +- Create a new file `EmployeeTrigger.java` with the following content: |
| 483 | +
|
| 484 | + ```java |
| 485 | + package com.function; |
| 486 | +
|
| 487 | + import com.microsoft.azure.functions.ExecutionContext; |
| 488 | + import com.microsoft.azure.functions.annotation.FunctionName; |
| 489 | + import com.microsoft.azure.functions.sql.annotation.SQLTrigger; |
| 490 | + import com.function.SqlChangeEmployee; |
| 491 | + import com.google.gson.Gson; |
| 492 | +
|
| 493 | + import java.util.logging.Level; |
| 494 | +
|
| 495 | + public class EmployeeTrigger { |
| 496 | + @FunctionName("EmployeeTrigger") |
| 497 | + public void run( |
| 498 | + @SQLTrigger( |
| 499 | + name = "changes", |
| 500 | + tableName = "[dbo].[Employees]", |
| 501 | + connectionStringSetting = "SqlConnectionString") |
| 502 | + SqlChangeEmployee[] changes, |
| 503 | + ExecutionContext context) { |
| 504 | +
|
| 505 | + context.getLogger().log(Level.INFO, "SQL Changes: " + new Gson().toJson(changes)); |
| 506 | + } |
| 507 | + } |
| 508 | + ``` |
| 509 | +
|
| 510 | +- *Skip these steps if you have not completed the output binding tutorial.* |
| 511 | + - Open your output binding file and modify some of the values. For example, change the value of Team column from 'Functions' to 'Azure SQL'. |
| 512 | + - Hit 'F5' to run your code. Click the link of the HTTP trigger from the output binding tutorial. |
| 513 | +- Update, insert, or delete rows in your SQL table while the function app is running and observe the function logs. |
| 514 | +- You should see the new log messages in the Visual Studio Code terminal containing the values of row-columns after the update operation. |
| 515 | +- Congratulations! You have successfully created your first SQL trigger binding! |
430 | 516 |
|
431 | 517 | ## Known Issues |
432 | 518 |
|
|
0 commit comments