Skip to content

Commit e2c1d03

Browse files
authored
Update SetupGuide_Javascript (#674)
* add js GetProductsNameNull sample & complete docs * update toc * move sample description to sample files.
1 parent b3733d5 commit e2c1d03

File tree

6 files changed

+57
-16
lines changed

6 files changed

+57
-16
lines changed

docs/SetupGuide_Javascript.md

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@
1313
- [Empty Parameter Value](#empty-parameter-value)
1414
- [Null Parameter Value](#null-parameter-value)
1515
- [Stored Procedure](#stored-procedure)
16-
- [IAsyncEnumerable](#iasyncenumerable)
1716
- [Output Binding](#output-binding)
1817
- [function.json Properties for Output Bindings](#functionjson-properties-for-output-bindings)
1918
- [Setup for Output Bindings](#setup-for-output-bindings)
2019
- [Samples for Output Bindings](#samples-for-output-bindings)
21-
- [ICollector\<T\>/IAsyncCollector\<T\>](#icollectortiasynccollectort)
2220
- [Array](#array)
2321
- [Single Row](#single-row)
2422
- [Trigger Binding](#trigger-binding)
@@ -110,23 +108,19 @@ Note: This tutorial requires that a SQL database is setup as shown in [Create a
110108

111109
#### Query String
112110

113-
_TODO_
111+
See the [GetProducts](https://github.com/Azure/azure-functions-sql-extension/blob/main/samples/samples-js/GetProducts) sample
114112

115113
#### Empty Parameter Value
116114

117-
_TODO_
115+
See the [GetProductsNameEmpty](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-js/GetProductsNameEmpty) sample
118116

119117
#### Null Parameter Value
120118

121-
_TODO_
119+
See the [GetProductsNameNull](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-js/GetProductsNameNull) sample
122120

123121
#### Stored Procedure
124122

125-
_TODO_
126-
127-
#### IAsyncEnumerable
128-
129-
_TODO_
123+
See the [GetProductsStoredProcedure](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-js/GetProductsStoredProcedure) sample
130124

131125
## Output Binding
132126

@@ -200,17 +194,13 @@ Note: This tutorial requires that a SQL database is setup as shown in [Create a
200194

201195
### Samples for Output Bindings
202196

203-
#### ICollector&lt;T&gt;/IAsyncCollector&lt;T&gt;
204-
205-
_TODO_
206-
207197
#### Array
208198

209-
_TODO_
199+
See the [AddProductsArray](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-js/AddProductsArray) sample
210200

211201
#### Single Row
212202

213-
_TODO_
203+
See the [AddProduct](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-js/AddProduct) sample
214204

215205
## Trigger Binding
216206

samples/samples-js/GetProducts/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
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+
// The input binding executes the `select * from Products where Cost = @Cost` query, returning the result as json object in the body.
5+
// The *parameters* argument passes the `{cost}` specified in the URL that triggers the function,
6+
// `getproducts/{cost}`, as the value of the `@Cost` parameter in the query.
7+
// *commandType* is set to `Text`, since the constructor argument of the binding is a raw query.
48
module.exports = async function (context, req, products) {
59
context.log('JavaScript HTTP trigger function processed a request.');
610
context.log(JSON.stringify(products));

samples/samples-js/GetProductsNameEmpty/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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+
// The parameter value of the `@Name` parameter is an empty string in the parameters arguments.
45
module.exports = async function (context, req, products) {
56
context.log('JavaScript HTTP trigger function processed a request.');
67
context.log(JSON.stringify(products));
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"bindings": [
3+
{
4+
"authLevel": "function",
5+
"name": "req",
6+
"type": "httpTrigger",
7+
"direction": "in",
8+
"methods": [
9+
"get"
10+
],
11+
"route":"getproducts-namenull/{name}"
12+
},
13+
{
14+
"name": "$return",
15+
"type": "http",
16+
"direction": "out"
17+
},
18+
{
19+
"name": "products",
20+
"type": "sql",
21+
"direction": "in",
22+
"commandText": "if @Name is null select * from Products where Name is null else select * from Products where @Name = name",
23+
"commandType": "Text",
24+
"parameters": "@Name={name}",
25+
"connectionStringSetting": "SqlConnectionString"
26+
}
27+
],
28+
"disabled": false
29+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
// If the `{name}` specified in the `getproducts-namenull/{name}` URL is "null",
5+
// the query returns all rows for which the Name column is `NULL`. Otherwise, it returns
6+
// all rows for which the value of the Name column matches the string passed in `{name}`
7+
module.exports = async function (context, req, products) {
8+
context.log('JavaScript HTTP trigger function processed a request.');
9+
context.log(JSON.stringify(products));
10+
return {
11+
status: 200,
12+
body: products
13+
};
14+
}

samples/samples-js/GetProductsStoredProcedure/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
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+
// `SelectsProductCost` is the name of a procedure stored in the user's database.
5+
// In this case, *CommandType* is `StoredProcedure`. The parameter value of the `@Cost` parameter in the
6+
// procedure is once again the `{cost}` specified in the `getproducts-storedprocedure/{cost}` URL.
47
module.exports = async function (context, req, products) {
58
context.log('JavaScript HTTP trigger function processed a request.');
69
context.log(JSON.stringify(products));

0 commit comments

Comments
 (0)