diff --git a/docs/SetupGuide_DotnetCSharpScript.md b/docs/SetupGuide_DotnetCSharpScript.md index 44ba9ab60..535f8ea13 100644 --- a/docs/SetupGuide_DotnetCSharpScript.md +++ b/docs/SetupGuide_DotnetCSharpScript.md @@ -130,19 +130,19 @@ The database scripts used for the following samples can be found [here](https:// #### Query String -See the [GetProducts](https://github.com/Azure/azure-functions-sql-extension/blob/main/samples/samples-csx/InputBindingSamples/GetProducts) sample +See the [GetProducts](https://github.com/Azure/azure-functions-sql-extension/blob/main/samples/samples-csx/GetProducts) sample #### Empty Parameter Value -See the [GetProductsNameEmpty](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-csx/InputBindingSamples/GetProductsNameEmpty) sample +See the [GetProductsNameEmpty](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-csx/GetProductsNameEmpty) sample #### Null Parameter Value -See the [GetProductsNameNull](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-csx/InputBindingSamples/GetProductsNameNull) sample +See the [GetProductsNameNull](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-csx/GetProductsNameNull) sample #### Stored Procedure -See the [GetProductsStoredProcedure](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-csx/InputBindingSamples/GetProductsStoredProcedure) sample +See the [GetProductsStoredProcedure](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-csx/GetProductsStoredProcedure) sample ## Output Binding @@ -172,14 +172,13 @@ Note: This tutorial requires that a SQL database is setup as shown in [Create a ```csharp #load "employee.csx" #r "Newtonsoft.Json" - #r "Microsoft.Azure.WebJobs.Extensions.Sql" using System.Net; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Primitives; using Newtonsoft.Json; - public static Product Run(HttpRequest req, ILogger log, [Sql("dbo.Employees", "SqlConnectionString")] out Employee employee) + public static Product Run(HttpRequest req, ILogger log, out Employee employee) { log.LogInformation("CSX HTTP trigger function processed a request."); @@ -218,12 +217,12 @@ Note: This tutorial requires that a SQL database is setup as shown in [Create a #### Array -See the [AddProductsArray](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-csx/OutputBindingSamples/AddProductsArray) sample +See the [AddProductsArray](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-csx/AddProductsArray) sample #### Single Row -See the [AddProduct](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-csx/OutputBindingSamples/AddProduct) sample +See the [AddProduct](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-csx/AddProduct) sample ### Sample with multiple Bindings -See the [GetAndAddProducts](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-csx/InputBindingSamples/GetAndAddProducts) sample +See the [GetAndAddProducts](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-csx/GetAndAddProducts) sample diff --git a/samples/samples-csx/OutputBindingSamples/AddProduct/function.json b/samples/samples-csx/AddProduct/function.json similarity index 100% rename from samples/samples-csx/OutputBindingSamples/AddProduct/function.json rename to samples/samples-csx/AddProduct/function.json diff --git a/samples/samples-csx/AddProduct/run.csx b/samples/samples-csx/AddProduct/run.csx new file mode 100644 index 000000000..e4c5c5c6b --- /dev/null +++ b/samples/samples-csx/AddProduct/run.csx @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +#load "../Common/product.csx" +#r "Newtonsoft.Json" + +using System.Net; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Primitives; +using Newtonsoft.Json; + +public static Product Run(HttpRequest req, ILogger log, out Product product) +{ + string requestBody = new StreamReader(req.Body).ReadToEnd(); + product = JsonConvert.DeserializeObject(requestBody); + + return product; +} \ No newline at end of file diff --git a/samples/samples-csx/OutputBindingSamples/AddProductParams/function.json b/samples/samples-csx/AddProductParams/function.json similarity index 100% rename from samples/samples-csx/OutputBindingSamples/AddProductParams/function.json rename to samples/samples-csx/AddProductParams/function.json diff --git a/samples/samples-csx/AddProductParams/run.csx b/samples/samples-csx/AddProductParams/run.csx new file mode 100644 index 000000000..901893e2f --- /dev/null +++ b/samples/samples-csx/AddProductParams/run.csx @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +#load "../Common/product.csx" +#r "Newtonsoft.Json" + +using System.Net; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Primitives; +using Newtonsoft.Json; + +public static Product Run(HttpRequest req, ILogger log, out Product product) +{ + product = new Product + { + Name = req.Query["name"], + ProductId = int.Parse(req.Query["productId"]), + Cost = int.Parse(req.Query["cost"]) + }; + + return product; +} \ No newline at end of file diff --git a/samples/samples-csx/OutputBindingSamples/AddProductWithDefaultPK/function.json b/samples/samples-csx/AddProductWithDefaultPK/function.json similarity index 100% rename from samples/samples-csx/OutputBindingSamples/AddProductWithDefaultPK/function.json rename to samples/samples-csx/AddProductWithDefaultPK/function.json diff --git a/samples/samples-csx/AddProductWithDefaultPK/run.csx b/samples/samples-csx/AddProductWithDefaultPK/run.csx new file mode 100644 index 000000000..da5a38bf4 --- /dev/null +++ b/samples/samples-csx/AddProductWithDefaultPK/run.csx @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +#load "../Common/product.csx" +#r "Newtonsoft.Json" + +using System.Net; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Primitives; +using Newtonsoft.Json; + +public static ProductWithDefaultPK Run(HttpRequest req, ILogger log, out ProductWithDefaultPK product) +{ + string requestBody = new StreamReader(req.Body).ReadToEnd(); + product = JsonConvert.DeserializeObject(requestBody); + + return product; +} \ No newline at end of file diff --git a/samples/samples-csx/OutputBindingSamples/AddProductWithIdentityColumn/function.json b/samples/samples-csx/AddProductWithIdentityColumn/function.json similarity index 100% rename from samples/samples-csx/OutputBindingSamples/AddProductWithIdentityColumn/function.json rename to samples/samples-csx/AddProductWithIdentityColumn/function.json diff --git a/samples/samples-csx/OutputBindingSamples/AddProductWithIdentityColumn/run.csx b/samples/samples-csx/AddProductWithIdentityColumn/run.csx similarity index 50% rename from samples/samples-csx/OutputBindingSamples/AddProductWithIdentityColumn/run.csx rename to samples/samples-csx/AddProductWithIdentityColumn/run.csx index 60e73f317..f04f04dcf 100644 --- a/samples/samples-csx/OutputBindingSamples/AddProductWithIdentityColumn/run.csx +++ b/samples/samples-csx/AddProductWithIdentityColumn/run.csx @@ -1,28 +1,21 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -#load "../../Common/product.csx" +#load "../Common/product.csx" #r "Newtonsoft.Json" -#r "Microsoft.Azure.WebJobs.Extensions.Sql" using System.Net; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Primitives; using Newtonsoft.Json; -public static ProductWithoutId Run(HttpRequest req, ILogger log, [Sql("dbo.Products", "SqlConnectionString")] out ProductWithoutId product) +public static ProductWithoutId Run(HttpRequest req, ILogger log, out ProductWithoutId product) { - log.LogInformation("C# HTTP trigger function processed a request."); - product = new ProductWithoutId { Name = req.Query["name"], Cost = int.Parse(req.Query["cost"]) }; - string responseMessage = string.IsNullOrEmpty(product.Name) - ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response." - : $"Hello, {product.Name}. This HTTP triggered function executed successfully."; - return product; } \ No newline at end of file diff --git a/samples/samples-csx/OutputBindingSamples/AddProductWithIdentityColumnIncluded/function.json b/samples/samples-csx/AddProductWithIdentityColumnIncluded/function.json similarity index 100% rename from samples/samples-csx/OutputBindingSamples/AddProductWithIdentityColumnIncluded/function.json rename to samples/samples-csx/AddProductWithIdentityColumnIncluded/function.json diff --git a/samples/samples-csx/OutputBindingSamples/AddProductWithIdentityColumnIncluded/run.csx b/samples/samples-csx/AddProductWithIdentityColumnIncluded/run.csx similarity index 53% rename from samples/samples-csx/OutputBindingSamples/AddProductWithIdentityColumnIncluded/run.csx rename to samples/samples-csx/AddProductWithIdentityColumnIncluded/run.csx index 7da049f2f..b3c0c4d43 100644 --- a/samples/samples-csx/OutputBindingSamples/AddProductWithIdentityColumnIncluded/run.csx +++ b/samples/samples-csx/AddProductWithIdentityColumnIncluded/run.csx @@ -1,19 +1,16 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -#load "../../Common/product.csx" +#load "../Common/product.csx" #r "Newtonsoft.Json" -#r "Microsoft.Azure.WebJobs.Extensions.Sql" using System.Net; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Primitives; using Newtonsoft.Json; -public static ProductWithOptionalId Run(HttpRequest req, ILogger log, [Sql("dbo.ProductsWithIdentity", "SqlConnectionString")] out ProductWithOptionalId product) +public static ProductWithOptionalId Run(HttpRequest req, ILogger log, out ProductWithOptionalId product) { - log.LogInformation("C# HTTP trigger function processed a request."); - product = product = new ProductWithOptionalId { Name = req.Query["name"], @@ -21,9 +18,5 @@ public static ProductWithOptionalId Run(HttpRequest req, ILogger log, [Sql("dbo. Cost = int.Parse(req.Query["cost"]) }; - string responseMessage = string.IsNullOrEmpty(product.Name) - ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response." - : $"Hello, {product.Name}. This HTTP triggered function executed successfully."; - return product; } \ No newline at end of file diff --git a/samples/samples-csx/OutputBindingSamples/AddProductWithMultiplePrimaryColumnsAndIdentity/function.json b/samples/samples-csx/AddProductWithMultiplePrimaryColumnsAndIdentity/function.json similarity index 100% rename from samples/samples-csx/OutputBindingSamples/AddProductWithMultiplePrimaryColumnsAndIdentity/function.json rename to samples/samples-csx/AddProductWithMultiplePrimaryColumnsAndIdentity/function.json diff --git a/samples/samples-csx/AddProductWithMultiplePrimaryColumnsAndIdentity/run.csx b/samples/samples-csx/AddProductWithMultiplePrimaryColumnsAndIdentity/run.csx new file mode 100644 index 000000000..34acece3e --- /dev/null +++ b/samples/samples-csx/AddProductWithMultiplePrimaryColumnsAndIdentity/run.csx @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +#load "../Common/product.csx" +#r "Newtonsoft.Json" + +using System.Net; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Primitives; +using Newtonsoft.Json; + +public static MultiplePrimaryKeyProductWithoutId Run(HttpRequest req, ILogger log, out MultiplePrimaryKeyProductWithoutId product) +{ + product = product = new MultiplePrimaryKeyProductWithoutId + { + ExternalId = int.Parse(req.Query["externalId"]), + Name = req.Query["name"], + Cost = int.Parse(req.Query["cost"]) + }; + + return product; +} \ No newline at end of file diff --git a/samples/samples-csx/OutputBindingSamples/AddProductsArray/function.json b/samples/samples-csx/AddProductsArray/function.json similarity index 100% rename from samples/samples-csx/OutputBindingSamples/AddProductsArray/function.json rename to samples/samples-csx/AddProductsArray/function.json diff --git a/samples/samples-csx/AddProductsArray/run.csx b/samples/samples-csx/AddProductsArray/run.csx new file mode 100644 index 000000000..a4431d153 --- /dev/null +++ b/samples/samples-csx/AddProductsArray/run.csx @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +#load "../Common/product.csx" +#r "Newtonsoft.Json" + +using System.Net; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Primitives; +using Newtonsoft.Json; + +public static Product[] Run(HttpRequest req, ILogger log, out Product[] products) +{ + string requestBody = new StreamReader(req.Body).ReadToEnd(); + products = JsonConvert.DeserializeObject(requestBody); + + return products; +} \ No newline at end of file diff --git a/samples/samples-csx/OutputBindingSamples/AddProductsCollector/function.json b/samples/samples-csx/AddProductsCollector/function.json similarity index 100% rename from samples/samples-csx/OutputBindingSamples/AddProductsCollector/function.json rename to samples/samples-csx/AddProductsCollector/function.json diff --git a/samples/samples-csx/OutputBindingSamples/AddProductsCollector/run.csx b/samples/samples-csx/AddProductsCollector/run.csx similarity index 69% rename from samples/samples-csx/OutputBindingSamples/AddProductsCollector/run.csx rename to samples/samples-csx/AddProductsCollector/run.csx index 7e516484b..fb7e878de 100644 --- a/samples/samples-csx/OutputBindingSamples/AddProductsCollector/run.csx +++ b/samples/samples-csx/AddProductsCollector/run.csx @@ -1,18 +1,15 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -#load "../../Common/product.csx" +#load "../Common/product.csx" #r "Newtonsoft.Json" -#r "Microsoft.Azure.WebJobs.Extensions.Sql" using System.Collections.Generic; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -public static ICollector Run(HttpRequest req, ILogger log, [Sql("dbo.Products", "SqlConnectionString")] ICollector products) +public static ICollector Run(HttpRequest req, ILogger log, ICollector products) { - log.LogInformation("C# HTTP trigger function processed a request."); - List newProducts = ProductUtilities.GetNewProducts(5000); foreach (Product product in newProducts) { diff --git a/samples/samples-csx/OutputBindingSamples/AddProductsWithIdentityColumnArray/function.json b/samples/samples-csx/AddProductsWithIdentityColumnArray/function.json similarity index 100% rename from samples/samples-csx/OutputBindingSamples/AddProductsWithIdentityColumnArray/function.json rename to samples/samples-csx/AddProductsWithIdentityColumnArray/function.json diff --git a/samples/samples-csx/OutputBindingSamples/AddProductsWithIdentityColumnArray/run.csx b/samples/samples-csx/AddProductsWithIdentityColumnArray/run.csx similarity index 57% rename from samples/samples-csx/OutputBindingSamples/AddProductsWithIdentityColumnArray/run.csx rename to samples/samples-csx/AddProductsWithIdentityColumnArray/run.csx index 303f19d14..0e9f9dca8 100644 --- a/samples/samples-csx/OutputBindingSamples/AddProductsWithIdentityColumnArray/run.csx +++ b/samples/samples-csx/AddProductsWithIdentityColumnArray/run.csx @@ -1,19 +1,16 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -#load "../../Common/product.csx" +#load "../Common/product.csx" #r "Newtonsoft.Json" -#r "Microsoft.Azure.WebJobs.Extensions.Sql" using System.Net; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Primitives; using Newtonsoft.Json; -public static ProductWithoutId[] Run(HttpRequest req, ILogger log, [Sql("dbo.Products", "SqlConnectionString")] out ProductWithoutId[] products) +public static ProductWithoutId[] Run(HttpRequest req, ILogger log, out ProductWithoutId[] products) { - log.LogInformation("C# HTTP trigger function processed a request."); - products = new[] { new ProductWithoutId @@ -28,9 +25,5 @@ public static ProductWithoutId[] Run(HttpRequest req, ILogger log, [Sql("dbo.Pro } }; - string responseMessage = products.Length > 0 - ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response." - : "No data passed, Please pass the objects to upsert in the request body."; - return products; } \ No newline at end of file diff --git a/samples/samples-csx/InputBindingSamples/GetAndAddProducts/function.json b/samples/samples-csx/GetAndAddProducts/function.json similarity index 100% rename from samples/samples-csx/InputBindingSamples/GetAndAddProducts/function.json rename to samples/samples-csx/GetAndAddProducts/function.json diff --git a/samples/samples-csx/InputBindingSamples/GetAndAddProducts/run.csx b/samples/samples-csx/GetAndAddProducts/run.csx similarity index 64% rename from samples/samples-csx/InputBindingSamples/GetAndAddProducts/run.csx rename to samples/samples-csx/GetAndAddProducts/run.csx index 505744667..8a16a707c 100644 --- a/samples/samples-csx/InputBindingSamples/GetAndAddProducts/run.csx +++ b/samples/samples-csx/GetAndAddProducts/run.csx @@ -1,9 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -#load "../../Common/product.csx" +#load "../Common/product.csx" #r "Newtonsoft.Json" -#r "Microsoft.Azure.WebJobs.Extensions.Sql" using System.Net; using Microsoft.AspNetCore.Mvc; @@ -11,9 +10,8 @@ using Microsoft.Extensions.Primitives; using Newtonsoft.Json; using System.Collections.Generic; -public static Product[] Run(HttpRequest req, ILogger log, IEnumerable products, [Sql("dbo.ProductsWithIdentity", "SqlConnectionString")] out Product[] productsWithIdentity) +public static Product[] Run(HttpRequest req, ILogger log, IEnumerable products, out Product[] productsWithIdentity) { - log.LogInformation("C# HTTP trigger function processed a request."); productsWithIdentity = products.ToArray(); return productsWithIdentity; } diff --git a/samples/samples-csx/InputBindingSamples/GetProductNamesView/function.json b/samples/samples-csx/GetProductNamesView/function.json similarity index 100% rename from samples/samples-csx/InputBindingSamples/GetProductNamesView/function.json rename to samples/samples-csx/GetProductNamesView/function.json diff --git a/samples/samples-csx/InputBindingSamples/GetProductNamesView/run.csx b/samples/samples-csx/GetProductNamesView/run.csx similarity index 81% rename from samples/samples-csx/InputBindingSamples/GetProductNamesView/run.csx rename to samples/samples-csx/GetProductNamesView/run.csx index b6a8bc62a..da0129fd0 100644 --- a/samples/samples-csx/InputBindingSamples/GetProductNamesView/run.csx +++ b/samples/samples-csx/GetProductNamesView/run.csx @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -#load "../../Common/product.csx" +#load "../Common/product.csx" #r "Newtonsoft.Json" using System.Net; @@ -12,6 +12,5 @@ using System.Collections.Generic; public static IActionResult Run(HttpRequest req, ILogger log, IEnumerable products) { - log.LogInformation("C# HTTP trigger function processed a request."); return new OkObjectResult(products); } diff --git a/samples/samples-csx/InputBindingSamples/GetProducts/function.json b/samples/samples-csx/GetProducts/function.json similarity index 100% rename from samples/samples-csx/InputBindingSamples/GetProducts/function.json rename to samples/samples-csx/GetProducts/function.json diff --git a/samples/samples-csx/InputBindingSamples/GetProductsNameEmpty/run.csx b/samples/samples-csx/GetProducts/run.csx similarity index 81% rename from samples/samples-csx/InputBindingSamples/GetProductsNameEmpty/run.csx rename to samples/samples-csx/GetProducts/run.csx index b00a86fcb..bac16e698 100644 --- a/samples/samples-csx/InputBindingSamples/GetProductsNameEmpty/run.csx +++ b/samples/samples-csx/GetProducts/run.csx @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -#load "../../Common/product.csx" +#load "../Common/product.csx" #r "Newtonsoft.Json" using System.Net; @@ -12,6 +12,5 @@ using System.Collections.Generic; public static IActionResult Run(HttpRequest req, ILogger log, IEnumerable products) { - log.LogInformation("C# HTTP trigger function processed a request."); return new OkObjectResult(products); } diff --git a/samples/samples-csx/InputBindingSamples/GetProductsAsyncEnumerable/function.json b/samples/samples-csx/GetProductsAsyncEnumerable/function.json similarity index 100% rename from samples/samples-csx/InputBindingSamples/GetProductsAsyncEnumerable/function.json rename to samples/samples-csx/GetProductsAsyncEnumerable/function.json diff --git a/samples/samples-csx/InputBindingSamples/GetProductsAsyncEnumerable/run.csx b/samples/samples-csx/GetProductsAsyncEnumerable/run.csx similarity index 95% rename from samples/samples-csx/InputBindingSamples/GetProductsAsyncEnumerable/run.csx rename to samples/samples-csx/GetProductsAsyncEnumerable/run.csx index c041161f0..f7f3eb489 100644 --- a/samples/samples-csx/InputBindingSamples/GetProductsAsyncEnumerable/run.csx +++ b/samples/samples-csx/GetProductsAsyncEnumerable/run.csx @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -#load "../../Common/product.csx" +#load "../Common/product.csx" #r "Newtonsoft.Json" using System.Net; diff --git a/samples/samples-csx/InputBindingSamples/GetProductsNameEmpty/function.json b/samples/samples-csx/GetProductsNameEmpty/function.json similarity index 100% rename from samples/samples-csx/InputBindingSamples/GetProductsNameEmpty/function.json rename to samples/samples-csx/GetProductsNameEmpty/function.json diff --git a/samples/samples-csx/InputBindingSamples/GetProductsNameNull/run.csx b/samples/samples-csx/GetProductsNameEmpty/run.csx similarity index 81% rename from samples/samples-csx/InputBindingSamples/GetProductsNameNull/run.csx rename to samples/samples-csx/GetProductsNameEmpty/run.csx index b00a86fcb..bac16e698 100644 --- a/samples/samples-csx/InputBindingSamples/GetProductsNameNull/run.csx +++ b/samples/samples-csx/GetProductsNameEmpty/run.csx @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -#load "../../Common/product.csx" +#load "../Common/product.csx" #r "Newtonsoft.Json" using System.Net; @@ -12,6 +12,5 @@ using System.Collections.Generic; public static IActionResult Run(HttpRequest req, ILogger log, IEnumerable products) { - log.LogInformation("C# HTTP trigger function processed a request."); return new OkObjectResult(products); } diff --git a/samples/samples-csx/InputBindingSamples/GetProductsNameNull/function.json b/samples/samples-csx/GetProductsNameNull/function.json similarity index 100% rename from samples/samples-csx/InputBindingSamples/GetProductsNameNull/function.json rename to samples/samples-csx/GetProductsNameNull/function.json diff --git a/samples/samples-csx/InputBindingSamples/GetProductsStoredProcedure/run.csx b/samples/samples-csx/GetProductsNameNull/run.csx similarity index 81% rename from samples/samples-csx/InputBindingSamples/GetProductsStoredProcedure/run.csx rename to samples/samples-csx/GetProductsNameNull/run.csx index b00a86fcb..bac16e698 100644 --- a/samples/samples-csx/InputBindingSamples/GetProductsStoredProcedure/run.csx +++ b/samples/samples-csx/GetProductsNameNull/run.csx @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -#load "../../Common/product.csx" +#load "../Common/product.csx" #r "Newtonsoft.Json" using System.Net; @@ -12,6 +12,5 @@ using System.Collections.Generic; public static IActionResult Run(HttpRequest req, ILogger log, IEnumerable products) { - log.LogInformation("C# HTTP trigger function processed a request."); return new OkObjectResult(products); } diff --git a/samples/samples-csx/InputBindingSamples/GetProductsStoredProcedure/function.json b/samples/samples-csx/GetProductsStoredProcedure/function.json similarity index 100% rename from samples/samples-csx/InputBindingSamples/GetProductsStoredProcedure/function.json rename to samples/samples-csx/GetProductsStoredProcedure/function.json diff --git a/samples/samples-csx/InputBindingSamples/GetProducts/run.csx b/samples/samples-csx/GetProductsStoredProcedure/run.csx similarity index 81% rename from samples/samples-csx/InputBindingSamples/GetProducts/run.csx rename to samples/samples-csx/GetProductsStoredProcedure/run.csx index b00a86fcb..bac16e698 100644 --- a/samples/samples-csx/InputBindingSamples/GetProducts/run.csx +++ b/samples/samples-csx/GetProductsStoredProcedure/run.csx @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -#load "../../Common/product.csx" +#load "../Common/product.csx" #r "Newtonsoft.Json" using System.Net; @@ -12,6 +12,5 @@ using System.Collections.Generic; public static IActionResult Run(HttpRequest req, ILogger log, IEnumerable products) { - log.LogInformation("C# HTTP trigger function processed a request."); return new OkObjectResult(products); } diff --git a/samples/samples-csx/InputBindingSamples/GetProductsStoredProcedureFromAppSetting/function.json b/samples/samples-csx/GetProductsStoredProcedureFromAppSetting/function.json similarity index 100% rename from samples/samples-csx/InputBindingSamples/GetProductsStoredProcedureFromAppSetting/function.json rename to samples/samples-csx/GetProductsStoredProcedureFromAppSetting/function.json diff --git a/samples/samples-csx/GetProductsStoredProcedureFromAppSetting/run.csx b/samples/samples-csx/GetProductsStoredProcedureFromAppSetting/run.csx new file mode 100644 index 000000000..bac16e698 --- /dev/null +++ b/samples/samples-csx/GetProductsStoredProcedureFromAppSetting/run.csx @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +#load "../Common/product.csx" +#r "Newtonsoft.Json" + +using System.Net; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Primitives; +using Newtonsoft.Json; +using System.Collections.Generic; + +public static IActionResult Run(HttpRequest req, ILogger log, IEnumerable products) +{ + return new OkObjectResult(products); +} diff --git a/samples/samples-csx/InputBindingSamples/.vscode/extensions.json b/samples/samples-csx/InputBindingSamples/.vscode/extensions.json deleted file mode 100644 index dde673dcd..000000000 --- a/samples/samples-csx/InputBindingSamples/.vscode/extensions.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "recommendations": [ - "ms-azuretools.vscode-azurefunctions" - ] -} \ No newline at end of file diff --git a/samples/samples-csx/InputBindingSamples/GetProductsStoredProcedureFromAppSetting/run.csx b/samples/samples-csx/InputBindingSamples/GetProductsStoredProcedureFromAppSetting/run.csx deleted file mode 100644 index b00a86fcb..000000000 --- a/samples/samples-csx/InputBindingSamples/GetProductsStoredProcedureFromAppSetting/run.csx +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -#load "../../Common/product.csx" -#r "Newtonsoft.Json" - -using System.Net; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Primitives; -using Newtonsoft.Json; -using System.Collections.Generic; - -public static IActionResult Run(HttpRequest req, ILogger log, IEnumerable products) -{ - log.LogInformation("C# HTTP trigger function processed a request."); - return new OkObjectResult(products); -} diff --git a/samples/samples-csx/OutputBindingSamples/.vscode/extensions.json b/samples/samples-csx/OutputBindingSamples/.vscode/extensions.json deleted file mode 100644 index dde673dcd..000000000 --- a/samples/samples-csx/OutputBindingSamples/.vscode/extensions.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "recommendations": [ - "ms-azuretools.vscode-azurefunctions" - ] -} \ No newline at end of file diff --git a/samples/samples-csx/OutputBindingSamples/AddProduct/run.csx b/samples/samples-csx/OutputBindingSamples/AddProduct/run.csx deleted file mode 100644 index 95e2adaad..000000000 --- a/samples/samples-csx/OutputBindingSamples/AddProduct/run.csx +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -#load "../../Common/product.csx" -#r "Newtonsoft.Json" -#r "Microsoft.Azure.WebJobs.Extensions.Sql" - -using System.Net; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Primitives; -using Newtonsoft.Json; - -public static Product Run(HttpRequest req, ILogger log, [Sql("dbo.Products", "SqlConnectionString")] out Product product) -{ - log.LogInformation("C# HTTP trigger function processed a request."); - - - string requestBody = new StreamReader(req.Body).ReadToEnd(); - product = JsonConvert.DeserializeObject(requestBody); - - string responseMessage = string.IsNullOrEmpty(product.Name) - ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response." - : $"Hello, {product.Name}. This HTTP triggered function executed successfully."; - - return product; -} \ No newline at end of file diff --git a/samples/samples-csx/OutputBindingSamples/AddProductParams/run.csx b/samples/samples-csx/OutputBindingSamples/AddProductParams/run.csx deleted file mode 100644 index 32246f2fb..000000000 --- a/samples/samples-csx/OutputBindingSamples/AddProductParams/run.csx +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -#load "../../Common/product.csx" -#r "Newtonsoft.Json" -#r "Microsoft.Azure.WebJobs.Extensions.Sql" - -using System.Net; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Primitives; -using Newtonsoft.Json; - -public static Product Run(HttpRequest req, ILogger log, [Sql("dbo.Products", "SqlConnectionString")] out Product product) -{ - log.LogInformation("C# HTTP trigger function processed a request."); - - product = new Product - { - Name = req.Query["name"], - ProductId = int.Parse(req.Query["productId"]), - Cost = int.Parse(req.Query["cost"]) - }; - - string responseMessage = string.IsNullOrEmpty(product.Name) - ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response." - : $"Hello, {product.Name}. This HTTP triggered function executed successfully."; - - return product; -} \ No newline at end of file diff --git a/samples/samples-csx/OutputBindingSamples/AddProductWithDefaultPK/run.csx b/samples/samples-csx/OutputBindingSamples/AddProductWithDefaultPK/run.csx deleted file mode 100644 index 01c0d3aad..000000000 --- a/samples/samples-csx/OutputBindingSamples/AddProductWithDefaultPK/run.csx +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -#load "../../Common/product.csx" -#r "Newtonsoft.Json" -#r "Microsoft.Azure.WebJobs.Extensions.Sql" - -using System.Net; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Primitives; -using Newtonsoft.Json; - -public static ProductWithDefaultPK Run(HttpRequest req, ILogger log, [Sql("dbo.ProductsWithDefaultPK", "SqlConnectionString")] out ProductWithDefaultPK product) -{ - log.LogInformation("C# HTTP trigger function processed a request."); - - - string requestBody = new StreamReader(req.Body).ReadToEnd(); - product = JsonConvert.DeserializeObject(requestBody); - - string responseMessage = string.IsNullOrEmpty(product.Name) - ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response." - : $"Hello, {product.Name}. This HTTP triggered function executed successfully."; - - return product; -} \ No newline at end of file diff --git a/samples/samples-csx/OutputBindingSamples/AddProductWithMultiplePrimaryColumnsAndIdentity/run.csx b/samples/samples-csx/OutputBindingSamples/AddProductWithMultiplePrimaryColumnsAndIdentity/run.csx deleted file mode 100644 index 41f076f45..000000000 --- a/samples/samples-csx/OutputBindingSamples/AddProductWithMultiplePrimaryColumnsAndIdentity/run.csx +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -#load "../../Common/product.csx" -#r "Newtonsoft.Json" -#r "Microsoft.Azure.WebJobs.Extensions.Sql" - -using System.Net; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Primitives; -using Newtonsoft.Json; - -public static MultiplePrimaryKeyProductWithoutId Run(HttpRequest req, ILogger log, [Sql("dbo.ProductsWithMultiplePrimaryColumnsAndIdentity", "SqlConnectionString")] out MultiplePrimaryKeyProductWithoutId product) -{ - log.LogInformation("C# HTTP trigger function processed a request."); - - product = product = new MultiplePrimaryKeyProductWithoutId - { - ExternalId = int.Parse(req.Query["externalId"]), - Name = req.Query["name"], - Cost = int.Parse(req.Query["cost"]) - }; - - string responseMessage = string.IsNullOrEmpty(product.Name) - ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response." - : $"Hello, {product.Name}. This HTTP triggered function executed successfully."; - - return product; -} \ No newline at end of file diff --git a/samples/samples-csx/OutputBindingSamples/AddProductsArray/run.csx b/samples/samples-csx/OutputBindingSamples/AddProductsArray/run.csx deleted file mode 100644 index 96a0120ac..000000000 --- a/samples/samples-csx/OutputBindingSamples/AddProductsArray/run.csx +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -#load "../../Common/product.csx" -#r "Newtonsoft.Json" -#r "Microsoft.Azure.WebJobs.Extensions.Sql" - -using System.Net; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Primitives; -using Newtonsoft.Json; - -public static Product[] Run(HttpRequest req, ILogger log, [Sql("dbo.Products", "SqlConnectionString")] out Product[] products) -{ - log.LogInformation("C# HTTP trigger function processed a request."); - - - string requestBody = new StreamReader(req.Body).ReadToEnd(); - products = JsonConvert.DeserializeObject(requestBody); - - string responseMessage = products.Length > 0 - ? "This HTTP triggered function executed successfully." - : "No data passed, Please pass the objects to upsert in the request body."; - - return products; -} \ No newline at end of file diff --git a/samples/samples-csx/OutputBindingSamples/host.json b/samples/samples-csx/OutputBindingSamples/host.json deleted file mode 100644 index b402e0789..000000000 --- a/samples/samples-csx/OutputBindingSamples/host.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "version": "2.0", - "logging": { - "applicationInsights": { - "samplingSettings": { - "isEnabled": true, - "excludedTypes": "Request" - } - }, - "logLevel": { - "default": "Trace" - } - }, - "extensionBundle": { - "id": "Microsoft.Azure.Functions.ExtensionBundle.Preview", - "version": "[4.*, 5.0.0)" - } -} diff --git a/samples/samples-csx/OutputBindingSamples/QueueTriggerProducts/function.json b/samples/samples-csx/QueueTriggerProducts/function.json similarity index 100% rename from samples/samples-csx/OutputBindingSamples/QueueTriggerProducts/function.json rename to samples/samples-csx/QueueTriggerProducts/function.json diff --git a/samples/samples-csx/OutputBindingSamples/QueueTriggerProducts/run.csx b/samples/samples-csx/QueueTriggerProducts/run.csx similarity index 75% rename from samples/samples-csx/OutputBindingSamples/QueueTriggerProducts/run.csx rename to samples/samples-csx/QueueTriggerProducts/run.csx index 42f7f0ee3..a2be84e50 100644 --- a/samples/samples-csx/OutputBindingSamples/QueueTriggerProducts/run.csx +++ b/samples/samples-csx/QueueTriggerProducts/run.csx @@ -1,14 +1,12 @@ -#load "../../Common/product.csx" +#load "../Common/product.csx" #r "Newtonsoft.Json" -#r "Microsoft.Azure.WebJobs.Extensions.Sql" using System; using System.Collections.Generic; using System.Diagnostics; using Newtonsoft.Json; -public static void Run(string queueMessage, ILogger log, - [Sql("[dbo].[Products]", "SqlConnectionString")] ICollector products) +public static void Run(string queueMessage, ILogger log, ICollector products) { int totalUpserts = 100; log.LogInformation($"[QueueTrigger]: {DateTime.Now} starting execution {queueMessage}. Rows to generate={totalUpserts}."); diff --git a/samples/samples-csx/OutputBindingSamples/TimerTriggerProducts/function.json b/samples/samples-csx/TimerTriggerProducts/function.json similarity index 100% rename from samples/samples-csx/OutputBindingSamples/TimerTriggerProducts/function.json rename to samples/samples-csx/TimerTriggerProducts/function.json diff --git a/samples/samples-csx/OutputBindingSamples/TimerTriggerProducts/run.csx b/samples/samples-csx/TimerTriggerProducts/run.csx similarity index 82% rename from samples/samples-csx/OutputBindingSamples/TimerTriggerProducts/run.csx rename to samples/samples-csx/TimerTriggerProducts/run.csx index 4f040acf3..c8c17d682 100644 --- a/samples/samples-csx/OutputBindingSamples/TimerTriggerProducts/run.csx +++ b/samples/samples-csx/TimerTriggerProducts/run.csx @@ -1,4 +1,4 @@ -#load "../../Common/product.csx" +#load "../Common/product.csx" #r "Newtonsoft.Json" #r "Microsoft.Azure.WebJobs.Extensions.Sql" @@ -8,8 +8,7 @@ using System.Diagnostics; using Newtonsoft.Json; private static int _executionNumber = 0; -public static void Run(TimerInfo myTimer, ILogger log, - [Sql("Products", "SqlConnectionString")] ICollector products) +public static void Run(TimerInfo myTimer, ILogger log, ICollector products) { int totalUpserts = 1000; log.LogInformation($"{DateTime.Now} starting execution #{_executionNumber}. Rows to generate={totalUpserts}."); diff --git a/samples/samples-csx/InputBindingSamples/host.json b/samples/samples-csx/host.json similarity index 100% rename from samples/samples-csx/InputBindingSamples/host.json rename to samples/samples-csx/host.json diff --git a/samples/samples-csx/InputBindingSamples/local.settings.json b/samples/samples-csx/local.settings.json similarity index 100% rename from samples/samples-csx/InputBindingSamples/local.settings.json rename to samples/samples-csx/local.settings.json diff --git a/test/Microsoft.Azure.WebJobs.Extensions.Sql.Tests.csproj b/test/Microsoft.Azure.WebJobs.Extensions.Sql.Tests.csproj index 1d5f2fa28..ef533f160 100644 --- a/test/Microsoft.Azure.WebJobs.Extensions.Sql.Tests.csproj +++ b/test/Microsoft.Azure.WebJobs.Extensions.Sql.Tests.csproj @@ -67,15 +67,10 @@ - <_CsxCopyItems Include="..\samples\samples-csx\InputBindingSamples\**\*.*" /> - <_CsxCopyItems Include="..\samples\samples-csx\OutputBindingSamples\**\*.*" /> + <_CsxCopyItems Include="..\samples\samples-csx\**\*.*" /> <_CsxCopyItems Include="Integration\test-csx\**\*.*" /> - - <_CommonCopyItems Include="..\samples\samples-csx\Common\**\*.*" /> - - - +