Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<RootNamespace>Microsoft.Azure.Functions.Worker.Extensions.Sql</RootNamespace>
<Description>Sql extension for .NET isolated Azure Functions</Description>
<Product>SQL Binding Worker</Product>
<TargetFramework>net6</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<!-- Default Version for dev -->
<Version>99.99.99</Version>
<OOPWorkerSupportedExtensionVersion>99.99.99</OOPWorkerSupportedExtensionVersion>
Expand Down
21 changes: 8 additions & 13 deletions Worker.Extensions.Sql/src/SqlChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,25 @@ namespace Microsoft.Azure.Functions.Worker.Extensions.Sql
/// Represents the changed row in the user table.
/// </summary>
/// <typeparam name="T">POCO class representing the row in the user table</typeparam>
public sealed class SqlChange<T>
/// <remarks>
/// Initializes a new instance of the <see cref="SqlChange{T}"/> class.
/// </remarks>
/// <param name="operation">Change operation</param>
/// <param name="item">POCO representing the row in the user table on which the change operation took place</param>
public sealed class SqlChange<T>(SqlChangeOperation operation, T item)
{
/// <summary>
/// Initializes a new instance of the <see cref="SqlChange{T}"/> class.
/// </summary>
/// <param name="operation">Change operation</param>
/// <param name="item">POCO representing the row in the user table on which the change operation took place</param>
public SqlChange(SqlChangeOperation operation, T item)
{
this.Operation = operation;
this.Item = item;
}

/// <summary>
/// Change operation (insert, update, or delete).
/// </summary>
public SqlChangeOperation Operation { get; }
public SqlChangeOperation Operation { get; } = operation;

/// <summary>
/// POCO representing the row in the user table on which the change operation took place. If the change
/// operation is <see cref="SqlChangeOperation.Delete" />, then only the properties corresponding to the primary
/// keys will be populated.
/// </summary>
public T Item { get; }
public T Item { get; } = item;
}

/// <summary>
Expand Down
32 changes: 13 additions & 19 deletions Worker.Extensions.Sql/src/SqlInputAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,16 @@

namespace Microsoft.Azure.Functions.Worker.Extensions.Sql
{
public sealed class SqlInputAttribute : InputBindingAttribute
/// <summary>
/// Creates an instance of the <see cref="SqlInputAttribute"/>, which takes a SQL query or stored procedure to run and returns the output to the function.
/// </summary>
/// <param name="commandText">Either a SQL query or stored procedure that will be run in the target database.</param>
/// <param name="connectionStringSetting">The name of the app setting where the SQL connection string is stored</param>
/// <param name="commandType">Specifies whether <see cref="CommandText"/> refers to a stored procedure or SQL query string. Defaults to <see cref="CommandType.Text"/></param>
/// <param name="parameters">Optional - Specifies the parameters that will be used to execute the SQL query or stored procedure. See <see cref="Parameters"/> for more details.</param>
public sealed class SqlInputAttribute(string commandText, string connectionStringSetting, CommandType commandType = CommandType.Text, string parameters = null) : InputBindingAttribute
{
/// <summary>
/// Creates an instance of the <see cref="SqlInputAttribute"/>, which takes a SQL query or stored procedure to run and returns the output to the function.
/// </summary>
/// <param name="commandText">Either a SQL query or stored procedure that will be run in the target database.</param>
/// <param name="connectionStringSetting">The name of the app setting where the SQL connection string is stored</param>
/// <param name="commandType">Specifies whether <see cref="CommandText"/> refers to a stored procedure or SQL query string. Defaults to <see cref="CommandType.Text"/></param>
/// <param name="parameters">Optional - Specifies the parameters that will be used to execute the SQL query or stored procedure. See <see cref="Parameters"/> for more details.</param>
public SqlInputAttribute(string commandText, string connectionStringSetting, CommandType commandType = CommandType.Text, string parameters = null)
{
this.CommandText = commandText ?? throw new ArgumentNullException(nameof(commandText));
this.ConnectionStringSetting = connectionStringSetting ?? throw new ArgumentNullException(nameof(connectionStringSetting));
this.CommandType = commandType;
this.Parameters = parameters;
}


/// <summary>
/// Creates an instance of the <see cref="SqlInputAttribute"/>, which takes a SQL query or stored procedure to run and returns the output to the function.
Expand All @@ -40,19 +34,19 @@ public SqlInputAttribute(string commandText, string connectionStringSetting) : t
/// create a ConnectionStringSetting with a name like SqlServerAuthentication. The value of the SqlServerAuthentication app setting
/// would look like "Data Source=test.database.windows.net;Database=TestDB;User ID={userid};Password={password}".
/// </summary>
public string ConnectionStringSetting { get; }
public string ConnectionStringSetting { get; } = connectionStringSetting ?? throw new ArgumentNullException(nameof(connectionStringSetting));

/// <summary>
/// Either a SQL query or stored procedure that will be run in the target database.
/// </summary>
public string CommandText { get; }
public string CommandText { get; } = commandText ?? throw new ArgumentNullException(nameof(commandText));

/// <summary>
/// Specifies whether <see cref="CommandText"/> refers to a stored procedure or SQL query string.
/// Use <see cref="CommandType.StoredProcedure"/> for the former, <see cref="CommandType.Text"/> for the latter.
/// Defaults to <see cref="CommandType.Text"/>.
/// </summary>
public CommandType CommandType { get; }
public CommandType CommandType { get; } = commandType;

/// <summary>
/// Specifies the parameters that will be used to execute the SQL query or stored procedure specified in <see cref="CommandText"/>.
Expand All @@ -63,6 +57,6 @@ public SqlInputAttribute(string commandText, string connectionStringSetting) : t
/// as in "@param1=,@param2=param2"
/// Note that neither the parameter name nor the parameter value can have ',' or '='
/// </summary>
public string Parameters { get; }
public string Parameters { get; } = parameters;
}
}
22 changes: 9 additions & 13 deletions Worker.Extensions.Sql/src/SqlOutputAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@

namespace Microsoft.Azure.Functions.Worker.Extensions.Sql
{
public class SqlOutputAttribute : OutputBindingAttribute
/// <summary>
/// Creates an instance of the <see cref="SqlOutputAttribute"/>, which takes a list of rows and upserts them into the target table.
/// </summary>
/// <param name="commandText">The table name to upsert the values to.</param>
/// <param name="connectionStringSetting">The name of the app setting where the SQL connection string is stored</param>
public class SqlOutputAttribute(string commandText, string connectionStringSetting) : OutputBindingAttribute
{
/// <summary>
/// Creates an instance of the <see cref="SqlOutputAttribute"/>, which takes a list of rows and upserts them into the target table.
/// </summary>
/// <param name="commandText">The table name to upsert the values to.</param>
/// <param name="connectionStringSetting">The name of the app setting where the SQL connection string is stored</param>
public SqlOutputAttribute(string commandText, string connectionStringSetting)
{
this.CommandText = commandText ?? throw new ArgumentNullException(nameof(commandText));
this.ConnectionStringSetting = connectionStringSetting ?? throw new ArgumentNullException(nameof(connectionStringSetting));
}


/// <summary>
/// The name of the app setting where the SQL connection string is stored
Expand All @@ -28,11 +24,11 @@ public SqlOutputAttribute(string commandText, string connectionStringSetting)
/// create a ConnectionStringSetting with a name like SqlServerAuthentication. The value of the SqlServerAuthentication app setting
/// would look like "Data Source=test.database.windows.net;Database=TestDB;User ID={userid};Password={password}".
/// </summary>
public string ConnectionStringSetting { get; }
public string ConnectionStringSetting { get; } = connectionStringSetting ?? throw new ArgumentNullException(nameof(connectionStringSetting));

/// <summary>
/// The table name to upsert the values to.
/// </summary>
public string CommandText { get; }
public string CommandText { get; } = commandText ?? throw new ArgumentNullException(nameof(commandText));
}
}
27 changes: 11 additions & 16 deletions Worker.Extensions.Sql/src/SqlTriggerAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,15 @@

namespace Microsoft.Azure.Functions.Worker.Extensions.Sql
{
public sealed class SqlTriggerAttribute : TriggerBindingAttribute
/// <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 sealed class SqlTriggerAttribute(string tableName, string connectionStringSetting, string leasesTableName = null) : TriggerBindingAttribute
{
/// <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.
Expand All @@ -31,19 +26,19 @@ public SqlTriggerAttribute(string tableName, string connectionStringSetting) : t
/// <summary>
/// Name of the app setting containing the SQL connection string.
/// </summary>
public string ConnectionStringSetting { get; }
public string ConnectionStringSetting { get; } = connectionStringSetting ?? throw new ArgumentNullException(nameof(connectionStringSetting));

/// <summary>
/// Name of the table to watch for changes.
/// </summary>
public string TableName { get; }
public string TableName { get; } = tableName ?? throw new ArgumentNullException(nameof(tableName));

/// <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; }
public string LeasesTableName { get; } = leasesTableName;
}
}
2 changes: 1 addition & 1 deletion Worker.Extensions.Sql/src/packages.lock.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": 2,
"dependencies": {
"net6.0": {
"net8.0": {
"Microsoft.Azure.Functions.Worker.Extensions.Abstractions": {
"type": "Direct",
"requested": "[1.3.0, )",
Expand Down
4 changes: 1 addition & 3 deletions builds/azure-pipelines/template-steps-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ steps:
inputs:
workingFile: $(Build.SourcesDirectory)/${{ parameters.sourcesSubdirectory }}/.npmrc

# Temporarily install Azure Functions Core Tools 4.0.7317 as the latest version (4.0.7512) causes 11 Python tests to fail
# Tracking issue: https://github.com/Azure/azure-functions-sql-extension/issues/1193
- script: npm install azure-functions-core-tools@4.0.7317 --global --globalconfig $(Build.SourcesDirectory)/${{ parameters.sourcesSubdirectory }}/.npmrc --loglevel verbose
- script: npm install azure-functions-core-tools --global --globalconfig $(Build.SourcesDirectory)/${{ parameters.sourcesSubdirectory }}/.npmrc --loglevel verbose
displayName: 'Install Azure Functions Core Tools'

- script: npm install azurite --global --globalconfig $(Build.SourcesDirectory)/${{ parameters.sourcesSubdirectory }}/.npmrc --loglevel verbose
Expand Down