Skip to content

Commit 33bdaf2

Browse files
committed
Minor Changes for Azure Function for MySQL
1 parent 17ed90e commit 33bdaf2

File tree

4 files changed

+94
-70
lines changed

4 files changed

+94
-70
lines changed

articles/azure-functions/functions-bindings-azure-mysql-input.md

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ This section contains the following examples:
4141
The examples refer to a `Product` class and a corresponding database table:
4242

4343
```csharp
44-
namespace Microsoft.Azure.WebJobs.Extensions.MySql.Samples.Common
44+
namespace AzureMySqlSamples.Common
4545
{
4646
public class Product
4747
{
@@ -80,23 +80,25 @@ The following example shows a C# function that retrieves a single record. The fu
8080
using System.Collections.Generic;
8181
using Microsoft.AspNetCore.Http;
8282
using Microsoft.AspNetCore.Mvc;
83-
using Microsoft.Azure.WebJobs.Extensions.Http;
84-
using Microsoft.Azure.WebJobs.Extensions.MySql.Samples.Common;
83+
using Microsoft.Azure.Functions.Worker;
84+
using Microsoft.Azure.Functions.Worker.Extensions.MySql;
85+
using Microsoft.Azure.Functions.Worker.Http;
86+
using AzureMySqlSamples.Common;
8587

86-
namespace Microsoft.Azure.WebJobs.Extensions.MySql.Samples.InputBindingSamples
88+
namespace AzureMySqlSamples.InputBindingIsolatedSamples
8789
{
88-
public static class GetProducts
90+
public static class GetProductById
8991
{
90-
[FunctionName(nameof(GetProducts))]
91-
public static IActionResult Run(
92-
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "getproducts/{productid}")]
93-
HttpRequest req,
94-
[MySql("select * from Products where Cost = @Cost",
92+
[Function(nameof(GetProductById))]
93+
public static IEnumerable<Product> Run(
94+
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "getproducts/{productId}")]
95+
HttpRequestData req,
96+
[MySqlInput("select * from Products where ProductId = @productId",
9597
"MySqlConnectionString",
96-
parameters: "@productId={productid}")]
98+
parameters: "@ProductId={productId}")]
9799
IEnumerable<Product> products)
98100
{
99-
return new OkObjectResult(products);
101+
return products;
100102
}
101103
}
102104
}
@@ -111,23 +113,24 @@ The following example shows a [C# function](functions-dotnet-class-library.md) t
111113
using System.Collections.Generic;
112114
using Microsoft.AspNetCore.Http;
113115
using Microsoft.AspNetCore.Mvc;
114-
using Microsoft.Azure.WebJobs.Extensions.Http;
115-
using Microsoft.Azure.WebJobs.Extensions.MySql.Samples.Common;
116-
117-
namespace Microsoft.Azure.WebJobs.Extensions.MySql.Samples.InputBindingSamples
116+
using Microsoft.Azure.Functions.Worker;
117+
using Microsoft.Azure.Functions.Worker.Extensions.MySql;
118+
using Microsoft.Azure.Functions.Worker.Http;
119+
using AzureMySqlSamples.Common;
120+
121+
namespace AzureMySqlSamples.InputBindingIsolatedSamples
118122
{
119123
public static class GetProducts
120124
{
121-
[FunctionName(nameof(GetProducts))]
122-
public static IActionResult Run(
123-
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "getproducts/{cost}")]
124-
HttpRequest req,
125-
[MySql("select * from Products where Cost != @Cost",
126-
"MySqlConnectionString",
127-
parameters: "@Cost={cost}")]
125+
[Function(nameof(GetProducts))]
126+
public static IEnumerable<Product> Run(
127+
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "getproducts")]
128+
HttpRequestData req,
129+
[MySqlInput("select * from Products",
130+
"MySqlConnectionString")]
128131
IEnumerable<Product> products)
129132
{
130-
return new OkObjectResult(products);
133+
return products;
131134
}
132135
}
133136
}
@@ -150,7 +153,7 @@ END
150153
```
151154

152155
```cs
153-
namespace Microsoft.Azure.WebJobs.Extensions.MySql.Samples.InputBindingSamples
156+
namespace AzureMySqlSamples.InputBindingSamples
154157
{
155158
public static class GetProductsStoredProcedure
156159
{
@@ -183,7 +186,7 @@ This section contains the following examples:
183186
The examples refer to a `Product` class and a corresponding database table:
184187

185188
```csharp
186-
namespace Microsoft.Azure.WebJobs.Extensions.MySql.Samples.Common
189+
namespace AzureMySqlSamples.Common
187190
{
188191
public class Product
189192
{
@@ -221,20 +224,21 @@ The following example shows a [C# function](functions-dotnet-class-library.md) t
221224
using System.Collections.Generic;
222225
using Microsoft.AspNetCore.Http;
223226
using Microsoft.AspNetCore.Mvc;
227+
using Microsoft.Azure.WebJobs;
224228
using Microsoft.Azure.WebJobs.Extensions.Http;
225-
using Microsoft.Azure.WebJobs.Extensions.MySql.Samples.Common;
226-
227-
namespace Microsoft.Azure.WebJobs.Extensions.MySql.Samples.InputBindingSamples
229+
using Microsoft.Azure.WebJobs.Extensions.MySql;
230+
using AzureMySqlSamples.Common;
231+
232+
namespace AzureMySqlSamples.InputBindingSamples
228233
{
229234
public static class GetProductById
230235
{
231-
[FunctionName(nameof(GetProducts))]
236+
[FunctionName("GetProductById")]
232237
public static IActionResult Run(
233-
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "getproducts/{productid}")]
234-
HttpRequest req,
235-
[MySql("select * from Products where ProductId= @productId",
238+
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "getproducts/{productId}")] HttpRequest req,
239+
[MySql("select * from Products where ProductId = @productId",
236240
"MySqlConnectionString",
237-
parameters: "@productId={productid")]
241+
parameters: "@ProductId={productId}")]
238242
IEnumerable<Product> products)
239243
{
240244
return new OkObjectResult(products);
@@ -252,20 +256,20 @@ The following example shows a [C# function](functions-dotnet-class-library.md) t
252256
using System.Collections.Generic;
253257
using Microsoft.AspNetCore.Http;
254258
using Microsoft.AspNetCore.Mvc;
259+
using Microsoft.Azure.WebJobs;
255260
using Microsoft.Azure.WebJobs.Extensions.Http;
256-
using Microsoft.Azure.WebJobs.Extensions.MySql.Samples.Common;
257-
258-
namespace Microsoft.Azure.WebJobs.Extensions.MySql.Samples.InputBindingSamples
261+
using Microsoft.Azure.WebJobs.Extensions.MySql;
262+
using AzureMySqlSamples.Common;
263+
264+
namespace AzureMySqlSamples.InputBindingSamples
259265
{
260266
public static class GetProducts
261267
{
262-
[FunctionName(nameof(GetProducts))]
268+
[FunctionName("GetProducts")]
263269
public static IActionResult Run(
264-
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "getproducts/{cost}")]
265-
HttpRequest req,
266-
[MySql("select * from Products where Cost != @Cost",
267-
"MySqlConnectionString",
268-
parameters: "@Cost={cost}")]
270+
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "getproducts")] HttpRequest req,
271+
[MySql("select * from Products",
272+
"MySqlConnectionString")]
269273
IEnumerable<Product> products)
270274
{
271275
return new OkObjectResult(products);
@@ -291,7 +295,7 @@ END
291295
```
292296

293297
```cs
294-
namespace Microsoft.Azure.WebJobs.Extensions.MySql.Samples.InputBindingSamples
298+
namespace AzureMySqlSamples.InputBindingSamples
295299
{
296300
public static class GetProductsStoredProcedure
297301
{
@@ -1118,6 +1122,10 @@ CREATE TABLE Products (
11181122
);
11191123
```
11201124

1125+
> [!NOTE]
1126+
> Please note that Azure Functions version 1.22.0b4 must be used for Python .
1127+
>
1128+
11211129
<a id="http-trigger-get-multiple-items-python"></a>
11221130
### HTTP trigger, get multiple rows
11231131

@@ -1492,7 +1500,7 @@ The following table explains the binding configuration properties that you set i
14921500

14931501
## Usage
14941502

1495-
The attribute's constructor takes the MySQL command text, the command type, parameters, and the connection string setting name. The command can be a MYSQL query with the command type `System.Data.CommandType.Text` or stored procedure name with the command type `System.Data.CommandType.StoredProcedure`. The connection string setting name corresponds to the application setting (in `local.settings.json` for local development) that contains the [connection string](https://dev.mysql.com/doc/refman/8.4/en/connecting-using-uri-or-key-value-pairs.html#connecting-using-uri) to the Azure Database for MySQL.
1503+
The attribute's constructor takes the MySQL command text, the command type, parameters, and the connection string setting name. The command can be a MYSQL query with the command type `System.Data.CommandType.Text` or stored procedure name with the command type `System.Data.CommandType.StoredProcedure`. The connection string setting name corresponds to the application setting (in `local.settings.json` for local development) that contains the [connection string](https://dev.mysql.com/doc/connector-net/en/connector-net-connections-string.html) to the Azure Database for MySQL.
14961504

14971505

14981506
If an exception occurs when a MySQL input binding is executed then the function code won't execute. This may result in an error code being returned, such as an HTTP trigger returning a 500 error code.

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ This section contains the below example:
4040
The examples refer to a `Product` class and a corresponding database table:
4141

4242
```csharp
43-
namespace Microsoft.Azure.WebJobs.Extensions.MySql.Samples.Common
43+
namespace AzureMySqlSamples.Common
4444
{
4545
public class Product
4646
{
@@ -73,18 +73,20 @@ The following example shows a [C# function](functions-dotnet-class-library.md) t
7373

7474
```cs
7575
using Microsoft.AspNetCore.Mvc;
76-
using Microsoft.Azure.WebJobs.Extensions.Http;
77-
using Microsoft.Azure.WebJobs.Extensions.MySql.Samples.Common;
76+
using Microsoft.Azure.Functions.Worker;
77+
using Microsoft.Azure.Functions.Worker.Extensions.MySql;
78+
using Microsoft.Azure.Functions.Worker.Http;
79+
using AzureMySqlSamples.Common;
7880

79-
namespace Microsoft.Azure.WebJobs.Extensions.MySql.Samples.OutputBindingSamples
81+
namespace AzureMySqlSamples.OutputBindingSamples
8082
{
8183
public static class AddProduct
8284
{
8385
[FunctionName(nameof(AddProduct))]
8486
public static IActionResult Run(
8587
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "addproduct")]
8688
[FromBody] Product prod,
87-
[MySql("`Products`", "MySqlConnectionString")] out Product product)
89+
[MySql("Products", "MySqlConnectionString")] out Product product)
8890
{
8991
product = prod;
9092
return new CreatedResult($"/api/addproduct", product);
@@ -104,7 +106,7 @@ This section contains the below example:
104106
The examples refer to a `Product` class and a corresponding database table:
105107

106108
```csharp
107-
namespace Microsoft.Azure.WebJobs.Extensions.MySql.Samples.Common
109+
namespace AzureMySqlSamples.Common
108110
{
109111
public class Product
110112
{
@@ -137,18 +139,20 @@ The following example shows a [C# function](functions-dotnet-class-library.md) t
137139

138140
```csharp
139141
using Microsoft.AspNetCore.Mvc;
142+
using Microsoft.Azure.WebJobs;
140143
using Microsoft.Azure.WebJobs.Extensions.Http;
141-
using Microsoft.Azure.WebJobs.Extensions.MySql.Samples.Common;
144+
using Microsoft.Azure.WebJobs.Extensions.MySql;
145+
using AzureMySqlSamples.Common;
142146

143-
namespace Microsoft.Azure.WebJobs.Extensions.MySql.Samples.OutputBindingSamples
147+
namespace AzureMySqlSamples.OutputBindingSamples
144148
{
145149
public static class AddProduct
146150
{
147151
[FunctionName(nameof(AddProduct))]
148152
public static IActionResult Run(
149153
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "addproduct")]
150154
[FromBody] Product prod,
151-
[MySql("`Products`", "MySqlConnectionString")] out Product product)
155+
[MySql("Products", "MySqlConnectionString")] out Product product)
152156
{
153157
product = prod;
154158
return new CreatedResult($"/api/addproduct", product);
@@ -530,6 +534,11 @@ CREATE TABLE Products (
530534
);
531535
```
532536

537+
> [!NOTE]
538+
> Please note that Azure Functions version 1.22.0b4 must be used for Python .
539+
>
540+
541+
533542
<a id="http-trigger-write-records-to-table-python"></a>
534543
### HTTP trigger, write records to a table
535544

articles/azure-functions/functions-bindings-azure-mysql-trigger.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ zone_pivot_groups: programming-languages-set-functions-lang-workers
2121
> While input and output bindings will be supported on all plans, the MySQL Trigger binding will be available only on [dedicated and premium plans](functions-scale.md) during the public preview. Support for Consumption plans in the MySQL Trigger binding will be introduced at general availability.
2222
>
2323
24-
The Azure Database for MySQL trigger creates a new column to monitor when a row is created, or deleted. The Trigger bindings monitor the user table for changes (inserts, updates) and invokes the function with updated row data.
24+
The Azure Database for MySQL Trigger bindings monitor the user table for changes (inserts, updates) and invokes the function with updated row data.
2525

2626
Azure MySQL Trigger bindings use "az_func_updated_at" and column's data, to monitor the user table for changes. As such, it is necessary to alter the table structure to allow change tracking on the MySQL table before using the trigger support. The change tracking can be enabled on a table through following query. For example, enable on ‘Products’ table:
2727

@@ -53,7 +53,7 @@ Changes are processed in the order that they were made, with the oldest changes
5353
2. Changes are "batched" together for a row. If multiple changes are made to a row between each iteration of the loop, then only the latest change entry exists for that row will be considered.
5454

5555
> [!NOTE]
56-
>Trigger Binding with table name containing alphanuemric & _(underscore) are supported. Apart from that Trigger Binding doesn't support any other special characters like (-, * $).
56+
>Trigger Binding with table name containing alphanuemric & _(underscore) are supported. Apart from that Trigger Binding doesn't support any other special characters like (-, *, $).
5757
>
5858
5959

@@ -71,7 +71,7 @@ More samples for the Azure Database for MySQL trigger are available in the [GitH
7171
The example refers to a `Product` class and a corresponding database table:
7272

7373
```csharp
74-
namespace Microsoft.Azure.WebJobs.Extensions.MySql.Samples.Common
74+
namespace AzureMySqlSamples.Common
7575
{
7676
public class Product
7777
{
@@ -122,11 +122,12 @@ The following example shows a [C# function](functions-dotnet-class-library.md) t
122122

123123
```cs
124124
using System.Collections.Generic;
125-
using Microsoft.Azure.WebJobs.Extensions.MySql.Samples.Common;
125+
using Microsoft.Azure.Functions.Worker;
126+
using Microsoft.Azure.Functions.Worker.Extensions.MySql;
126127
using Microsoft.Extensions.Logging;
127128
using Newtonsoft.Json;
128129

129-
namespace Microsoft.Azure.WebJobs.Extensions.MySql.Samples.TriggerBindingSamples
130+
namespace AzureMySqlSamples.TriggerBindingSamples
130131
{
131132
public static class ProductsTrigger
132133
{
@@ -153,7 +154,7 @@ More samples for the Azure Database for MySQL trigger are available in the [GitH
153154
The example refers to a `Product` class and a corresponding database table:
154155

155156
```csharp
156-
namespace Microsoft.Azure.WebJobs.Extensions.MySql.Samples.Common
157+
namespace AzureMySqlSamples.Common
157158
{
158159
public class Product
159160
{
@@ -202,11 +203,12 @@ The following example shows a [C# function](functions-dotnet-class-library.md) t
202203

203204
```cs
204205
using System.Collections.Generic;
205-
using Microsoft.Azure.WebJobs.Extensions.MySql.Samples.Common;
206+
using Microsoft.Azure.WebJobs;
207+
using Microsoft.Azure.WebJobs.Extensions.MySql;
206208
using Microsoft.Extensions.Logging;
207209
using Newtonsoft.Json;
208210

209-
namespace Microsoft.Azure.WebJobs.Extensions.MySql.Samples.TriggerBindingSamples
211+
namespace AzureMySqlSamples.TriggerBindingSamples
210212
{
211213
public static class ProductsTrigger
212214
{
@@ -519,6 +521,11 @@ DEFAULT CURRENT_TIMESTAMP
519521
ON UPDATE CURRENT_TIMESTAMP;
520522
```
521523

524+
> [!NOTE]
525+
> Please note that Azure Functions version 1.22.0b4 must be used for Python .
526+
>
527+
528+
522529
The MySQL trigger binds to a variable `Product`, a list of objects each with two properties:
523530
- **item:** the item that was changed. The structure of the item will follow the table schema.
524531
- **operation:** The possible values is `Update` for both insert and update.
@@ -597,7 +604,7 @@ def main(changes):
597604
| Attribute property |Description|
598605
|---------|---------|
599606
| **TableName** | Required. The name of the table monitored by the trigger. |
600-
| **ConnectionStringSetting** | Required. The name of an app setting that contains the connection string for the database containing the table monitored for changes. The connection string setting name corresponds to the application setting (in `local.settings.json` for local development) that contains the [connection string](https://dev.mysql.com/doc/refman/8.4/en/connecting-using-uri-or-key-value-pairs.html) to the Azure Database for MySQL.|
607+
| **ConnectionStringSetting** | Required. The name of an app setting that contains the connection string for the database containing the table monitored for changes. The connection string setting name corresponds to the application setting (in `local.settings.json` for local development) that contains the [connection string](https://dev.mysql.com/doc/connector-net/en/connector-net-connections-string.html) to the Azure Database for MySQL.|
601608
| **LeasesTableName** | Optional. Name of the table used to store leases. If not specified, the leases table name will be Leases_{FunctionId}_{TableId}.
602609

603610

@@ -614,7 +621,7 @@ In the [Java functions runtime library](/java/api/overview/azure/functions/runti
614621
|---------|---------|
615622
| **name** | Required. The name of the parameter that the trigger binds to. |
616623
| **tableName** | Required. The name of the table monitored by the trigger. |
617-
| **connectionStringSetting** | Required. The name of an app setting that contains the connection string for the database containing the table monitored for changes. The connection string setting name corresponds to the application setting (in `local.settings.json` for local development) that contains the [connection string](https://dev.mysql.com/doc/refman/8.4/en/connecting-using-uri-or-key-value-pairs.html) to the Azure Database for MySQL.|
624+
| **connectionStringSetting** | Required. The name of an app setting that contains the connection string for the database containing the table monitored for changes. The connection string setting name corresponds to the application setting (in `local.settings.json` for local development) that contains the [connection string](https://dev.mysql.com/doc/connector-net/en/connector-net-connections-string.html) to the Azure Database for MySQL.|
618625
| **LeasesTableName** | Optional. Name of the table used to store leases. If not specified, the leases table name will be Leases_{FunctionId}_{TableId}.
619626

620627
::: zone-end
@@ -631,7 +638,7 @@ The following table explains the binding configuration properties that you set i
631638
| **type** | Required. Must be set to `MysqlTrigger`. |
632639
| **direction** | Required. Must be set to `in`. |
633640
| **tableName** | Required. The name of the table monitored by the trigger. |
634-
| **connectionStringSetting** | Required. The name of an app setting that contains the connection string for the database containing the table monitored for changes. The connection string setting name corresponds to the application setting (in `local.settings.json` for local development) that contains the [connection string](https://dev.mysql.com/doc/refman/8.4/en/connecting-using-uri-or-key-value-pairs.html) to the Azure Database for MySQL.|
641+
| **connectionStringSetting** | Required. The name of an app setting that contains the connection string for the database containing the table monitored for changes. The connection string setting name corresponds to the application setting (in `local.settings.json` for local development) that contains the [connection string](https://dev.mysql.com/doc/connector-net/en/connector-net-connections-string.html) to the Azure Database for MySQL.|
635642
| **LeasesTableName** | Optional. Name of the table used to store leases. If not specified, the leases table name will be Leases_{FunctionId}_{TableId}.
636643

637644
::: zone-end

0 commit comments

Comments
 (0)