Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Azure-Samples/dab-adventureworks-lt
Turn AdventureWorksLT sample database into a REST and GraphQL service with Data API builder
https://github.com/Azure-Samples/dab-adventureworks-lt
adventureworks api graphql rest
Last synced: 3 months ago
JSON representation
Turn AdventureWorksLT sample database into a REST and GraphQL service with Data API builder
- Host: GitHub
- URL: https://github.com/Azure-Samples/dab-adventureworks-lt
- Owner: Azure-Samples
- License: mit
- Created: 2023-10-04T23:11:49.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-25T20:29:39.000Z (about 1 year ago)
- Last Synced: 2024-06-11T12:47:31.252Z (5 months ago)
- Topics: adventureworks, api, graphql, rest
- Language: Shell
- Homepage:
- Size: 31.3 KB
- Stars: 9
- Watchers: 6
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - Azure-Samples/dab-adventureworks-lt - Turn AdventureWorksLT sample database into a REST and GraphQL service with Data API builder (Shell)
README
---
page_type: sample
languages:
- csharp
- sql
- tsql
products:
- azure-app-service
- azure-sql-database
- sql-server
- azure-sql-managed-instance
- azure-sqlserver-vm
name: AdventureWorks LT Data API builder
description: Expose the sample database Adventure Works LT as a REST and GraphQL API via Data API builder
---# Data API builder: AdventureWorks LT
Expose the sample database Adventure Works LT as a REST and GraphQL API via Data API builder
## Create database
Create an Azure SQL database using the AdventureWorksLT sample database. You can follow the instructions in the following article: [Quickstart: Create a single database - Azure SQL Database](https://learn.microsoft.com/azure/azure-sql/database/single-database-create-quickstart?view=azuresql&tabs=azure-portal). Make sure to allow Azure Service to connect to the database, by selecting **Yes** for the **Allow Azure services to access server** option.
## Create user
[Connect to the created Azure SQL database](https://learn.microsoft.com/azure-data-studio/quickstart-sql-database?view=sql-server-ver16) and run the following script to create a user:
```sql
create user dab_adw_user with password = '2_we2KWE-1S!cca';
grant select on schema::SalesLT to dab_adw_user;
```## Deploy the Azure resources
In a Linux shell (using Linux, [WSL](https://learn.microsoft.com/windows/wsl/install) or the [Cloud Shell](https://azure.microsoft.com/get-started/azure-portal/cloud-shell/)) make sure you have [AZ CLI](https://learn.microsoft.com/cli/azure/) installed and then run the `azure-deploy.sh` script. If it is the first time you're running the script, it will create a `.env` file and then stop.
Fill the `.env` file with the required values and run the script again. The connection string for the Azure SQL database can be found in the Azure portal, in the Azure SQL database blade, under the **Connection strings** section. Make sure to use the created `dab_adw_user`. For example:
```
MSSQL='Server=.database.windows.net;Database=AdventureWorksLT;User ID=dab_adw_user;Password=2_we2KWE-1S!cca;'
```This will create the following resources:
- Resource Group
- Storage Account
- App Service Plan ([B1](https://azure.microsoft.com/en-us/pricing/details/app-service/linux/#pricing))
- Web AppData API builder will be executed as a Docker container in the Web App.
## Test the deployment
The deployment will pull the Docker image from `mcr.microsoft.com/azure-databases/data-api-builder:latest`. Please wait a couple of minutes before testing the API, to allow the Docker image to be pulled and the container to be started.
You can test if the everything is up and running by running thw following command:
```text
curl https:/.azurewebsites.net/
```and it should return the string "Healthy". If it doesn't, wait for a few seconds and try again, as the container may still be starting.
Once everything has been deployed, you can test the API by opening the following URL in a browser:
```text
http://.azurewebsites.net/swagger
```or, for GraphQL
```text
http://.azurewebsites.net/graphql
```## Additional Resources
To automatically expose all tables in the database, you can start from the `sql-to-dab-config.sql` sample scripts. Make sure to review the script and customize it to your needs. For example, you may want to rename and customize the relationships created from the `Address` entity to the `SalesOrderHeader` entity, to set a better name of the relationship based on the `ShipToAddressID` and `BillToAddressID` fields.