Skip to content
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
17 changes: 8 additions & 9 deletions docs/SetupGuide_DotnetCSharpScript.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.");

Expand Down Expand Up @@ -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
18 changes: 18 additions & 0 deletions samples/samples-csx/AddProduct/run.csx
Original file line number Diff line number Diff line change
@@ -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<Product>(requestBody);

return product;
}
22 changes: 22 additions & 0 deletions samples/samples-csx/AddProductParams/run.csx
Original file line number Diff line number Diff line change
@@ -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;
}
18 changes: 18 additions & 0 deletions samples/samples-csx/AddProductWithDefaultPK/run.csx
Original file line number Diff line number Diff line change
@@ -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<ProductWithDefaultPK>(requestBody);

return product;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -1,29 +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"
#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"],
ProductId = string.IsNullOrEmpty(req.Query["productId"]) ? (int?)null : 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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
18 changes: 18 additions & 0 deletions samples/samples-csx/AddProductsArray/run.csx
Original file line number Diff line number Diff line change
@@ -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<Product[]>(requestBody);

return products;
}
Original file line number Diff line number Diff line change
@@ -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<Product> Run(HttpRequest req, ILogger log, [Sql("dbo.Products", "SqlConnectionString")] ICollector<Product> products)
public static ICollector<Product> Run(HttpRequest req, ILogger log, ICollector<Product> products)
{
log.LogInformation("C# HTTP trigger function processed a request.");

List<Product> newProducts = ProductUtilities.GetNewProducts(5000);
foreach (Product product in newProducts)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
// 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;
using System.Collections.Generic;

public static Product[] Run(HttpRequest req, ILogger log, IEnumerable<Product> products, [Sql("dbo.ProductsWithIdentity", "SqlConnectionString")] out Product[] productsWithIdentity)
public static Product[] Run(HttpRequest req, ILogger log, IEnumerable<Product> products, out Product[] productsWithIdentity)
{
log.LogInformation("C# HTTP trigger function processed a request.");
productsWithIdentity = products.ToArray<Product>();
return productsWithIdentity;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,6 +12,5 @@ using System.Collections.Generic;

public static IActionResult Run(HttpRequest req, ILogger log, IEnumerable<ProductName> products)
{
log.LogInformation("C# HTTP trigger function processed a request.");
return new OkObjectResult(products);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,6 +12,5 @@ using System.Collections.Generic;

public static IActionResult Run(HttpRequest req, ILogger log, IEnumerable<Product> products)
{
log.LogInformation("C# HTTP trigger function processed a request.");
return new OkObjectResult(products);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,6 +12,5 @@ using System.Collections.Generic;

public static IActionResult Run(HttpRequest req, ILogger log, IEnumerable<Product> products)
{
log.LogInformation("C# HTTP trigger function processed a request.");
return new OkObjectResult(products);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,6 +12,5 @@ using System.Collections.Generic;

public static IActionResult Run(HttpRequest req, ILogger log, IEnumerable<Product> products)
{
log.LogInformation("C# HTTP trigger function processed a request.");
return new OkObjectResult(products);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,6 +12,5 @@ using System.Collections.Generic;

public static IActionResult Run(HttpRequest req, ILogger log, IEnumerable<Product> products)
{
log.LogInformation("C# HTTP trigger function processed a request.");
return new OkObjectResult(products);
}
Loading