Skip to content

Commit 9a12dc3

Browse files
Cleanup docs (#159)
* Cleanup docs * Fix links
1 parent d5ea19b commit 9a12dc3

File tree

2 files changed

+76
-98
lines changed

2 files changed

+76
-98
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,12 @@ This project has adopted the Microsoft Open Source Code of Conduct. For more inf
1212

1313
### SQL Setup
1414

15-
This requires already having a SQL database. If you need to create a SQL database, we recommend one of 2 options:
16-
- [Local SQL Server running in a Docker container](https://docs.microsoft.com/sql/linux/quickstart-install-connect-docker)
17-
- [Azure SQL Database](#Create-Azure-SQL-Database).
18-
19-
A primary key must be set in your SQL table before using the bindings. To do this, run the below SQL commands in the SQL query editor. Note that this step needs to only be done once. If this has already been done, you can safely proceed to [Set Up Development Environment](#set-up-development-environment).
20-
21-
1. Ensure there are no NULL values in the primary key column. The primary key will usually be an ID column.
22-
23-
```sql
24-
ALTER TABLE [TableName] ALTER COLUMN [PrimaryKeyColumnName] int NOT NULL
25-
```
26-
27-
2. Set primary key column.
28-
29-
```sql
30-
ALTER TABLE [TableName] ADD CONSTRAINT PKey PRIMARY KEY CLUSTERED ([PrimaryKeyColumn]);
31-
```
32-
33-
3. Congrats on setting up your database! Now continue to set up your local environment and complete the quick start.
15+
In order to test changes it is suggested that you have a SQL server set up to connect to and run queries against. Instructions to set this up can be found in the [Quick Start Guide](./README.md#quick-start)
3416

3517
### Set Up Development Environment
3618

3719
1. [Install VS Code](https://code.visualstudio.com/Download)
38-
20+
3921
2. Clone repo and open in VS Code:
4022

4123
```bash
@@ -46,19 +28,6 @@ code .
4628
3. Install extensions when prompted after VS Code opens
4729
- Note: This includes the Azure Functions, C#, and editorconfig extensions
4830

49-
4. Get your SqlConnectionString.
50-
51-
If you provisioned an Azure SQL Database, your connection string can be found in your SQL database resource by going to the left blade and clicking 'Connection strings'. Copy the Connection String.
52-
53-
- (*Note: when pasting in the connection string, you will need to replace part of the connection string where it says '{your_password}' with your Azure SQL Server password*)
54-
55-
If your database wasn't provisioned in Azure, please follow documentation [here](https://docs.microsoft.com/sql/connect/homepage-sql-connection-programming), if you're unfamliar with how to construct a connection string.
56-
57-
5. In 'local.settings.json' in 'Values', verify you have the below. If not, add the below and replace "Your Connection String" with the your connection string from the previous step:
31+
4. Configure the Function App located in the [samples](./samples) folder by following the instructions [here](./README.md#configure-function-app)
5832

59-
```json
60-
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
61-
"AzureWebJobsDashboard": "UseDevelopmentStorage=true",
62-
"SqlConnectionString": "<Your Connection String>"
63-
```
64-
6. Press F5 to run SQL bindings samples that are included in this repo.
33+
5. Press F5 to run SQL bindings samples that are included in this repo. The output window should display startup information as well as the function endpoints that were started.

README.md

Lines changed: 72 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
This repository contains the Azure SQL binding for Azure Functions extension code as well as a quick start tutorial and samples illustrating how to use the binding in different ways. A high level explanation of the bindings is provided below. Additional information for each is in their respective sample sections.
88

9-
- **input binding**: takes a SQL query to run and returns the output of the query in the function.
10-
- **output binding**: takes a list of rows and upserts them into the user table (i.e. If a row doesn't already exist, it is added. If it does, it is updated).
9+
- **Input Binding**: takes a SQL query to run and returns the output of the query in the function.
10+
- **Output Binding**: takes a list of rows and upserts them into the user table (i.e. If a row doesn't already exist, it is added. If it does, it is updated).
1111

1212
Further information on the Azure SQL binding for Azure Functions is also available in the [Azure Functions docs](https://docs.microsoft.com/azure/azure-functions/functions-bindings-azure-sql).
1313

@@ -17,10 +17,13 @@ Further information on the Azure SQL binding for Azure Functions is also availab
1717
- [Introduction](#introduction)
1818
- [Table of Contents](#table-of-contents)
1919
- [Quick Start](#quick-start)
20+
- [Create a SQL Server](#create-a-sql-server)
21+
- [Docker container](#docker-container)
22+
- [Azure SQL Database](#azure-sql-database)
2023
- [SQL Setup](#sql-setup)
21-
- [Set Up Local .NET Function App](#set-up-local-net-function-app)
24+
- [Create .NET Function App](#create-net-function-app)
25+
- [Configure Function App](#configure-function-app)
2226
- [Tutorials](#tutorials)
23-
- [Create Azure SQL Database](#create-azure-sql-database)
2427
- [Input Binding Tutorial](#input-binding-tutorial)
2528
- [Output Binding Tutorial](#output-binding-tutorial)
2629
- [More Samples](#more-samples)
@@ -39,61 +42,105 @@ Further information on the Azure SQL binding for Azure Functions is also availab
3942

4043
## Quick Start
4144

45+
### Create a SQL Server
46+
47+
First you'll need a SQL server for the bindings to connect to. If you already have your own set up then you can skip this step, otherwise pick from one of the below options.
48+
49+
#### Docker container
50+
51+
SQL Server on Docker makes it easy to set up and connect to a locally hosted instance of SQL Server. Instructions for getting started can be found [here](https://docs.microsoft.com/sql/linux/sql-server-linux-docker-container-deployment).
52+
53+
#### Azure SQL Database
54+
55+
Azure SQL Database is a fully managed platform as a service (PaaS) database engine that runs the latest stable version of the Microsoft SQL Server database engine. Instructions for getting started can be found [here](https://docs.microsoft.com/azure/azure-sql/database/single-database-create-quickstart).
56+
57+
4258
### SQL Setup
4359

44-
This requires already having a SQL database. If you need to create a SQL database, please refer to [Create Azure SQL Database](#Create-Azure-SQL-Database) in the tutorials section.
60+
Next you'll configure your SQL Server database for use with Azure SQL binding for Azure Functions.
4561

46-
A primary key must be set in your SQL table before using the bindings. To do this, run the below SQL commands in the SQL query editor.
62+
This will require connecting to and running queries - you can use [Azure Data Studio](https://docs.microsoft.com/sql/azure-data-studio/download-azure-data-studio) or the [MSSQL for VS Code Extension](https://docs.microsoft.com/sql/tools/visual-studio-code/sql-server-develop-use-vscode) to do this.
4763

48-
1. Ensure there are no NULL values in the primary key column. The primary key will usually be an ID column.
64+
1. First you'll need a table to run queries against. If you already have one you'd like to use then you can skip this step.
4965

50-
```sql
51-
ALTER TABLE ['your table name'] alter column ['column to be primary key'int NOT NULL
52-
```
66+
Otherwise connect to your database and run the following query to create a simple table to start with.
67+
68+
```sql
69+
CREATE TABLE Employees (
70+
    EmployeeId int,
71+
    FirstName varchar(255),
72+
    LastName varchar(255),
73+
    Company varchar(255),
74+
    Team varchar(255)
75+
);
76+
```
5377

54-
1. Set primary key column.
78+
2. Next a primary key must be set in your SQL table before using the bindings. To do this, run the queries below, replacing the placeholder values for your table and column.
79+
80+
```sql
81+
ALTER TABLE ['{table_name}'] ALTER COLUMN ['{primary_key_column_name}'int NOT NULL
82+
83+
ALTER TABLE ['{table_name}'] ADD CONSTRAINT PKey PRIMARY KEY CLUSTERED (['{primary_key_column_name}']);
84+
```
5585

56-
```sql
57-
ALTER TABLE ['your table name'] ADD CONSTRAINT PKey PRIMARY KEY CLUSTERED (['column to be primary key']);
58-
```
5986

60-
1. Congrats on setting up your database! Now continue to set up your local environment and complete the quick start.
87+
### Create .NET Function App
6188

62-
### Set Up Local .NET Function App
89+
Now you will need a .NET Function App to add the binding to. If you have one created already you can skip this step.
6390

64-
These steps can be done in the Terminal/CLI or with PowerShell. Completing this section will allow you to begin using the Azure SQL binding.
91+
These steps can be done in the Terminal/CLI or with PowerShell.
6592

6693
1. Install [Azure Functions Core Tools](https://docs.microsoft.com/azure/azure-functions/functions-run-local)
6794

68-
1. Create a function app.
95+
2. Create a function app.
6996

7097
```bash
7198
mkdir MyApp
7299
cd MyApp
73100
func init --worker-runtime dotnet
74101
```
75102

103+
**Note**: Other languages are not supported at this time
104+
76105
1. Install the extension.
77106

78107
```powershell
79108
dotnet add package Microsoft.Azure.WebJobs.Extensions.Sql --prerelease
80109
```
81110

111+
### Configure Function App
112+
113+
Once you have your Function App you need to configure it for use with Azure SQL bindings for Azure Functions.
114+
82115
1. Ensure you have Azure Storage Emulator running. This is specific to the sample functions in this repository with a non-HTTP trigger. For information on the Azure Storage Emulator, refer to the docs on its use in [functions local development](https://docs.microsoft.com/azure/azure-functions/functions-app-settings#azurewebjobsstorage) and [installation](https://docs.microsoft.com/azure/storage/common/storage-use-emulator#get-the-storage-emulator).
83116

84-
1. Get your SqlConnectionString. Your connection string can be found in your SQL database resource by going to the left blade and clicking 'Connection strings'. Copy the Connection String.
117+
1. Get your SQL connection string
118+
119+
<details>
120+
<summary>Local SQL Server</summary>
121+
- Use this connection string, replacing the placeholder values for the database and password.</br>
122+
</br>
123+
<code>Server=localhost;Initial Catalog={db_name};Persist Security Info=False;User ID=sa;Password={your_password};</code>
124+
</details>
85125

86-
(*Note: when pasting in the connection string, you will need to replace part of the connection string where it says '{your_password}' with your Azure SQL Server password*)
126+
<details>
127+
<summary>Azure SQL Server</summary>
128+
- Browse to the SQL Database resource in the [Azure portal](https://ms.portal.azure.com/)</br>
129+
- In the left blade click on the <b>Connection Strings</b> tab</br>
130+
- Copy the <b>SQL Authentication</b> connection string</br>
131+
</br>
132+
(<i>Note: when pasting in the connection string, you will need to replace part of the connection string where it says '{your_password}' with your Azure SQL Server password</i>)
133+
</details>
87134

88-
1. In 'local.settings.json' in 'Values', verify you have the below. If not, add the below and replace "Your Connection String" with the your connection string from the previous step:
135+
1. Open the generated `local.settings.json` file and in the `Values` section verify you have the below. If not, add the below and replace `{connection_string}` with the your connection string from the previous step:
89136

90137
```json
91138
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
92139
"AzureWebJobsDashboard": "UseDevelopmentStorage=true",
93-
"SqlConnectionString": "<Your Connection String>"
140+
"SqlConnectionString": "{connection_string}"
94141
```
95142

96-
1. Verify your host.json looks like the below:
143+
1. Verify your `host.json` looks like the below:
97144

98145
```json
99146
{
@@ -113,47 +160,9 @@ These steps can be done in the Terminal/CLI or with PowerShell. Completing this
113160

114161
## Tutorials
115162

116-
### Create Azure SQL Database
117-
118-
We will create a simple Azure SQL Database. For additional reference on Azure SQL Databases, go [here](https://docs.microsoft.com/azure/azure-sql/database/single-database-create-quickstart?tabs=azure-portal).
119-
120-
- Create an Azure SQL Database
121-
- Make sure you have an Azure subscription. If you don't already have an Azure Subscription, go [here](https://azure.microsoft.com/free/search/?&OCID=AID2100131_SEM_XzK4bAAAAJBpCjfl:20200918000154:s&msclkid=f33d47a9a4ec1c1b6ced18cd9bd2923f&ef_id=XzK4bAAAAJBpCjfl:20200918000154:s&dclid=CKLQqbL28esCFUrBfgod4BIBMA).
122-
- Navigate to the [Azure portal](https://ms.portal.azure.com/)
123-
- Click 'Create a resource', then search the marketplace for 'SQL Database' and select it. Provide a 'Subscription', 'Resource Group', and 'Database name.' Under the 'Server' field, click 'Create New'
124-
<kbd>![alt text](/Images/dbSetup.png)</kbd>
125-
- Fill in the fields of the 'New server' panel. Make sure you know your 'Server admin login' and 'Password' as you will need them later. Click 'OK' at the bottom of the panel.
126-
- Click 'Review and Create' at the bottom of the page. Then press 'Create.' While you are waiting for your resource to be created, feel free to do the [Set Up Local .NET Function App](#Set-Up-Local-.NET-Function-App) step if you have not done so already and return here when completed.
127-
- Once created, navigate to the SQL Database resource. In the left panel, click 'Query editor'
128-
- Enter your Azure SQL login from when you created the SQL Database.
129-
- If an error pops up for not being able to open the server, copy the Client IP address in the second sentence of the error message, and click 'set server firewall' at the bottom
130-
- In the new window, click 'Add Client IP.' This will create an entry
131-
- In the section with Rule Name, Start IP, and End IP, paste the IP address you just copied into the Start and End IP fields for the entry created in the previous step.
132-
- Hit 'Save' in the top left and navigate back into the SQL Database login page.
133-
- Enter your login. You should now be in the Query editor view
134-
- Enter the below script and hit run to create a table. Once created, if you expand the Tables section by clicking the arrow, you should see a table
135-
136-
```sql
137-
CREATE TABLE Employees (
138-
    EmployeeId int,
139-
    FirstName varchar(255),
140-
    LastName varchar(255),
141-
    Company varchar(255),
142-
    Team varchar(255)
143-
);
144-
```
145-
146-
- Enter the blow script and hit run to create an entry in the table. Once created, if you right click your table name and click 'Select Top 1000 Rows', you'll be able to see your entry present.
147-
148-
```sql
149-
INSERT INTO [dbo].[Employees] values (1, 'Hello', 'World', 'Microsoft', 'Functions')
150-
```
151-
152-
- Congratulations! You have successfully created an Azure SQL Database! Make sure you complete [Quick Start](#Quick-Start) before continuing to the rest of the tutorial.
153-
154163
### Input Binding Tutorial
155164

156-
Note: This tutorial requires that the Azure SQL database is setup as shown in [Create Azure SQL Database](#Create-Azure-SQL-Database).
165+
Note: This tutorial requires that a SQL database is setup as shown in [Create a SQL Server](#Create-a-SQL-Server).
157166

158167
- Open your app that you created in 'Set Up Your Local Environment' in VSCode
159168
- Press 'F1' and search for 'Azure Functions: Create Function'
@@ -201,7 +210,7 @@ Note: This tutorial requires that the Azure SQL database is setup as shown in [C
201210
202211
### Output Binding Tutorial
203212
204-
Note: This tutorial requires that the Azure SQL database is setup as shown in [Create Azure SQL Database](#Create-Azure-SQL-Database), and that you have the 'Employee.cs' class from the [Input Binding Tutorial](#Input-Binding-Tutorial).
213+
Note: This tutorial requires that a SQL database is setup as shown in [Create a SQL Server](#Create-a-SQL-Server), and that you have the 'Employee.cs' class from the [Input Binding Tutorial](#Input-Binding-Tutorial).
205214
206215
- Open your app in VSCode
207216
- Press 'F1' and search for 'Azure Functions: Create Function'

0 commit comments

Comments
 (0)