├── .devcontainer
├── .env
├── Dockerfile
├── devcontainer.json
├── docker-compose.yml
└── sql
│ ├── installSQLtools.sh
│ └── postCreateCommand.sh
├── .gitignore
├── .vscode
└── tasks.json
├── CODE_OF_CONDUCT.md
├── DAB-DevContainers-AzureSQL.png
├── LICENSE
├── README.md
├── SECURITY.md
├── SUPPORT.md
├── dab
├── .env
└── dab.config.json
├── database
└── Library
│ ├── Library.sqlproj
│ ├── Sequences
│ └── globalId.sql
│ ├── StoredProcedures
│ └── stp_get_all_cowritten_books_by_author.sql
│ ├── Tables
│ ├── authors.sql
│ ├── books.sql
│ └── books_authors.sql
│ ├── Views
│ └── vw_books_details.sql
│ ├── bin
│ └── Debug
│ │ ├── Library.dacpac
│ │ ├── Library.dll
│ │ └── Library.pdb
│ └── postDeployment.sql
└── scripts
├── dab_http_requests.sh
└── verifyDatabase.sql
/.devcontainer/.env:
--------------------------------------------------------------------------------
1 | SA_PASSWORD=P@ssw0rd!
--------------------------------------------------------------------------------
/.devcontainer/Dockerfile:
--------------------------------------------------------------------------------
1 | # [Choice] .NET version: 8.0-bookworm
2 | ARG VARIANT="8.0-bookworm"
3 | FROM mcr.microsoft.com/devcontainers/dotnet:1-${VARIANT}
4 |
5 | # Add .NET global tools path
6 | ENV PATH $PATH:/home/vscode/.dotnet:/home/vscode/.dotnet/tools
7 |
8 | # [Optional] Uncomment this section to install additional OS packages.
9 | RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
10 | && apt-get -y install --no-install-recommends software-properties-common
11 |
12 | # Install SQL Tools: SQLPackage and sqlcmd
13 | COPY sql/installSQLtools.sh installSQLtools.sh
14 | RUN bash ./installSQLtools.sh \
15 | && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts
16 |
17 | # Install Data API Builder for vscode user
18 | RUN su vscode -c "dotnet tool install --global Microsoft.DataApiBuilder" 2>&1
--------------------------------------------------------------------------------
/.devcontainer/devcontainer.json:
--------------------------------------------------------------------------------
1 | // For format details, see https://aka.ms/devcontainer.json.
2 | // For config options, see the README at: https://github.com/devcontainers/templates/tree/main/src/dotnet-mssql
3 | {
4 | "name": "Data API builder and Azure SQL Database",
5 | "dockerComposeFile": "docker-compose.yml",
6 | "service": "app",
7 | "workspaceFolder": "/workspace",
8 |
9 | // Configure tool-specific properties.
10 | "customizations": {
11 | // Configure properties specific to VS Code.
12 | "vscode": {
13 | // Set *default* container specific settings.json values on container create.
14 | "settings": {
15 | "mssql.connections": [
16 | {
17 | "server": "localhost,1433",
18 | "database": "master",
19 | "authenticationType": "SqlLogin",
20 | "user": "sa",
21 | "password": "${env:SA_PASSWORD}",
22 | "savePassword": true,
23 | "profileName": "LocalDev",
24 | "trustServerCertificate": true
25 | }
26 | ],
27 | "sqlDatabaseProjects.dotnetSDK Location": "/usr/share/dotnet/sdk/"
28 | },
29 | // Add the IDs of extensions you want installed when the container is created.
30 | "extensions": [
31 | "ms-dotnettools.csharp",
32 | "ms-mssql.mssql",
33 | "ms-vscode.vscode-node-azure-pack",
34 | "ms-azuretools.vscode-docker",
35 | "github.copilot",
36 | "github.codespaces"
37 | ]
38 | }
39 | },
40 |
41 | // Use 'forwardPorts' to make a list of ports inside the container available locally.
42 | "forwardPorts": [5000, 5001, 1433],
43 |
44 | // Post create commands to run after the container is created.
45 | "postCreateCommand": "bash .devcontainer/sql/postCreateCommand.sh 'database/Library/bin/Debug'",
46 |
47 | // Features to add to the dev container. More info: https://containers.dev/features.
48 | "features": {
49 | "ghcr.io/devcontainers/features/azure-cli:1": {
50 | "installBicep": true,
51 | "installUsingPython": true,
52 | "version": "latest"
53 | },
54 | "ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
55 | "version": "latest"
56 | },
57 | "ghcr.io/azure/azure-dev/azd:latest": {
58 | "version": "latest"
59 | }
60 | }
61 | // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
62 | // "remoteUser": "root"
63 | }
--------------------------------------------------------------------------------
/.devcontainer/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '3'
2 |
3 | services:
4 | app:
5 | build:
6 | context: .
7 | dockerfile: Dockerfile
8 | args:
9 | # Update 'VARIANT' to pick a version of .NET: 8.0-bookworm
10 | VARIANT: "8.0-bookworm"
11 |
12 | volumes:
13 | - ..:/workspace:cached
14 |
15 | # Overrides default command so things don't shut down after the process ends.
16 | command: sleep infinity
17 |
18 | # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
19 | network_mode: service:db
20 | # Uncomment the next line to use a non-root user for all processes.
21 | # user: vscode
22 |
23 | # Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
24 | # (Adding the "ports" property to this file will not forward from a Codespace.)
25 |
26 | db:
27 | image: mcr.microsoft.com/mssql/server:2022-latest
28 | hostname: SQL-Library
29 | container_name: SQL-Library
30 | restart: unless-stopped
31 | environment:
32 | ACCEPT_EULA: Y
33 | env_file:
34 | - .env
35 | deploy:
36 | resources:
37 | limits:
38 | cpus: '1'
39 | memory: 2048M
40 | # Add "forwardPorts": ["1433"] to **devcontainer.json** to forward MSSQL locally.
41 | # (Adding the "ports" property to this file will not forward from a Codespace.)
--------------------------------------------------------------------------------
/.devcontainer/sql/installSQLtools.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | echo "Installing Go-SQLCmd ..."
4 | curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc
5 | sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/prod.list)"
6 | sudo apt-get update
7 | sudo apt-get install sqlcmd
8 | echo "Go-SQLCmd installed."
9 |
10 | echo "Installing Sqlpackage ..."
11 | curl -sSL -o sqlpackage.zip "https://aka.ms/sqlpackage-linux"
12 | mkdir /opt/sqlpackage
13 | unzip sqlpackage.zip -d /opt/sqlpackage
14 | rm sqlpackage.zip
15 | chmod a+x /opt/sqlpackage/sqlpackage
16 | echo "Sqlpackage installed."
--------------------------------------------------------------------------------
/.devcontainer/sql/postCreateCommand.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Setting variables
4 | dacpac="false"
5 |
6 | # Load SA_PASSWORD from .env file
7 | export $(grep -v '^#' .devcontainer/.env | xargs)
8 | SApassword=$SA_PASSWORD
9 |
10 | # Parameters
11 | dacpath=$1
12 |
13 | echo "SELECT * FROM SYS.DATABASES" | dd of=testsqlconnection.sql
14 | for i in {1..30};
15 | do
16 | sqlcmd -S localhost -U sa -P $SApassword -d master -i testsqlconnection.sql > /dev/null
17 | if [ $? -eq 0 ]
18 | then
19 | echo "SQL server ready"
20 | break
21 | else
22 | echo "Not ready yet..."
23 | sleep 1
24 | fi
25 | done
26 | rm testsqlconnection.sql
27 |
28 | for f in $dacpath/*
29 | do
30 | if [ $f == $dacpath/*".dacpac" ]
31 | then
32 | dacpac="true"
33 | echo "Found dacpac $f"
34 | fi
35 | done
36 |
37 | if [ $dacpac == "true" ]
38 | then
39 | for f in $dacpath/*
40 | do
41 | if [ $f == $dacpath/*".dacpac" ]
42 | then
43 | dbname=$(basename $f ".dacpac")
44 | echo "Deploying dacpac $f"
45 | /opt/sqlpackage/sqlpackage /Action:Publish /SourceFile:$f /TargetServerName:localhost /TargetDatabaseName:$dbname /TargetUser:sa /TargetPassword:$SApassword /TargetTrustServerCertificate:True
46 | fi
47 | done
48 | fi
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.swp
2 | *.*~
3 | project.lock.json
4 | .DS_Store
5 | *.pyc
6 | nupkg/
7 |
8 | # User-specific files
9 | !/database/Library/bin/Debug/*
10 |
11 | # Visual Studio Code
12 | #.vscode/
13 |
14 | # Rider
15 | .idea/
16 |
17 | # Visual Studio
18 | .vs/
19 |
20 | # MonoDevelop
21 | .mono/
22 |
23 | # Fleet
24 | .fleet/
25 |
26 | # Code Rush
27 | .cr/
28 |
29 | # User-specific files
30 | *.suo
31 | *.user
32 | *.userosscache
33 | *.sln.docstates
34 |
35 | # Build results
36 | # [Dd]ebug/
37 | [Dd]ebugPublic/
38 | [Rr]elease/
39 | [Rr]eleases/
40 | x64/
41 | x86/
42 | build/
43 | bld/
44 | # [Bb]in/
45 | [Oo]bj/
46 | [Oo]ut/
47 | msbuild.log
48 | msbuild.err
49 | msbuild.wrn
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "label": "Execute SQL Query",
8 | "type": "shell",
9 | "command": "code",
10 | "args": [
11 | "--goto",
12 | "${workspaceFolder}/scripts/verifyDatabase.sql"
13 | ],
14 | "presentation": {
15 | "reveal": "always",
16 | "panel": "new"
17 | }
18 | },
19 | {
20 | "label": "Build SQL Database project",
21 | "type": "shell",
22 | "command": "dotnet build",
23 | "options": {
24 | "cwd": "${workspaceFolder}/database/Library"
25 | }
26 | },
27 | {
28 | "label": "Deploy SQL Database project",
29 | "type": "shell",
30 | "command": "bash",
31 | "args": [
32 | ".devcontainer/sql/postCreateCommand.sh",
33 | "database/Library/bin/Debug"
34 | ]
35 | },
36 | {
37 | "label": "Trust .NET HTTPS certificate for Data API builder",
38 | "type": "shell",
39 | "command": "dotnet dev-certs https --trust",
40 | "options": {
41 | "cwd": "${workspaceFolder}/dab"
42 | }
43 | },
44 | {
45 | "label": "Run Data API builder",
46 | "type": "shell",
47 | "command": "dab start --config=dab.config.json --no-https-redirect",
48 | "options": {
49 | "cwd": "${workspaceFolder}/dab"
50 | }
51 | },
52 | {
53 | "label": "Open Swagger UI",
54 | "type": "shell",
55 | "command": "xdg-open http://localhost:5000/swagger/index.html",
56 | "problemMatcher": []
57 | }
58 | ]
59 | }
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Microsoft Open Source Code of Conduct
2 |
3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
4 |
5 | Resources:
6 |
7 | - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
8 | - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
9 | - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns
10 |
--------------------------------------------------------------------------------
/DAB-DevContainers-AzureSQL.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/vscode-remote-try-dab/ffb077265d8c74721d5f36cb334ee231bb384fbc/DAB-DevContainers-AzureSQL.png
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Microsoft Corporation.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | page_type: sample
3 | languages:
4 | - sql
5 | - tsql
6 | - dockerfile
7 | - data-api-builder
8 | products:
9 | - azure
10 | - azure-sql-database
11 | urlFragment: devcontainer
12 | name: Sample devcontainer for Data API builder and Azure SQL Database
13 | description: Try out Data API builder (DAB) using a sample application within a devcontainer. This sample application is designed to connect to Azure SQL Database.
14 | ---
15 |
16 |
17 | # Try Out Development Containers: Data API builder & Azure SQL Database
18 |
19 | [](https://codespaces.new/microsoft/vscode-remote-try-dab/tree/main)
20 | [](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/microsoft/vscode-remote-try-dab/tree/main)
21 |
22 | A **development container** is a running [Docker](https://www.docker.com) container with a well-defined tool/runtime stack and its prerequisites. You can try out development containers with **[GitHub Codespaces](https://github.com/features/codespaces)** or **[Visual Studio Code Remote - Containers](https://aka.ms/vscode-remote/containers)**.
23 |
24 | This is a sample project that lets you try out either option in a few easy steps. We have a variety of other [vscode-remote-try-*](https://github.com/search?q=org%3Amicrosoft+vscode-remote-try-&type=Repositories) sample projects, too.
25 |
26 | > **Note:** If you already have a Codespace or dev container, you can jump to the [About this](#about-this-template) section.
27 |
28 | ## Setting up the development container
29 |
30 | ### GitHub Codespaces
31 |
32 | Follow these steps to open this sample in a Codespaces:
33 |
34 | 1. Click the Code drop-down menu and select the **Codespaces** tab.
35 | 1. Click on **Create codespaces on main** at the bottom of the pane.
36 |
37 | For more info, check out the [GitHub documentation](https://docs.github.com/en/free-pro-team@latest/github/developing-online-with-codespaces/creating-a-codespace#creating-a-codespace).
38 |
39 | ### VS Code Dev Containers
40 |
41 | If you already have VS Code and Docker installed, you can click the badge above or [here](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/microsoft/vscode-remote-try-sqlserver) to get started. Clicking these links will cause VS Code to automatically install the Dev Containers extension if needed, clone the source code into a container volume, and spin up a dev container for use.
42 |
43 | Follow these steps to open this sample in a container using the VS Code Dev Containers extension:
44 |
45 | 1. If this is your first time using a development container, please ensure your system meets the pre-reqs (i.e. have Docker installed) in the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started).
46 |
47 | 2. To use this repository, you can either open the repository in an isolated Docker volume:
48 |
49 | - Press F1 and select the **Dev Containers: Try a Sample...** command.
50 | - Choose the ".NET Core" sample, wait for the container to start, and try things out!
51 | > **Note:** Under the hood, this will use the **Dev Containers: Clone Repository in Container Volume...** command to clone the source code in a Docker volume instead of the local filesystem. [Volumes](https://docs.docker.com/storage/volumes/) are the preferred mechanism for persisting container data.
52 |
53 | Or open a locally cloned copy of the code:
54 |
55 | - Clone this repository to your local filesystem.
56 | - Press F1 and select the **Dev Containers: Open Folder in Container...** command.
57 | - Select the cloned copy of this folder, wait for the container to start, and try things out!
58 |
59 | ## About this template
60 |
61 | This template creates two containers, one for the Dev Container that includes .NET and Data API builder and one for Microsoft SQL Server. You will be connected to the Ubuntu, and from within that container the MS SQL container will be available on **`localhost`** port 1433. The Data API builder container also includes supporting scripts in the `.devcontainer/sql` folder used to configure the `Library` sample database.
62 |
63 | 
64 |
65 | The SQL container is deployed from the latest developer edition of Microsoft SQL 2022. The database(s) are made available directly in the Codespace/VS Code through the MSSQL extension with a connection labeled "LocalDev". The default `sa` user password is set using the .devcontainer/.env file. The default SQL port is mapped to port `1433` in `.devcontainer/docker-compose.yml`.
66 |
67 | Data API builder is a .NET Core application that provides a RESTful API for interacting with the database. This sample repository includes a preconfigured database, that is used by DAB to create the REST and GraphQL endpoints. Swagger UI offers a web-based UI that provides information about the REST endpoint, using the generated OpenAPI specification available at the default path: `http://localhost:5000/swagger/index.html`. Entities configured to be available via GraphQL are available at the default path: `http://localhost:5000/graphql`.
68 |
69 | If you wan to run some manual tests, you can use the `dab_http_request.sh` file included in the `scripts`folder. This `sh` file includes multiple http request calls you can to understand how the Data API builder to interact with the database.
70 |
71 | > **Note:**
72 | While the SQL Server container employs a standard version of SQL Server, all database development within this Dev Container can be validated for Azure SQL Database using the SQL Database Project. The SQL Database project is preconfigured with the target platform set as Azure SQL Database.
73 |
74 | ### Visual Code Tasks
75 |
76 | We have added several tasks to this repository to help with common actions. You can access these tasks by opening the Command Palette in VS Code. Here's how:
77 |
78 | 1. Press F1 or Ctrl+Shift+P to open the Command Palette.
79 | 2. Type "Run Task" and select "Tasks: Run Task".
80 | 3. Choose the task you want to run from the list.
81 |
82 | #### Execute SQL Query (Verify database)
83 |
84 | This task opens the `verifyDatabase.sql` file in your workspace and executes the SQL query in it. It uses the `ms-mssql.mssql` extension to execute the query. This task is part of the build group and is the default task that runs when you run the build task group.
85 |
86 | #### Build SQL Database project (Optional)
87 |
88 | This task builds the SQL Database project. It runs the command `dotnet build` in the `database/Library` directory of your workspace.
89 |
90 | This task is optional, but it is useful to verify the database schema. You can use this SQL Database project to make changes to the database schema and deploy it to the SQL Server container.
91 |
92 | #### Deploy SQL Database Project (Optional)
93 |
94 | This task involves deploying the SQL Database project to your SQL Server container. It executes the `postCreateCommand.sh` script found in the `.devcontainer/sql` directory of your workspace.
95 |
96 | The `postCreateCommand.sh` script requires one argument: the path to the directory containing the .dacpac file for the SQL Database project. In this scenario, that directory is `database/Library/bin/Debug`.
97 |
98 | It utilizes the sqlpackage command-line utility to update the database schema using the .dacpac file, employing authentication credentials from the `.env` file situated in the `.devcontainer` directory.
99 |
100 | #### Trust HTTPS certificate for Data API builder (DAB)
101 |
102 | As this Dev Container users .NET 8, you need to trust the .NET HTTPS certificate before starting the Data API builder engine. This task runs the command dotnet dev-certs https --trust.
103 |
104 | #### Start Data API builder (DAB) engine
105 |
106 | This task starts the DAB engine using the configuration file located at `dab/dab.config.json`. It executes the command `dab start --config=dab.config.json --no-https-redirect` within the dab directory of your workspace.
107 |
108 | > **Note:** Remember to check the Swagger and GraphQL endpoints after starting the DAB engine.
109 |
110 | ### Changing the SA password
111 |
112 | To adjust the sa password, you need to modify the `.env` file located within the `.devcontainer` directory. This password is crucial for the creation of the SQL Server container and the deployment of the Library database using the `database/Library/bin/Debug/Library.dacpac` file.
113 |
114 | The password must comply with the following rules:
115 |
116 | - It should have a minimum length of 8 characters.
117 | - It should include characters from at least three of the following categories: uppercase letters, lowercase letters, numbers, and non-alphanumeric symbols.
118 |
119 | ### Database deployment
120 |
121 | By default, a demo database titled `Library` is created using a DAC package. The deployment process is automated through the `postCreateCommand.sh` script, which is specified in the devcontainer.json configuration:
122 |
123 | ```json
124 | "postCreateCommand": "bash .devcontainer/sql/postCreateCommand.sh 'database/Library/bin/Debug'"
125 | ```
126 |
127 | #### Automated Database Deployment
128 |
129 | The `postCreateCommand.sh` script handles the database deployment by performing the following steps:
130 |
131 | 1. Loads the `SA_PASSWORD` from the `.env` file.
132 | 1. Waits for the SQL Server to be ready by attempting to connect multiple times.
133 | 1. Checks for .dacpac files in the specified directory (`database/Library/bin/Debug`).
134 | 1. Deploys each .dacpac file found to the SQL Server.
135 |
136 | #### Using the SQL Database Projects Extension
137 |
138 | You can use the SQL Database Projects extension to deploy the database schema. The Library.sqlproj project is located in the database/Library folder and can be built using the Build SQL Database project task. The output .dacpac files should be placed in the ./bin/Debug folder for deployment.
139 |
140 | #### Verifying the Database Schema
141 |
142 | The `verifyDatabase.sql` file in the `database/Library` folder can be used to verify the database schema after deployment. You can run this script using the `Execute SQL Query` VS Code task.
143 |
144 | This setup ensures that your databases are properly deployed and ready to use after the container is created.
145 |
146 | ### Adding another service
147 |
148 | You can add other services to your `.devcontainer/docker-compose.yml` file [as described in Docker's documentation](https://docs.docker.com/compose/compose-file/#service-configuration-reference). However, if you want anything running in this service to be available in the container on localhost, or want to forward the service locally, be sure to add this line to the service config:
149 |
150 | ```yaml
151 | # Runs the service on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
152 | network_mode: service:db
153 | ```
154 |
155 | ### Using the forwardPorts property
156 |
157 | By default, web frameworks and tools often only listen to localhost inside the container. As a result, we recommend using the `forwardPorts` property to make these ports available locally.
158 |
159 | ```json
160 | "forwardPorts": [9000]
161 | ```
162 |
163 | The `ports` property in `docker-compose.yml` [publishes](https://docs.docker.com/config/containers/container-networking/#published-ports) rather than forwards the port. This will not work in a cloud environment like Codespaces and applications need to listen to `*` or `0.0.0.0` for the application to be accessible externally. Fortunately the `forwardPorts` property does not have this limitation.
164 |
165 | ## Contributing
166 |
167 | This project welcomes contributions and suggestions. Most contributions require you to agree to a
168 | Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
169 | the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
170 |
171 | When you submit a pull request, a CLA bot will automatically determine whether you need to provide
172 | a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
173 | provided by the bot. You will only need to do this once across all repos using our CLA.
174 |
175 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
176 | For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
177 | contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
178 |
179 | ## Trademarks
180 |
181 | This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
182 | trademarks or logos is subject to and must follow
183 | [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
184 | Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
185 | Any use of third-party trademarks or logos are subject to those third-party's policies.
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | ## Security
4 |
5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet) and [Xamarin](https://github.com/xamarin).
6 |
7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/security.md/definition), please report it to us as described below.
8 |
9 | ## Reporting Security Issues
10 |
11 | **Please do not report security vulnerabilities through public GitHub issues.**
12 |
13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/security.md/msrc/create-report).
14 |
15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/security.md/msrc/pgp).
16 |
17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).
18 |
19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
20 |
21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
22 | * Full paths of source file(s) related to the manifestation of the issue
23 | * The location of the affected source code (tag/branch/commit or direct URL)
24 | * Any special configuration required to reproduce the issue
25 | * Step-by-step instructions to reproduce the issue
26 | * Proof-of-concept or exploit code (if possible)
27 | * Impact of the issue, including how an attacker might exploit the issue
28 |
29 | This information will help us triage your report more quickly.
30 |
31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/security.md/msrc/bounty) page for more details about our active programs.
32 |
33 | ## Preferred Languages
34 |
35 | We prefer all communications to be in English.
36 |
37 | ## Policy
38 |
39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/security.md/cvd).
40 |
41 |
42 |
--------------------------------------------------------------------------------
/SUPPORT.md:
--------------------------------------------------------------------------------
1 | # TODO: The maintainer of this repo has not yet edited this file
2 |
3 | **REPO OWNER**: Do you want Customer Service & Support (CSS) support for this product/project?
4 |
5 | - **No CSS support:** Fill out this template with information about how to file issues and get help.
6 | - **Yes CSS support:** Fill out an intake form at [aka.ms/onboardsupport](https://aka.ms/onboardsupport). CSS will work with/help you to determine next steps.
7 | - **Not sure?** Fill out an intake as though the answer were "Yes". CSS will help you decide.
8 |
9 | *Then remove this first heading from this SUPPORT.MD file before publishing your repo.*
10 |
11 | # Support
12 |
13 | ## How to file issues and get help
14 |
15 | This project uses GitHub Issues to track bugs and feature requests. Please search the existing
16 | issues before filing new issues to avoid duplicates. For new issues, file your bug or
17 | feature request as a new Issue.
18 |
19 | For help and questions about using this project, please **REPO MAINTAINER: INSERT INSTRUCTIONS HERE
20 | FOR HOW TO ENGAGE REPO OWNERS OR COMMUNITY FOR HELP. COULD BE A STACK OVERFLOW TAG OR OTHER
21 | CHANNEL. WHERE WILL YOU HELP PEOPLE?**.
22 |
23 | ## Microsoft Support Policy
24 |
25 | Support for this **PROJECT or PRODUCT** is limited to the resources listed above.
26 |
--------------------------------------------------------------------------------
/dab/.env:
--------------------------------------------------------------------------------
1 | CONN_STRING=Server=localhost;Database=library;User ID=SA;Password=P@ssw0rd!;TrustServerCertificate=true
2 | ASPNETCORE_URLS="http://localhost:5000;https://localhost:5001"
3 | DAB_ENVIRONMENT=Development
--------------------------------------------------------------------------------
/dab/dab.config.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://github.com/Azure/data-api-builder/releases/download/v1.1.7/dab.draft.schema.json",
3 | "data-source": {
4 | "database-type": "mssql",
5 | "connection-string": "@env('CONN_STRING')"
6 | },
7 | "mssql": {
8 | "set-session-context": true
9 | },
10 | "runtime": {
11 | "rest": {
12 | "enabled": true,
13 | "path": "/api",
14 | "request-body-strict": true
15 | },
16 | "graphql": {
17 | "enabled": true,
18 | "path": "/graphql",
19 | "allow-introspection": true
20 | },
21 | "host": {
22 | "cors": {
23 | "origins": [],
24 | "allow-credentials": false
25 | },
26 | "authentication": {
27 | "provider": "StaticWebApps"
28 | },
29 | "mode": "development"
30 | }
31 | },
32 | "entities": {
33 | "Author": {
34 | "source": "dbo.authors",
35 | "permissions": [
36 | {
37 | "role": "anonymous",
38 | "actions": ["*"]
39 | }
40 | ]
41 | },
42 | "Book": {
43 | "source": {
44 | "type": "table",
45 | "object": "dbo.books"
46 | },
47 | "permissions": [
48 | {
49 | "role": "anonymous",
50 | "actions": ["*"]
51 | }
52 | ]
53 | }
54 | }
55 | }
--------------------------------------------------------------------------------
/database/Library/Library.sqlproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Library
6 | {021706C6-F183-47DF-B7B6-F229958DF384}
7 | Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider
8 | 1033, CI
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/database/Library/Sequences/globalId.sql:
--------------------------------------------------------------------------------
1 | CREATE SEQUENCE [dbo].[globalId]
2 | AS INT
3 | START WITH 1000000
4 | INCREMENT BY 1;
5 |
6 |
7 | GO
8 |
9 |
--------------------------------------------------------------------------------
/database/Library/StoredProcedures/stp_get_all_cowritten_books_by_author.sql:
--------------------------------------------------------------------------------
1 |
2 | create procedure dbo.stp_get_all_cowritten_books_by_author
3 | @author nvarchar(100),
4 | @searchType char(1) = 'c'
5 | as
6 |
7 | declare @authorSearchString nvarchar(110);
8 |
9 | if @searchType = 'c'
10 | set @authorSearchString = '%' + @author + '%' -- contains
11 | else if @searchType = 's'
12 | set @authorSearchString = @author + '%' -- startswith
13 | else
14 | throw 50000, '@searchType must be set to "c" or "s"', 16;
15 |
16 | with
17 | aggregated_authors
18 | as
19 | (
20 | select
21 | ba.book_id,
22 | string_agg(concat(a.first_name, ' ', (a.middle_name + ' '), a.last_name), ', ') as authors,
23 | author_count = count(*)
24 | from
25 | dbo.books_authors ba
26 | inner join
27 | dbo.authors a on ba.author_id = a.id
28 | group by
29 | ba.book_id
30 | )
31 | select
32 | b.id,
33 | b.title,
34 | b.pages,
35 | b.[year],
36 | aa.authors
37 | from
38 | dbo.books b
39 | inner join
40 | aggregated_authors aa on b.id = aa.book_id
41 | inner join
42 | dbo.books_authors ba on b.id = ba.book_id
43 | inner join
44 | dbo.authors a on a.id = ba.author_id
45 | where
46 | aa.author_count > 1
47 | and
48 | (
49 | concat(a.first_name, ' ', (a.middle_name + ' '), a.last_name) like @authorSearchString
50 | or
51 | concat(a.first_name, ' ', a.last_name) like @authorSearchString
52 | );
53 |
54 | GO
55 |
56 |
--------------------------------------------------------------------------------
/database/Library/Tables/authors.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE [dbo].[authors] (
2 | [id] INT DEFAULT (NEXT VALUE FOR [dbo].[globalId]) NOT NULL,
3 | [first_name] NVARCHAR (100) NOT NULL,
4 | [middle_name] NVARCHAR (100) NULL,
5 | [last_name] NVARCHAR (100) NOT NULL,
6 | PRIMARY KEY CLUSTERED ([id] ASC)
7 | );
8 |
9 |
10 | GO
11 |
12 |
--------------------------------------------------------------------------------
/database/Library/Tables/books.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE [dbo].[books] (
2 | [id] INT DEFAULT (NEXT VALUE FOR [dbo].[globalId]) NOT NULL,
3 | [title] NVARCHAR (1000) NOT NULL,
4 | [year] INT NULL,
5 | [pages] INT NULL,
6 | PRIMARY KEY CLUSTERED ([id] ASC)
7 | );
8 |
9 |
10 | GO
11 |
12 |
--------------------------------------------------------------------------------
/database/Library/Tables/books_authors.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE [dbo].[books_authors] (
2 | [author_id] INT NOT NULL,
3 | [book_id] INT NOT NULL,
4 | PRIMARY KEY CLUSTERED ([author_id] ASC, [book_id] ASC),
5 | FOREIGN KEY ([author_id]) REFERENCES [dbo].[authors] ([id]),
6 | FOREIGN KEY ([book_id]) REFERENCES [dbo].[books] ([id])
7 | );
8 |
9 |
10 | GO
11 |
12 | CREATE NONCLUSTERED INDEX [ixnc1]
13 | ON [dbo].[books_authors]([book_id] ASC, [author_id] ASC);
14 |
15 |
16 | GO
17 |
18 |
--------------------------------------------------------------------------------
/database/Library/Views/vw_books_details.sql:
--------------------------------------------------------------------------------
1 |
2 | create view dbo.vw_books_details
3 | as
4 | with
5 | aggregated_authors
6 | as
7 | (
8 | select
9 | ba.book_id,
10 | string_agg(concat(a.first_name, ' ', (a.middle_name + ' '), a.last_name), ', ') as authors
11 | from
12 | dbo.books_authors ba
13 | inner join
14 | dbo.authors a on ba.author_id = a.id
15 | group by
16 | ba.book_id
17 | )
18 | select
19 | b.id,
20 | b.title,
21 | b.pages,
22 | b.[year],
23 | aa.authors
24 | from
25 | dbo.books b
26 | inner join
27 | aggregated_authors aa on b.id = aa.book_id
28 |
29 | GO
30 |
31 |
--------------------------------------------------------------------------------
/database/Library/bin/Debug/Library.dacpac:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/vscode-remote-try-dab/ffb077265d8c74721d5f36cb334ee231bb384fbc/database/Library/bin/Debug/Library.dacpac
--------------------------------------------------------------------------------
/database/Library/bin/Debug/Library.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/vscode-remote-try-dab/ffb077265d8c74721d5f36cb334ee231bb384fbc/database/Library/bin/Debug/Library.dll
--------------------------------------------------------------------------------
/database/Library/bin/Debug/Library.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/vscode-remote-try-dab/ffb077265d8c74721d5f36cb334ee231bb384fbc/database/Library/bin/Debug/Library.pdb
--------------------------------------------------------------------------------
/database/Library/postDeployment.sql:
--------------------------------------------------------------------------------
1 | -- This file contains SQL statements that will be executed after the build script.
2 | -- Authors data
3 | ---------------------------------------------------------------------------
4 | IF NOT EXISTS (SELECT 1 FROM dbo.authors WHERE id = 1)
5 | BEGIN
6 | INSERT INTO dbo.authors (id, first_name, middle_name, last_name)
7 | VALUES (1, 'Isaac', 'Yudovick', 'Asimov')
8 | END;
9 |
10 | IF NOT EXISTS (SELECT 1 FROM dbo.authors WHERE id = 2)
11 | BEGIN
12 | INSERT INTO dbo.authors (id, first_name, middle_name, last_name)
13 | VALUES (2, 'Arthur', 'Charles', 'Clarke')
14 | END;
15 |
16 | IF NOT EXISTS (SELECT 1 FROM dbo.authors WHERE id = 3)
17 | BEGIN
18 | INSERT INTO dbo.authors (id, first_name, middle_name, last_name)
19 | VALUES (3, 'Herbert', 'George', 'Wells')
20 | END;
21 |
22 | IF NOT EXISTS (SELECT 1 FROM dbo.authors WHERE id = 4)
23 | BEGIN
24 | INSERT INTO dbo.authors (id, first_name, middle_name, last_name)
25 | VALUES (4, 'Jules', 'Gabriel', 'Verne')
26 | END;
27 |
28 | IF NOT EXISTS (SELECT 1 FROM dbo.authors WHERE id = 5)
29 | BEGIN
30 | INSERT INTO dbo.authors (id, first_name, middle_name, last_name)
31 | VALUES (5, 'Philip', 'Kindred', 'Dick')
32 | END;
33 | GO
34 |
35 | -- Books data
36 | ---------------------------------------------------------------------------
37 | IF NOT EXISTS (SELECT 1 FROM dbo.books WHERE id = 1000)
38 | BEGIN
39 | INSERT INTO dbo.books (id, title, year, pages)
40 | VALUES (1000, 'Prelude to Foundation', 1988, 403)
41 | END;
42 |
43 | IF NOT EXISTS (SELECT 1 FROM dbo.books WHERE id = 1001)
44 | BEGIN
45 | INSERT INTO dbo.books (id, title, year, pages)
46 | VALUES (1001, 'Forward the Foundation', 1993, 417)
47 | END;
48 |
49 | IF NOT EXISTS (SELECT 1 FROM dbo.books WHERE id = 1002)
50 | BEGIN
51 | INSERT INTO dbo.books (id, title, year, pages)
52 | VALUES (1002, 'Foundation', 1951, 255)
53 | END;
54 |
55 | IF NOT EXISTS (SELECT 1 FROM dbo.books WHERE id = 1003)
56 | BEGIN
57 | INSERT INTO dbo.books (id, title, year, pages)
58 | VALUES (1003, 'Foundation and Empire', 1952, 247)
59 | END;
60 |
61 | IF NOT EXISTS (SELECT 1 FROM dbo.books WHERE id = 1004)
62 | BEGIN
63 | INSERT INTO dbo.books (id, title, year, pages)
64 | VALUES (1004, 'Second Foundation', 1953, 210)
65 | END;
66 |
67 | IF NOT EXISTS (SELECT 1 FROM dbo.books WHERE id = 1005)
68 | BEGIN
69 | INSERT INTO dbo.books (id, title, year, pages)
70 | VALUES (1005, 'Foundation''s Edge', 1982, 367)
71 | END;
72 |
73 | IF NOT EXISTS (SELECT 1 FROM dbo.books WHERE id = 1006)
74 | BEGIN
75 | INSERT INTO dbo.books (id, title, year, pages)
76 | VALUES (1006, 'Foundation and Earth', 1986, 356)
77 | END;
78 |
79 | IF NOT EXISTS (SELECT 1 FROM dbo.books WHERE id = 1007)
80 | BEGIN
81 | INSERT INTO dbo.books (id, title, year, pages)
82 | VALUES (1007, 'Nemesis', 1989, 386)
83 | END;
84 |
85 | IF NOT EXISTS (SELECT 1 FROM dbo.books WHERE id = 1008)
86 | BEGIN
87 | INSERT INTO dbo.books (id, title, year, pages)
88 | VALUES (1008, '2001: A Space Odyssey', 1968, 221)
89 | END;
90 |
91 | IF NOT EXISTS (SELECT 1 FROM dbo.books WHERE id = 1009)
92 | BEGIN
93 | INSERT INTO dbo.books (id, title, year, pages)
94 | VALUES (1009, '2010: Odyssey Two', 1982, 291)
95 | END;
96 |
97 | IF NOT EXISTS (SELECT 1 FROM dbo.books WHERE id = 1010)
98 | BEGIN
99 | INSERT INTO dbo.books (id, title, year, pages)
100 | VALUES (1010, '2061: Odyssey Three ', 1987, 256)
101 | END;
102 |
103 | IF NOT EXISTS (SELECT 1 FROM dbo.books WHERE id = 1011)
104 | BEGIN
105 | INSERT INTO dbo.books (id, title, year, pages)
106 | VALUES (1011, '3001: The Final Odyssey ', 1997, 288)
107 | END;
108 |
109 | IF NOT EXISTS (SELECT 1 FROM dbo.books WHERE id = 1012)
110 | BEGIN
111 | INSERT INTO dbo.books (id, title, year, pages)
112 | VALUES (1012, 'The Time Machine', 1895, 118)
113 | END;
114 |
115 | IF NOT EXISTS (SELECT 1 FROM dbo.books WHERE id = 1013)
116 | BEGIN
117 | INSERT INTO dbo.books (id, title, year, pages)
118 | VALUES (1013, 'The Island of Doctor Moreau', 1896, 153)
119 | END;
120 |
121 | IF NOT EXISTS (SELECT 1 FROM dbo.books WHERE id = 1014)
122 | BEGIN
123 | INSERT INTO dbo.books (id, title, year, pages)
124 | VALUES (1014, 'The Invisible Man', 1897, 151)
125 | END;
126 |
127 | IF NOT EXISTS (SELECT 1 FROM dbo.books WHERE id = 1015)
128 | BEGIN
129 | INSERT INTO dbo.books (id, title, year, pages)
130 | VALUES (1015, 'The War of the Worlds', 1898, 192)
131 | END;
132 |
133 | IF NOT EXISTS (SELECT 1 FROM dbo.books WHERE id = 1016)
134 | BEGIN
135 | INSERT INTO dbo.books (id, title, year, pages)
136 | VALUES (1016, 'Journey to the Center of the Earth', 1864, 183)
137 | END;
138 |
139 | IF NOT EXISTS (SELECT 1 FROM dbo.books WHERE id = 1017)
140 | BEGIN
141 | INSERT INTO dbo.books (id, title, year, pages)
142 | VALUES (1017, 'Twenty Thousand Leagues Under the Sea', 1870, 187)
143 | END;
144 |
145 | IF NOT EXISTS (SELECT 1 FROM dbo.books WHERE id = 1018)
146 | BEGIN
147 | INSERT INTO dbo.books (id, title, year, pages)
148 | VALUES (1018, 'Around the World in Eighty Days', 1873, 167)
149 | END;
150 |
151 | IF NOT EXISTS (SELECT 1 FROM dbo.books WHERE id = 1019)
152 | BEGIN
153 | INSERT INTO dbo.books (id, title, year, pages)
154 | VALUES (1019, 'From the Earth to the Moon', 1865, 186)
155 | END;
156 |
157 | IF NOT EXISTS (SELECT 1 FROM dbo.books WHERE id = 1020)
158 | BEGIN
159 | INSERT INTO dbo.books (id, title, year, pages)
160 | VALUES (1020, 'Do Androids Dream of Electric Sheep?', 1968, 244)
161 | END;
162 |
163 | IF NOT EXISTS (SELECT 1 FROM dbo.books WHERE id = 1021)
164 | BEGIN
165 | INSERT INTO dbo.books (id, title, year, pages)
166 | VALUES (1021, 'Ubik', 1969, 224)
167 | END;
168 |
169 | IF NOT EXISTS (SELECT 1 FROM dbo.books WHERE id = 1022)
170 | BEGIN
171 | INSERT INTO dbo.books (id, title, year, pages)
172 | VALUES (1022, 'The Man in the High Castle', 1962, 259)
173 | END;
174 |
175 | IF NOT EXISTS (SELECT 1 FROM dbo.books WHERE id = 1023)
176 | BEGIN
177 | INSERT INTO dbo.books (id, title, year, pages)
178 | VALUES (1023, 'A Scanner Darkly', 1977, 224)
179 | END;
180 | GO
181 |
182 | -- Books + Authors data
183 | ---------------------------------------------------------------------------
184 | -- Insert records for author 1
185 | IF NOT EXISTS (SELECT 1 FROM dbo.books_authors WHERE author_id = 1 AND book_id = 1000)
186 | BEGIN
187 | INSERT INTO dbo.books_authors (author_id, book_id)
188 | VALUES (1, 1000)
189 | END;
190 |
191 | IF NOT EXISTS (SELECT 1 FROM dbo.books_authors WHERE author_id = 1 AND book_id = 1001)
192 | BEGIN
193 | INSERT INTO dbo.books_authors (author_id, book_id)
194 | VALUES (1, 1001)
195 | END;
196 |
197 | IF NOT EXISTS (SELECT 1 FROM dbo.books_authors WHERE author_id = 1 AND book_id = 1002)
198 | BEGIN
199 | INSERT INTO dbo.books_authors (author_id, book_id)
200 | VALUES (1, 1002)
201 | END;
202 |
203 | IF NOT EXISTS (SELECT 1 FROM dbo.books_authors WHERE author_id = 1 AND book_id = 1003)
204 | BEGIN
205 | INSERT INTO dbo.books_authors (author_id, book_id)
206 | VALUES (1, 1003)
207 | END;
208 |
209 | IF NOT EXISTS (SELECT 1 FROM dbo.books_authors WHERE author_id = 1 AND book_id = 1004)
210 | BEGIN
211 | INSERT INTO dbo.books_authors (author_id, book_id)
212 | VALUES (1, 1004)
213 | END;
214 |
215 | IF NOT EXISTS (SELECT 1 FROM dbo.books_authors WHERE author_id = 1 AND book_id = 1005)
216 | BEGIN
217 | INSERT INTO dbo.books_authors (author_id, book_id)
218 | VALUES (1, 1005)
219 | END;
220 |
221 | IF NOT EXISTS (SELECT 1 FROM dbo.books_authors WHERE author_id = 1 AND book_id = 1006)
222 | BEGIN
223 | INSERT INTO dbo.books_authors (author_id, book_id)
224 | VALUES (1, 1006)
225 | END;
226 |
227 | IF NOT EXISTS (SELECT 1 FROM dbo.books_authors WHERE author_id = 1 AND book_id = 1007)
228 | BEGIN
229 | INSERT INTO dbo.books_authors (author_id, book_id)
230 | VALUES (1, 1007)
231 | END;
232 |
233 | -- Insert records for author 2
234 | IF NOT EXISTS (SELECT 1 FROM dbo.books_authors WHERE author_id = 2 AND book_id = 1008)
235 | BEGIN
236 | INSERT INTO dbo.books_authors (author_id, book_id)
237 | VALUES (2, 1008)
238 | END;
239 |
240 | IF NOT EXISTS (SELECT 1 FROM dbo.books_authors WHERE author_id = 2 AND book_id = 1009)
241 | BEGIN
242 | INSERT INTO dbo.books_authors (author_id, book_id)
243 | VALUES (2, 1009)
244 | END;
245 |
246 | IF NOT EXISTS (SELECT 1 FROM dbo.books_authors WHERE author_id = 2 AND book_id = 1010)
247 | BEGIN
248 | INSERT INTO dbo.books_authors (author_id, book_id)
249 | VALUES (2, 1010)
250 | END;
251 |
252 | IF NOT EXISTS (SELECT 1 FROM dbo.books_authors WHERE author_id = 2 AND book_id = 1011)
253 | BEGIN
254 | INSERT INTO dbo.books_authors (author_id, book_id)
255 | VALUES (2, 1011)
256 | END;
257 |
258 | -- Insert records for author 3
259 | IF NOT EXISTS (SELECT 1 FROM dbo.books_authors WHERE author_id = 3 AND book_id = 1012)
260 | BEGIN
261 | INSERT INTO dbo.books_authors (author_id, book_id)
262 | VALUES (3, 1012)
263 | END;
264 |
265 | IF NOT EXISTS (SELECT 1 FROM dbo.books_authors WHERE author_id = 3 AND book_id = 1013)
266 | BEGIN
267 | INSERT INTO dbo.books_authors (author_id, book_id)
268 | VALUES (3, 1013)
269 | END;
270 |
271 | IF NOT EXISTS (SELECT 1 FROM dbo.books_authors WHERE author_id = 3 AND book_id = 1014)
272 | BEGIN
273 | INSERT INTO dbo.books_authors (author_id, book_id)
274 | VALUES (3, 1014)
275 | END;
276 |
277 | IF NOT EXISTS (SELECT 1 FROM dbo.books_authors WHERE author_id = 3 AND book_id = 1015)
278 | BEGIN
279 | INSERT INTO dbo.books_authors (author_id, book_id)
280 | VALUES (3, 1015)
281 | END;
282 |
283 | -- Insert records for author 4
284 | IF NOT EXISTS (SELECT 1 FROM dbo.books_authors WHERE author_id = 4 AND book_id = 1016)
285 | BEGIN
286 | INSERT INTO dbo.books_authors (author_id, book_id)
287 | VALUES (4, 1016)
288 | END;
289 |
290 | IF NOT EXISTS (SELECT 1 FROM dbo.books_authors WHERE author_id = 4 AND book_id = 1017)
291 | BEGIN
292 | INSERT INTO dbo.books_authors (author_id, book_id)
293 | VALUES (4, 1017)
294 | END;
295 |
296 | IF NOT EXISTS (SELECT 1 FROM dbo.books_authors WHERE author_id = 4 AND book_id = 1018)
297 | BEGIN
298 | INSERT INTO dbo.books_authors (author_id, book_id)
299 | VALUES (4, 1018)
300 | END;
301 |
302 | IF NOT EXISTS (SELECT 1 FROM dbo.books_authors WHERE author_id = 4 AND book_id = 1019)
303 | BEGIN
304 | INSERT INTO dbo.books_authors (author_id, book_id)
305 | VALUES (4, 1019)
306 | END;
307 |
308 | -- Insert records for author 5
309 | IF NOT EXISTS (SELECT 1 FROM dbo.books_authors WHERE author_id = 5 AND book_id = 1020)
310 | BEGIN
311 | INSERT INTO dbo.books_authors (author_id, book_id)
312 | VALUES (5, 1020)
313 | END;
314 |
315 | IF NOT EXISTS (SELECT 1 FROM dbo.books_authors WHERE author_id = 5 AND book_id = 1021)
316 | BEGIN
317 | INSERT INTO dbo.books_authors (author_id, book_id)
318 | VALUES (5, 1021)
319 | END;
320 |
321 | IF NOT EXISTS (SELECT 1 FROM dbo.books_authors WHERE author_id = 5 AND book_id = 1022)
322 | BEGIN
323 | INSERT INTO dbo.books_authors (author_id, book_id)
324 | VALUES (5, 1022)
325 | END;
326 |
327 | IF NOT EXISTS (SELECT 1 FROM dbo.books_authors WHERE author_id = 5 AND book_id = 1023)
328 | BEGIN
329 | INSERT INTO dbo.books_authors (author_id, book_id)
330 | VALUES (5, 1023)
331 | END;
332 | GO
--------------------------------------------------------------------------------
/scripts/dab_http_requests.sh:
--------------------------------------------------------------------------------
1 | # Testing Data API builder REST and GraphQL endpoints
2 |
3 | # Just cmd + click / ctrl + click on the links to open them in your browser
4 | # Check DAB health endpoint
5 | http://localhost:5000
6 |
7 | # Inspect REST endpoint using Swagger
8 | http://localhost:5000/swagger/index.html
9 |
10 | # Inspect GraphQL endpoint using Banana Cake Pop
11 | http://localhost:5000/graphql
12 |
13 | # Curl commands, just copy and paste them in your terminal
14 | # Check API endpoint for Books and Authors entitiesnetstat -tuln | grep :5000
15 | curl -s http://localhost:5000/api/Book | jq
16 | curl -s http://localhost:5000/api/Author | jq
17 |
18 | # Check API endpoint for Books and Authors entities, using $filter and jq to filter the output
19 | curl -s "http://localhost:5000/api/Book?\$filter=title%20eq%20'Foundation'" | jq
20 | curl -s http://localhost:5000/api/Author | jq '.value[0] | {id, first_name, last_name}'
21 |
22 | # Check GraphQL endpoint for Books entity, query the first 2 books in ascending order by id
23 | curl -X POST \
24 | -H "Content-Type: application/json" \
25 | -d '{"query": "{ books(first: 2, orderBy: {id: ASC}) { items { id title } } }"}' \
26 | http://localhost:5000/graphql | jq
27 |
28 | # Check GraphQL endpoint for Books entity (GetBooks), query the first 2 books in descending order by id using variables
29 | curl -X POST \
30 | -H "Content-Type: application/json" \
31 | -d '{"query": "query GetBooks($first: Int!) { books(first: $first) { items { id title } } }", "variables": {"first": 2}}' \
32 | http://localhost:5000/graphql | jq
33 |
34 | # Check GraphQL endpoint for Authors entity, query the first 2 authors in ascending order by id
35 | curl -X POST \
36 | -H "Content-Type: application/json" \
37 | -d '{"query": "{ authors(first: 2, orderBy: {id: ASC}) { items { id first_name last_name } } }"}' \
38 | http://localhost:5000/graphql | jq
--------------------------------------------------------------------------------
/scripts/verifyDatabase.sql:
--------------------------------------------------------------------------------
1 | -- Verifying database
2 | use library;
3 | go
4 | select * from dbo.authors;
5 | go
6 | select * from dbo.books;
7 | go
--------------------------------------------------------------------------------