Skip to content

Commit 73728ab

Browse files
committed
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 0a183fa commit 73728ab

File tree

51 files changed

+144
-258
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
-258
lines changed

docs/SetupGuide_DotnetCSharpScript.md

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
- [Array](#array)
2222
- [Single Row](#single-row)
2323
- [Sample with multiple Bindings](#sample-with-multiple-bindings)
24-
- [Trigger Binding](#trigger-binding)
2524

2625
## CSharp Scripting
2726

@@ -131,19 +130,19 @@ The database scripts used for the following samples can be found [here](https://
131130

132131
#### Query String
133132

134-
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
135134

136135
#### Empty Parameter Value
137136

138-
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
139138

140139
#### Null Parameter Value
141140

142-
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
143142

144143
#### Stored Procedure
145144

146-
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
147146

148147
## Output Binding
149148

@@ -173,14 +172,13 @@ Note: This tutorial requires that a SQL database is setup as shown in [Create a
173172
```csharp
174173
#load "employee.csx"
175174
#r "Newtonsoft.Json"
176-
#r "Microsoft.Azure.WebJobs.Extensions.Sql"
177175
178176
using System.Net;
179177
using Microsoft.AspNetCore.Mvc;
180178
using Microsoft.Extensions.Primitives;
181179
using Newtonsoft.Json;
182180
183-
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)
184182
{
185183
log.LogInformation("CSX HTTP trigger function processed a request.");
186184
@@ -219,17 +217,12 @@ Note: This tutorial requires that a SQL database is setup as shown in [Create a
219217

220218
#### Array
221219

222-
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
223221

224222
#### Single Row
225223

226-
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
227225

228226
### Sample with multiple Bindings
229227

230-
See the [GetAndAddProducts](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-csx/InputBindingSamples/GetAndAddProducts) sample
231-
232-
233-
## Trigger Binding
234-
235-
> Trigger binding support is only available for in-proc C# functions at present.
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)