Skip to content

Commit 93becf3

Browse files
committed
From DAB repo
1 parent ef5492b commit 93becf3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+3950
-35
lines changed

.devcontainer/Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# [Choice] .NET version: 6.0-focal, 7.0-bullseye
2+
ARG VARIANT="6.0-focal"
3+
FROM mcr.microsoft.com/devcontainers/dotnet:0-${VARIANT}
4+
5+
# Add .NET global tools path
6+
ENV PATH $PATH:/home/vscode/.dotnet:/home/vscode/.dotnet/tools
7+
8+
# [Choice] Node.js version: none, lts/*, 18, 16, 14
9+
ARG NODE_VERSION="none"
10+
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
11+
12+
# [Optional] Uncomment this section to install additional OS packages.
13+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
14+
&& apt-get -y install --no-install-recommends software-properties-common
15+
16+
# Install SQL Tools: SQLPackage and sqlcmd
17+
COPY sql/installSQLtools.sh installSQLtools.sh
18+
RUN bash ./installSQLtools.sh \
19+
&& apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts
20+
21+
# Install Data API Builder for vscode user
22+
RUN su vscode -c "dotnet tool install --global Microsoft.DataApiBuilder" 2>&1
23+
24+
# Install StrawberryShake.Tools for vscode user
25+
RUN su vscode -c "dotnet tool install --global StrawberryShake.Tools" 2>&1

.devcontainer/devcontainer.json

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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 SQL Server",
5+
"dockerComposeFile": "docker-compose.yml",
6+
"service": "app",
7+
"workspaceFolder": "/workspace",
8+
// "containerEnv": {
9+
// "SA_PASSWORD": "P@ssw0rd!"
10+
// },
11+
// "remoteEnv": {
12+
// "SA_PASSWORD": "P@ssw0rd!"
13+
// },
14+
// Configure tool-specific properties.
15+
"customizations": {
16+
// Configure properties specific to VS Code.
17+
"vscode": {
18+
// Set *default* container specific settings.json values on container create.
19+
"settings": {
20+
"mssql.connections": [
21+
{
22+
"server": "localhost,1433",
23+
"database": "master",
24+
"authenticationType": "SqlLogin",
25+
"user": "sa",
26+
"password": "P@ssw0rd!",
27+
"savePassword": true,
28+
"profileName": "LocalDev",
29+
"trustServerCertificate": true
30+
}
31+
],
32+
"sqlDatabaseProjects.dotnetSDK Location": "/usr/share/dotnet/sdk/6.0.414"
33+
},
34+
// Add the IDs of extensions you want installed when the container is created.
35+
"extensions": [
36+
"ms-dotnettools.csdevkit",
37+
"ms-dotnettools.csharp",
38+
"ms-dotnettools.blazorwasm-companion",
39+
"ms-azuretools.vscode-bicep",
40+
"hashicorp.terraform",
41+
"ms-mssql.mssql",
42+
"ms-vscode.vscode-node-azure-pack",
43+
"ms-azuretools.vscode-docker",
44+
"github.copilot",
45+
"github.codespaces",
46+
"postman.postman-for-vscode"
47+
]
48+
}
49+
},
50+
51+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
52+
// "forwardPorts": [5000, 5001],
53+
// "portsAttributes": {
54+
// "5001": {
55+
// "protocol": "https"
56+
// }
57+
// }
58+
"forwardPorts": [5000, 5001, 1433],
59+
60+
// Post create commands to run after the container is created.
61+
"postCreateCommand": "bash .devcontainer/sql/postCreateCommand.sh P@ssw0rd! './bin/Debug/' './.devcontainer/sql/'",
62+
63+
// Post start commands to run after the container is started.
64+
//"postStartCommand": "cd dab && dab start --config=dab.config.json",
65+
66+
// Features to add to the dev container. More info: https://containers.dev/features.
67+
"features": {
68+
"ghcr.io/devcontainers/features/azure-cli:1": {
69+
"installBicep": true,
70+
"installUsingPython": true,
71+
"version": "latest"
72+
},
73+
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
74+
"version": "latest"
75+
},
76+
"ghcr.io/azure/azure-dev/azd:latest": {
77+
"version": "latest"
78+
},
79+
"ghcr.io/devcontainers/features/terraform:1": {
80+
"version": "latest"
81+
}
82+
}
83+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
84+
// "remoteUser": "root"
85+
}

.devcontainer/docker-compose.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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: 6.0-focal, 7.0-bullseye
10+
VARIANT: "6.0-focal"
11+
# Optional version of Node.js
12+
NODE_VERSION: "none"
13+
14+
volumes:
15+
- ..:/workspace:cached
16+
17+
# Overrides default command so things don't shut down after the process ends.
18+
command: sleep infinity
19+
20+
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
21+
network_mode: service:db
22+
# Uncomment the next line to use a non-root user for all processes.
23+
# user: vscode
24+
25+
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
26+
# (Adding the "ports" property to this file will not forward from a Codespace.)
27+
28+
db:
29+
image: mcr.microsoft.com/mssql/server:2022-latest
30+
hostname: SQL-Library
31+
container_name: SQL-Library
32+
restart: unless-stopped
33+
environment:
34+
SA_PASSWORD: P@ssw0rd!
35+
ACCEPT_EULA: Y
36+
# Add "forwardPorts": ["1433"] to **devcontainer.json** to forward MSSQL locally.
37+
# (Adding the "ports" property to this file will not forward from a Codespace.)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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 install sqlcmd
7+
echo "Go-SQLCmd installed."
8+
9+
echo "Installing Sqlpackage ..."
10+
curl -sSL -o sqlpackage.zip "https://aka.ms/sqlpackage-linux"
11+
mkdir /opt/sqlpackage
12+
unzip sqlpackage.zip -d /opt/sqlpackage
13+
rm sqlpackage.zip
14+
chmod a+x /opt/sqlpackage/sqlpackage
15+
echo "Sqlpackage installed."
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
-- Copyright (c) Microsoft Corporation.
2+
-- Licensed under the MIT License.
3+
use master;
4+
go
5+
6+
if not exists
7+
(select name from sys.databases where name = N'library')
8+
create database library;
9+
go
10+
11+
use library;
12+
go
13+
14+
drop table if exists dbo.books_authors;
15+
drop table if exists dbo.books;
16+
drop table if exists dbo.authors;
17+
drop sequence if exists dbo.globalId;
18+
go
19+
20+
create sequence dbo.globalId
21+
as int
22+
start with 1000000
23+
increment by 1
24+
go
25+
26+
create table dbo.books
27+
(
28+
id int not null primary key default (next value for dbo.globalId),
29+
title nvarchar(1000) not null,
30+
[year] int null,
31+
[pages] int null
32+
)
33+
go
34+
35+
create table dbo.authors
36+
(
37+
id int not null primary key default (next value for dbo.globalId),
38+
first_name nvarchar(100) not null,
39+
middle_name nvarchar(100) null,
40+
last_name nvarchar(100) not null
41+
)
42+
go
43+
44+
create table dbo.books_authors
45+
(
46+
author_id int not null foreign key references dbo.authors(id),
47+
book_id int not null foreign key references dbo.books(id),
48+
primary key (
49+
author_id,
50+
book_id
51+
)
52+
)
53+
go
54+
55+
create nonclustered index ixnc1 on dbo.books_authors(book_id, author_id)
56+
go
57+
58+
insert into dbo.authors
59+
values
60+
(1, 'Isaac', 'Yudovick', 'Asimov'),
61+
(2, 'Arthur', 'Charles', 'Clarke'),
62+
(3, 'Herbert', 'George', 'Wells'),
63+
(4, 'Jules', 'Gabriel', 'Verne'),
64+
(5, 'Philip', 'Kindred','Dick');
65+
GO
66+
67+
insert into dbo.books
68+
values
69+
(1000, 'Prelude to Foundation', 1988, 403),
70+
(1001, 'Forward the Foundation', 1993, 417),
71+
(1002, 'Foundation', 1951, 255),
72+
(1003, 'Foundation and Empire', 1952, 247),
73+
(1004, 'Second Foundation', 1953, 210),
74+
(1005, 'Foundation''s Edge', 1982, 367),
75+
(1006, 'Foundation and Earth', 1986, 356),
76+
(1007, 'Nemesis', 1989, 386),
77+
(1008, '2001: A Space Odyssey', 1968, 221),
78+
(1009, '2010: Odyssey Two', 1982, 291),
79+
(1010, '2061: Odyssey Three ', 1987, 256),
80+
(1011, '3001: The Final Odyssey ', 1997, 288),
81+
(1012, 'The Time Machine', 1895, 118),
82+
(1013, 'The Island of Doctor Moreau', 1896, 153),
83+
(1014, 'The Invisible Man', 1897, 151),
84+
(1015, 'The War of the Worlds', 1898, 192),
85+
(1016, 'Journey to the Center of the Earth', 1864, 183),
86+
(1017, 'Twenty Thousand Leagues Under the Sea', 1870, 187),
87+
(1018, 'Around the World in Eighty Days', 1873, 167),
88+
(1019, 'From the Earth to the Moon', 1865, 186),
89+
(1020, 'Do Androids Dream of Electric Sheep?', 1968, 244),
90+
(1021, 'Ubik', 1969, 224),
91+
(1022, 'The Man in the High Castle', 1962, 259),
92+
(1023, 'A Scanner Darkly', 1977, 224);
93+
go
94+
95+
insert into dbo.books_authors
96+
values
97+
(1, 1000),
98+
(1, 1001),
99+
(1, 1002),
100+
(1, 1003),
101+
(1, 1004),
102+
(1, 1005),
103+
(1, 1006),
104+
(1, 1007),
105+
(2, 1008),
106+
(2, 1009),
107+
(2, 1010),
108+
(2, 1011),
109+
(3, 1012),
110+
(3, 1013),
111+
(3, 1014),
112+
(3, 1015),
113+
(4, 1016),
114+
(4, 1017),
115+
(4, 1018),
116+
(4, 1019),
117+
(5, 1020),
118+
(5, 1021),
119+
(5, 1022),
120+
(5, 1023);
121+
go
122+
123+
create or alter view dbo.vw_books_details
124+
as
125+
with
126+
aggregated_authors
127+
as
128+
(
129+
select
130+
ba.book_id,
131+
string_agg(concat(a.first_name, ' ', (a.middle_name + ' '), a.last_name), ', ') as authors
132+
from
133+
dbo.books_authors ba
134+
inner join
135+
dbo.authors a on ba.author_id = a.id
136+
group by
137+
ba.book_id
138+
)
139+
select
140+
b.id,
141+
b.title,
142+
b.pages,
143+
b.[year],
144+
aa.authors
145+
from
146+
dbo.books b
147+
inner join
148+
aggregated_authors aa on b.id = aa.book_id
149+
go
150+
151+
create or alter procedure dbo.stp_get_all_cowritten_books_by_author
152+
@author nvarchar(100),
153+
@searchType char(1) = 'c'
154+
as
155+
156+
declare @authorSearchString nvarchar(110);
157+
158+
if @searchType = 'c'
159+
set @authorSearchString = '%' + @author + '%' -- contains
160+
else if @searchType = 's'
161+
set @authorSearchString = @author + '%' -- startswith
162+
else
163+
throw 50000, '@searchType must be set to "c" or "s"', 16;
164+
165+
with
166+
aggregated_authors
167+
as
168+
(
169+
select
170+
ba.book_id,
171+
string_agg(concat(a.first_name, ' ', (a.middle_name + ' '), a.last_name), ', ') as authors,
172+
author_count = count(*)
173+
from
174+
dbo.books_authors ba
175+
inner join
176+
dbo.authors a on ba.author_id = a.id
177+
group by
178+
ba.book_id
179+
)
180+
select
181+
b.id,
182+
b.title,
183+
b.pages,
184+
b.[year],
185+
aa.authors
186+
from
187+
dbo.books b
188+
inner join
189+
aggregated_authors aa on b.id = aa.book_id
190+
inner join
191+
dbo.books_authors ba on b.id = ba.book_id
192+
inner join
193+
dbo.authors a on a.id = ba.author_id
194+
where
195+
aa.author_count > 1
196+
and
197+
(
198+
concat(a.first_name, ' ', (a.middle_name + ' '), a.last_name) like @authorSearchString
199+
or
200+
concat(a.first_name, ' ', a.last_name) like @authorSearchString
201+
);
202+
go

0 commit comments

Comments
 (0)