-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathSqlTriggerAttribute.cs
55 lines (49 loc) · 2.74 KB
/
SqlTriggerAttribute.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
using Microsoft.Azure.WebJobs.Description;
namespace Microsoft.Azure.WebJobs
{
/// <summary>
/// Attribute used to bind a parameter to SQL trigger message.
/// </summary>
[Binding]
[AttributeUsage(AttributeTargets.Parameter)]
public sealed class SqlTriggerAttribute : Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="SqlTriggerAttribute"/> class, which triggers the function when any changes on the specified table are detected.
/// </summary>
/// <param name="tableName">Name of the table to watch for changes.</param>
/// <param name="connectionStringSetting">The name of the app setting where the SQL connection string is stored</param>
/// <param name="leasesTableName">Optional - The name of the table used to store leases. If not specified, the leases table name will be Leases_{FunctionId}_{TableId}</param>
public SqlTriggerAttribute(string tableName, string connectionStringSetting, string leasesTableName = null)
{
this.TableName = tableName ?? throw new ArgumentNullException(nameof(tableName));
this.ConnectionStringSetting = connectionStringSetting ?? throw new ArgumentNullException(nameof(connectionStringSetting));
this.LeasesTableName = leasesTableName;
}
/// <summary>
/// Initializes a new instance of the <see cref="SqlTriggerAttribute"/> class with null value for LeasesTableName.
/// </summary>
/// <param name="tableName">Name of the table to watch for changes.</param>
/// <param name="connectionStringSetting">The name of the app setting where the SQL connection string is stored</param>
public SqlTriggerAttribute(string tableName, string connectionStringSetting) : this(tableName, connectionStringSetting, null) { }
/// <summary>
/// Name of the app setting containing the SQL connection string.
/// </summary>
[ConnectionString]
public string ConnectionStringSetting { get; }
/// <summary>
/// Name of the table to watch for changes.
/// </summary>
public string TableName { get; }
/// <summary>
/// Name of the table used to store leases.
/// If not specified, the leases table name will be Leases_{FunctionId}_{TableId}
/// More information on how this is generated can be found here
/// https://github.com/Azure/azure-functions-sql-extension/blob/main/docs/TriggerBinding.md#az_funcleasestablename
/// </summary>
public string LeasesTableName { get; }
}
}