Skip to content
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

Add SQL Binding templates to v4 #1162

Merged
merged 1 commit into from
Feb 2, 2022
Merged
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
8 changes: 8 additions & 0 deletions Build/PackageFiles/ItemTemplates.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,13 @@
<file src="..\..\Functions.Templates\Templates\KafkaOutput-CSharp\.template.config\template.json" target="content\KafkaOutput-CSharp\.template.config\template.json" />
<file src="..\..\Functions.Templates\Templates\KafkaOutput-CSharp\.template.config\vs-2017.3.host.json" target="content\KafkaOutput-CSharp\.template.config\vs-2017.3.host.json" />
<file src="..\..\Functions.Templates\Templates\KafkaOutput-CSharp\.template.config\vs-2017.3\*.*" target="content\KafkaOutput-CSharp\.template.config\vs-2017.3" />
<file src="..\..\Functions.Templates\Templates\SqlInputBinding-CSharp\SqlInputBindingCSharp.cs" target="content\SqlInputBinding-CSharp\SqlInputBindingCSharp.cs" />
<file src="..\..\Functions.Templates\Templates\SqlInputBinding-CSharp\.template.config\template.json" target="content\SqlInputBinding-CSharp\.template.config\template.json" />
<file src="..\..\Functions.Templates\Templates\SqlInputBinding-CSharp\.template.config\vs-2017.3.host.json" target="content\SqlInputBinding-CSharp\.template.config\vs-2017.3.host.json" />
<file src="..\..\Functions.Templates\Templates\SqlInputBinding-CSharp\.template.config\vs-2017.3\*.*" target="content\SqlInputBinding-CSharp\.template.config\vs-2017.3" />
<file src="..\..\Functions.Templates\Templates\SqlOutputBinding-CSharp\SqlOutputBindingCSharp.cs" target="content\SqlOutputBinding-CSharp\SqlOutputBindingCSharp.cs" />
<file src="..\..\Functions.Templates\Templates\SqlOutputBinding-CSharp\.template.config\template.json" target="content\SqlOutputBinding-CSharp\.template.config\template.json" />
<file src="..\..\Functions.Templates\Templates\SqlOutputBinding-CSharp\.template.config\vs-2017.3.host.json" target="content\SqlOutputBinding-CSharp\.template.config\vs-2017.3.host.json" />
<file src="..\..\Functions.Templates\Templates\SqlOutputBinding-CSharp\.template.config\vs-2017.3\*.*" target="content\SqlOutputBinding-CSharp\.template.config\vs-2017.3" />
</files>
</package>
6 changes: 6 additions & 0 deletions Functions.Templates/Resources/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1876,4 +1876,10 @@ function app.</value>
<data name="kafka_consumergroup_label" xml:space="preserve">
<value>Consumer Group</value>
</data>
<data name="SqlInputBinding_description" xml:space="preserve">
<value>A C# function that will be run on an HTTP trigger and returns the results of a provided SQL query.</value>
</data>
<data name="SqlOuputBinding_description" xml:space="preserve">
<value>A C# function that will be run on an HTTP trigger and takes a list of rows and upserts them into the user table (i.e. If a row doesn't already exist, it is added. If it does, it is updated).</value>
</data>
</root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"author": "Microsoft",
"classifications": [
"Azure Function",
"Input",
"SQL"
],
"name": "SqlInputBinding",
"identity": "Azure.Function.CSharp.SqlInputBinding",
"groupIdentity": "Azure.Function.SqlInputBinding",
"shortName": "sqlinput",
"tags": {
"language": "C#",
"type": "item"
},
"sourceName": "SqlInputBindingCSharp",
"symbols": {
"connectionStringSetting": {
"description": "The name of the app setting containing your SQL connection string.",
"type": "parameter",
"defaultValue": "",
"replaces": "SqlConnectionString"
},
"object": {
"description": "This is the table or view name for the SQL input binding.",
"type": "parameter",
"defaultValue": "[dbo].[table1]",
"replaces": "object"
}
},
"primaryOutputs": [
{
"path": "SqlInputBindingCSharp.cs"
}
],
"defaultName": "SqlInputBindingCSharp",
"postActions": [
{
"Description": "Adding Reference to Microsoft.Azure.WebJobs.Extensions.Sql Nuget package",
"ActionId": "B17581D1-C5C9-4489-8F0A-004BE667B814",
"ContinueOnError": "true",
"ManualInstructions": [],
"args": {
"referenceType": "package",
"reference": "Microsoft.Azure.WebJobs.Extensions.Sql", "version": "0.1.131-preview",
"projectFileExtensions": ".csproj"
}
},
{
"description": "Restore NuGet packages required by this project.",
"manualInstructions": [],
"actionId": "210D431B-A78B-4D2F-B762-4ED3E3EA9025",
"continueOnError": true
},
{
"condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")",
"description": "Opens the function class file in the editor",
"manualInstructions": [],
"actionId": "84C0DA21-51C8-4541-9940-6CA19AF04EE6",
"args": {
"files": "0"
},
"continueOnError": true
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": {
"text": "SQL input binding",
"package": "{E9BCFE2B-304A-4D7F-836F-F3A4FB1A1451}",
"id": "3000"
},
"description": {
"text": "A C# function that takes a SQL query to run on a provided table or view and returns the output of the query",
"package": "{E9BCFE2B-304A-4D7F-836F-F3A4FB1A1451}",
"id": "3001"
},
"order": 400,
"icon": "vs-2017.3/functionF.png",
"learnMoreLink": "https://aka.ms/sqlbindingsinput",
"uiFilters": [
"functions"
],
"symbolInfo": [
{
"id": "connectionStringSetting",
"name": {
"id": "3002",
"text": "Connection string setting name",
"package": "{E9BCFE2B-304A-4D7F-836F-F3A4FB1A1451}"
},
"isVisible": true
},
{
"id": "object",
"name": {
"id": "3003",
"text": "Table or View",
"package": "{E9BCFE2B-304A-4D7F-836F-F3A4FB1A1451}"
},
"isVisible": true
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;

namespace Company.Function
{
public static class SqlInputBindingCSharp
{
// Visit https://aka.ms/sqlbindingsinput to learn how to use this input binding
[FunctionName("SqlInputBinding")]
public static IActionResult Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
[Sql("SELECT * FROM object",
CommandType = System.Data.CommandType.Text,
ConnectionStringSetting = "SqlConnectionString")] IEnumerable<Object> result,
ILogger log)
{
log.LogInformation("C# HTTP trigger with SQL Input Binding function processed a request.");

return new OkObjectResult(result);
}
}
}
13 changes: 13 additions & 0 deletions Functions.Templates/Templates/SqlInputBinding-CSharp/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"bindings": [
{
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"methods": [
"get"
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# SQL Input Binding - C<span>#</span>

The `SQL Input Binding` makes it easy to retrieve data from a database, returning the output of the query or stored procedure to the function.

## How it works

For a `SQL Input Binding` to work, you provide the existing object in the database to query. For instance, you can set the object to `[dbo].[table1]` to query this table.

For more information, see the official [docs](https://aka.ms/sqlbindingsinput).
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"author": "Microsoft",
"classifications": [
"Azure Function",
"Output",
"SQL"
],
"name": "SqlOutputBinding",
"identity": "Azure.Function.CSharp.SqlOutputBinding",
"groupIdentity": "Azure.Function.SqlOutputBinding",
"shortName": "sqloutput",
"tags": {
"language": "C#",
"type": "item"
},
"sourceName": "SqlOutputBindingCSharp",
"symbols": {
"connectionStringSetting": {
"description": "The name of the app setting containing your SQL connection string.",
"type": "parameter",
"defaultValue": "",
"replaces": "SqlConnectionString"
},
"table": {
"description": "This is the table for the SQL output binding.",
"type": "parameter",
"defaultValue": "[dbo].[table1]",
"replaces": "table"
}
},
"primaryOutputs": [
{
"path": "SqlOutputBindingCSharp.cs"
}
],
"defaultName": "SqlOutputBindingCSharp",
"postActions": [
{
"Description": "Adding Reference to Microsoft.Azure.WebJobs.Extensions.Sql Nuget package",
"ActionId": "B17581D1-C5C9-4489-8F0A-004BE667B814",
"ContinueOnError": "true",
"ManualInstructions": [],
"args": {
"referenceType": "package",
"reference": "Microsoft.Azure.WebJobs.Extensions.Sql", "version": "0.1.131-preview",
"projectFileExtensions": ".csproj"
}
},
{
"description": "Restore NuGet packages required by this project.",
"manualInstructions": [],
"actionId": "210D431B-A78B-4D2F-B762-4ED3E3EA9025",
"continueOnError": true
},
{
"condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")",
"description": "Opens the function class file in the editor",
"manualInstructions": [],
"actionId": "84C0DA21-51C8-4541-9940-6CA19AF04EE6",
"args": {
"files": "0"
},
"continueOnError": true
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": {
"text": "SQL output binding",
"package": "{E9BCFE2B-304A-4D7F-836F-F3A4FB1A1451}",
"id": "3000"
},
"description": {
"text": "A C# function that takes a list of rows and upserts them into the user table",
"package": "{E9BCFE2B-304A-4D7F-836F-F3A4FB1A1451}",
"id": "3001"
},
"order": 400,
"icon": "vs-2017.3/functionF.png",
"learnMoreLink": "https://aka.ms/sqlbindingsoutput",
"uiFilters": [
"functions"
],
"symbolInfo": [
{
"id": "connectionStringSetting",
"name": {
"id": "3002",
"text": "Connection string setting name",
"package": "{E9BCFE2B-304A-4D7F-836F-F3A4FB1A1451}"
},
"isVisible": true
},
{
"id": "table",
"name": {
"id": "3003",
"text": "Table",
"package": "{E9BCFE2B-304A-4D7F-836F-F3A4FB1A1451}"
},
"isVisible": true
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;

namespace Company.Function
{
public static class SqlOutputBindingCSharp
{
// Visit https://aka.ms/sqlbindingsoutput to learn how to use this output binding
[FunctionName("SqlOutputBinding")]
public static CreatedResult Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "addtodoitem")] HttpRequest req,
[Sql("table", ConnectionStringSetting = "SqlConnectionString")] out ToDoItem output,
ILogger log)
{
log.LogInformation("C# HTTP trigger with SQL Output Binding function processed a request.");

output = new ToDoItem
{
Id = "1",
Priority = 1,
Description = "Hello World"
};

return new CreatedResult($"/api/addtodoitem", output);
}
}

public class ToDoItem
{
public string Id { get; set; }
public int Priority { get; set; }
public string Description { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"bindings": [
{
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"methods": [
"get"
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# SQL Output Binding - C<span>#</span>

The `SQL Output Binding` makes it easy to take a list of rows and upsert them into the user table (i.e. If a row doesn't already exist, it is added. If it does, it is updated).

## How it works

For a `SQL Output Binding` to work, you provide the existing table in the database to upsert rows into. For instance, you can set the table to `[dbo].[table1]` to upsert into this table.

For more information, see the official [docs](https://aka.ms/sqlbindingsoutput)