-
Notifications
You must be signed in to change notification settings - Fork 67
Add JObject support for SQL trigger #722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2911221
add support for jobject and js, ps, python samples
lucyzhang929 c686bc3
use utils JsonSerializeObject + comment
lucyzhang929 a88d2e1
Update src/TriggerBinding/SqlTriggerBindingProvider.cs
lucyzhang929 88ce3b2
fix unit test + pylint
lucyzhang929 631859e
Merge branch 'main' into luczhan/triggerjobject
lucyzhang929 dea0f27
Merge branch 'release/trigger' into luczhan/triggerjobject
Charles-Gagnon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "bindings": [ | ||
| { | ||
| "name": "changes", | ||
| "type": "sqlTrigger", | ||
| "direction": "in", | ||
| "tableName": "Products", | ||
| "connectionStringSetting": "SqlConnectionString" | ||
| } | ||
| ], | ||
| "disabled": false | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
|
||
| module.exports = async function (context, changes) { | ||
| context.log(`SQL Changes: ${JSON.stringify(changes)}`) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "bindings": [ | ||
| { | ||
| "name": "changes", | ||
| "type": "sqlTrigger", | ||
| "direction": "in", | ||
| "tableName": "Products", | ||
| "connectionStringSetting": "SqlConnectionString" | ||
| } | ||
| ], | ||
| "disabled": false | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
|
||
| using namespace System.Net | ||
|
|
||
| param($changes) | ||
| $changesJson = $changes | ConvertTo-Json | ||
| # The output is used to inspect the trigger binding parameter in test methods. | ||
| # Removing new lines for testing purposes. | ||
| $changesJson = $changesJson -replace [Environment]::NewLine,""; | ||
| Write-Host "SQL Changes: $changesJson" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| import json | ||
| import logging | ||
|
|
||
| def main(changes): | ||
| logging.info("SQL Changes: %s", json.loads(changes)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "bindings": [ | ||
| { | ||
| "name": "changes", | ||
| "type": "sqlTrigger", | ||
| "direction": "in", | ||
| "tableName": "Products", | ||
| "connectionStringSetting": "SqlConnectionString" | ||
| } | ||
| ], | ||
| "disabled": false | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,10 @@ | |
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Azure.WebJobs.Host.Bindings; | ||
|
|
||
| using Newtonsoft.Json.Linq; | ||
|
|
||
| namespace Microsoft.Azure.WebJobs.Extensions.Sql | ||
| { | ||
|
|
@@ -15,6 +16,8 @@ internal class SqlTriggerValueProvider : IValueProvider | |
| { | ||
| private readonly object _value; | ||
| private readonly string _tableName; | ||
| private readonly Type _parameterType; | ||
| private readonly bool _isString; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="SqlTriggerValueProvider"/> class. | ||
|
|
@@ -24,21 +27,37 @@ internal class SqlTriggerValueProvider : IValueProvider | |
| /// <param name="tableName">Name of the user table</param> | ||
| public SqlTriggerValueProvider(Type parameterType, object value, string tableName) | ||
| { | ||
| this.Type = parameterType; | ||
| this._parameterType = parameterType; | ||
| this._value = value; | ||
| this._tableName = tableName; | ||
| this._isString = parameterType == typeof(string); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the trigger argument value. | ||
| /// </summary> | ||
| public Type Type { get; } | ||
| public Type Type | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Followed the CosmosDB extension implementation here. They also support JArray but the languages I tested so far (JS, PS, Python) are only using String. We can add JArray later if needed for other languages/scenarios. |
||
| { | ||
| get | ||
| { | ||
| if (this._isString) | ||
| { | ||
| return typeof(IReadOnlyCollection<JObject>); | ||
| } | ||
| return this._parameterType; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns value of the trigger argument. | ||
| /// </summary> | ||
| public Task<object> GetValueAsync() | ||
| { | ||
| if (this._isString) | ||
| { | ||
| return Task.FromResult<object>(Utils.JsonSerializeObject(this._value)); | ||
| } | ||
|
|
||
| return Task.FromResult(this._value); | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.