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

Clean csx samples #812

Merged
merged 7 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
27 changes: 27 additions & 0 deletions samples/samples-csx/AddProduct/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"bindings": [
{
"authLevel": "function",
"name": "req",
"direction": "in",
"type": "httpTrigger",
"methods": [
"post"
],
"route": "addproduct"
},
{
"name": "$return",
"type": "http",
"direction": "out"
},
{
"name": "product",
"type": "sql",
"direction": "out",
"commandText": "[dbo].[Products]",
"commandType": "Text",
"connectionStringSetting": "SqlConnectionString"
}
]
}
25 changes: 25 additions & 0 deletions samples/samples-csx/AddProduct/run.csx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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)
{
log.LogInformation("C# HTTP trigger function processed a request.");


string requestBody = new StreamReader(req.Body).ReadToEnd();
product = JsonConvert.DeserializeObject<Product>(requestBody);

string responseMessage = string.IsNullOrEmpty(product.Name)
Copy link
Contributor

@Charles-Gagnon Charles-Gagnon Apr 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this, it's not even used (same for all the other samples)

? "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;
}
27 changes: 27 additions & 0 deletions samples/samples-csx/AddProductParams/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"bindings": [
{
"authLevel": "function",
"name": "req",
"direction": "in",
"type": "httpTrigger",
"methods": [
"get"
],
"route": "addproduct-params"
},
{
"name": "$return",
"type": "http",
"direction": "out"
},
{
"name": "product",
"type": "sql",
"direction": "out",
"commandText": "[dbo].[Products]",
"connectionStringSetting": "SqlConnectionString"
}
],
"disabled": false
}
28 changes: 28 additions & 0 deletions samples/samples-csx/AddProductParams/run.csx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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)
{
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;
}
27 changes: 27 additions & 0 deletions samples/samples-csx/AddProductWithDefaultPK/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"bindings": [
{
"authLevel": "function",
"name": "req",
"direction": "in",
"type": "httpTrigger",
"methods": [
"post"
],
"route": "addproductwithdefaultpk"
},
{
"name": "$return",
"type": "http",
"direction": "out"
},
{
"name": "product",
"type": "sql",
"direction": "out",
"commandText": "[dbo].[ProductsWithDefaultPK]",
"connectionStringSetting": "SqlConnectionString"
}
],
"disabled": false
}
25 changes: 25 additions & 0 deletions samples/samples-csx/AddProductWithDefaultPK/run.csx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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)
{
log.LogInformation("C# HTTP trigger function processed a request.");


string requestBody = new StreamReader(req.Body).ReadToEnd();
product = JsonConvert.DeserializeObject<ProductWithDefaultPK>(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;
}
27 changes: 27 additions & 0 deletions samples/samples-csx/AddProductWithIdentityColumn/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"bindings": [
{
"authLevel": "function",
"name": "req",
"direction": "in",
"type": "httpTrigger",
"methods": [
"get"
],
"route": "addproductwithidentitycolumn"
},
{
"name": "$return",
"type": "http",
"direction": "out"
},
{
"name": "product",
"type": "sql",
"direction": "out",
"commandText": "[dbo].[ProductsWithIdentity]",
"connectionStringSetting": "SqlConnectionString"
}
],
"disabled": false
}
27 changes: 27 additions & 0 deletions samples/samples-csx/AddProductWithIdentityColumn/run.csx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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 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
@@ -0,0 +1,27 @@
{
"bindings": [
{
"authLevel": "function",
"name": "req",
"direction": "in",
"type": "httpTrigger",
"methods": [
"get"
],
"route": "addproductwithidentitycolumnincluded"
},
{
"name": "$return",
"type": "http",
"direction": "out"
},
{
"name": "product",
"type": "sql",
"direction": "out",
"commandText": "[dbo].[ProductsWithIdentity]",
"connectionStringSetting": "SqlConnectionString"
}
],
"disabled": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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 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,27 @@
{
"bindings": [
{
"authLevel": "function",
"name": "req",
"direction": "in",
"type": "httpTrigger",
"methods": [
"get"
],
"route": "addproductwithmultipleprimarycolumnsandidentity"
},
{
"name": "$return",
"type": "http",
"direction": "out"
},
{
"name": "product",
"type": "sql",
"direction": "out",
"commandText": "[dbo].[ProductsWithMultiplePrimaryColumnsAndIdentity]",
"connectionStringSetting": "SqlConnectionString"
}
],
"disabled": false
}
Loading