Skip to content

Commit a3c928d

Browse files
authored
Clean csx samples (#812)
* sql attribute not needed * simplify the folder structure for csx * add local.settings.json * rename folders in proj file * clean up logs and unused
1 parent bddbe09 commit a3c928d

File tree

51 files changed

+144
-251
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+144
-251
lines changed

docs/SetupGuide_DotnetCSharpScript.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,19 +130,19 @@ The database scripts used for the following samples can be found [here](https://
130130

131131
#### Query String
132132

133-
See the [GetProducts](https://github.com/Azure/azure-functions-sql-extension/blob/main/samples/samples-csx/InputBindingSamples/GetProducts) sample
133+
See the [GetProducts](https://github.com/Azure/azure-functions-sql-extension/blob/main/samples/samples-csx/GetProducts) sample
134134

135135
#### Empty Parameter Value
136136

137-
See the [GetProductsNameEmpty](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-csx/InputBindingSamples/GetProductsNameEmpty) sample
137+
See the [GetProductsNameEmpty](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-csx/GetProductsNameEmpty) sample
138138

139139
#### Null Parameter Value
140140

141-
See the [GetProductsNameNull](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-csx/InputBindingSamples/GetProductsNameNull) sample
141+
See the [GetProductsNameNull](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-csx/GetProductsNameNull) sample
142142

143143
#### Stored Procedure
144144

145-
See the [GetProductsStoredProcedure](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-csx/InputBindingSamples/GetProductsStoredProcedure) sample
145+
See the [GetProductsStoredProcedure](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-csx/GetProductsStoredProcedure) sample
146146

147147
## Output Binding
148148

@@ -172,14 +172,13 @@ Note: This tutorial requires that a SQL database is setup as shown in [Create a
172172
```csharp
173173
#load "employee.csx"
174174
#r "Newtonsoft.Json"
175-
#r "Microsoft.Azure.WebJobs.Extensions.Sql"
176175
177176
using System.Net;
178177
using Microsoft.AspNetCore.Mvc;
179178
using Microsoft.Extensions.Primitives;
180179
using Newtonsoft.Json;
181180
182-
public static Product Run(HttpRequest req, ILogger log, [Sql("dbo.Employees", "SqlConnectionString")] out Employee employee)
181+
public static Product Run(HttpRequest req, ILogger log, out Employee employee)
183182
{
184183
log.LogInformation("CSX HTTP trigger function processed a request.");
185184
@@ -218,12 +217,12 @@ Note: This tutorial requires that a SQL database is setup as shown in [Create a
218217

219218
#### Array
220219

221-
See the [AddProductsArray](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-csx/OutputBindingSamples/AddProductsArray) sample
220+
See the [AddProductsArray](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-csx/AddProductsArray) sample
222221

223222
#### Single Row
224223

225-
See the [AddProduct](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-csx/OutputBindingSamples/AddProduct) sample
224+
See the [AddProduct](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-csx/AddProduct) sample
226225

227226
### Sample with multiple Bindings
228227

229-
See the [GetAndAddProducts](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-csx/InputBindingSamples/GetAndAddProducts) sample
228+
See the [GetAndAddProducts](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-csx/GetAndAddProducts) sample

samples/samples-csx/OutputBindingSamples/AddProduct/function.json renamed to samples/samples-csx/AddProduct/function.json

File renamed without changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
#load "../Common/product.csx"
5+
#r "Newtonsoft.Json"
6+
7+
using System.Net;
8+
using Microsoft.AspNetCore.Mvc;
9+
using Microsoft.Extensions.Primitives;
10+
using Newtonsoft.Json;
11+
12+
public static Product Run(HttpRequest req, ILogger log, out Product product)
13+
{
14+
string requestBody = new StreamReader(req.Body).ReadToEnd();
15+
product = JsonConvert.DeserializeObject<Product>(requestBody);
16+
17+
return product;
18+
}

samples/samples-csx/OutputBindingSamples/AddProductParams/function.json renamed to samples/samples-csx/AddProductParams/function.json

File renamed without changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
#load "../Common/product.csx"
5+
#r "Newtonsoft.Json"
6+
7+
using System.Net;
8+
using Microsoft.AspNetCore.Mvc;
9+
using Microsoft.Extensions.Primitives;
10+
using Newtonsoft.Json;
11+
12+
public static Product Run(HttpRequest req, ILogger log, out Product product)
13+
{
14+
product = new Product
15+
{
16+
Name = req.Query["name"],
17+
ProductId = int.Parse(req.Query["productId"]),
18+
Cost = int.Parse(req.Query["cost"])
19+
};
20+
21+
return product;
22+
}

samples/samples-csx/OutputBindingSamples/AddProductWithDefaultPK/function.json renamed to samples/samples-csx/AddProductWithDefaultPK/function.json

File renamed without changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
#load "../Common/product.csx"
5+
#r "Newtonsoft.Json"
6+
7+
using System.Net;
8+
using Microsoft.AspNetCore.Mvc;
9+
using Microsoft.Extensions.Primitives;
10+
using Newtonsoft.Json;
11+
12+
public static ProductWithDefaultPK Run(HttpRequest req, ILogger log, out ProductWithDefaultPK product)
13+
{
14+
string requestBody = new StreamReader(req.Body).ReadToEnd();
15+
product = JsonConvert.DeserializeObject<ProductWithDefaultPK>(requestBody);
16+
17+
return product;
18+
}

samples/samples-csx/OutputBindingSamples/AddProductWithIdentityColumn/function.json renamed to samples/samples-csx/AddProductWithIdentityColumn/function.json

File renamed without changes.

samples/samples-csx/OutputBindingSamples/AddProductWithIdentityColumn/run.csx renamed to samples/samples-csx/AddProductWithIdentityColumn/run.csx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4-
#load "../../Common/product.csx"
4+
#load "../Common/product.csx"
55
#r "Newtonsoft.Json"
6-
#r "Microsoft.Azure.WebJobs.Extensions.Sql"
76

87
using System.Net;
98
using Microsoft.AspNetCore.Mvc;
109
using Microsoft.Extensions.Primitives;
1110
using Newtonsoft.Json;
1211

13-
public static ProductWithoutId Run(HttpRequest req, ILogger log, [Sql("dbo.Products", "SqlConnectionString")] out ProductWithoutId product)
12+
public static ProductWithoutId Run(HttpRequest req, ILogger log, out ProductWithoutId product)
1413
{
15-
log.LogInformation("C# HTTP trigger function processed a request.");
16-
1714
product = new ProductWithoutId
1815
{
1916
Name = req.Query["name"],
2017
Cost = int.Parse(req.Query["cost"])
2118
};
2219

23-
string responseMessage = string.IsNullOrEmpty(product.Name)
24-
? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
25-
: $"Hello, {product.Name}. This HTTP triggered function executed successfully.";
26-
2720
return product;
2821
}

samples/samples-csx/OutputBindingSamples/AddProductWithIdentityColumnIncluded/function.json renamed to samples/samples-csx/AddProductWithIdentityColumnIncluded/function.json

File renamed without changes.

0 commit comments

Comments
 (0)