-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
212 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
CREATE VIEW vSalesByCityAndCategory | ||
AS | ||
SELECT | ||
c.City, | ||
p.Category, | ||
SUM(f.Quantity) AS TotalQuantity, | ||
SUM(f.SalesTotal) AS TotalSales | ||
FROM | ||
dbo.FactSalesOrder f | ||
INNER JOIN dbo.DimCustomer c ON f.CustomerKey = c.CustomerKey | ||
INNER JOIN dbo.DimProduct p ON f.ProductKey = p.ProductKey | ||
GROUP BY | ||
c.City, | ||
p.Category | ||
|
||
GO |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
-- Insert sample data into the Customers table | ||
MERGE INTO DimCustomer AS target | ||
USING (VALUES | ||
(1, 'John', 'Doe', '123 Main St', 'Springfield', '12345'), | ||
(2, 'Jane', 'Smith', '456 Elm St', 'Springfield', '12345'), | ||
(3, 'Bob', 'Jones', '789 Oak St', 'Springfield', '12345') | ||
) AS source (CustomerKey, FirstName, LastName, AddressLine1, City, PostalCode) | ||
ON target.CustomerKey = source.CustomerKey | ||
WHEN NOT MATCHED BY TARGET THEN | ||
INSERT (CustomerKey, FirstName, LastName, AddressLine1, City, PostalCode) | ||
VALUES (source.CustomerKey, source.FirstName, source.LastName, source.AddressLine1, source.City, source.PostalCode); | ||
|
||
-- Insert sample data into the DimProducts table | ||
MERGE INTO DimProduct AS target | ||
USING (VALUES | ||
(1, 'Bike', 'BK-001', 1000.00), | ||
(2, 'Car', 'CR-001', 2000.00), | ||
(3, 'Truck', 'TR-001', 3000.00) | ||
) AS source (ProductKey, ProductName, Category, ListPrice) | ||
ON target.ProductKey = source.ProductKey | ||
WHEN NOT MATCHED BY TARGET THEN | ||
INSERT (ProductKey, ProductName, Category, ListPrice) | ||
VALUES (source.ProductKey, source.ProductName, source.Category, source.ListPrice); | ||
|
||
-- Insert sample data into the DimDate table | ||
MERGE INTO DimDate AS target | ||
USING (VALUES | ||
(1, '2020-01-01'), | ||
(2, '2020-01-02'), | ||
(3, '2020-01-03') | ||
) AS source (DateKey, Date) | ||
ON target.DateKey = source.DateKey | ||
WHEN NOT MATCHED BY TARGET THEN | ||
INSERT (DateKey, Date) | ||
VALUES (source.DateKey, source.Date); | ||
|
||
-- Insert sample data into the FactSales table | ||
MERGE INTO FactSalesOrder AS target | ||
USING (VALUES | ||
(1, 1, 1, 1, 1, 1000.00), | ||
(2, 2, 2, 2, 2, 4000.00), | ||
(3, 3, 3, 3, 3, 9000.00) | ||
) AS source (SalesOrderKey, SalesOrderDateKey, ProductKey, CustomerKey, Quantity, SalesTotal) | ||
ON target.SalesOrderKey = source.SalesOrderKey | ||
WHEN NOT MATCHED BY TARGET THEN | ||
INSERT (SalesOrderKey, SalesOrderDateKey, ProductKey, CustomerKey, Quantity, SalesTotal) | ||
VALUES (source.SalesOrderKey, source.SalesOrderDateKey, source.ProductKey, source.CustomerKey, source.Quantity, source.SalesTotal); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# directories | ||
**/bin/ | ||
**/obj/ | ||
**/out/ | ||
|
||
# files | ||
Dockerfile* | ||
**/*.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:9.0 AS build | ||
ARG TARGETARCH | ||
WORKDIR /source | ||
|
||
# Copy the project file and restore dependencies | ||
COPY *.csproj ./ | ||
RUN dotnet restore -a $TARGETARCH | ||
|
||
# Copy source code and publish app | ||
COPY . ./ | ||
RUN dotnet publish -c Release -a $TARGETARCH --no-restore -o /app | ||
|
||
# Use the official Microsoft .NET runtime image | ||
FROM mcr.microsoft.com/dotnet/runtime:9.0 AS final | ||
WORKDIR /app | ||
COPY --link --from=build /app ./ | ||
ARG APP_UID=1000 | ||
USER $APP_UID | ||
ENTRYPOINT ["./SqlClient.ConsoleApp"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text.Json; | ||
using System.Diagnostics; | ||
using Microsoft.Data.SqlClient; | ||
using System.Threading.Tasks; | ||
using static System.Console; | ||
|
||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace SqlClient.ConsoleApp | ||
{ | ||
class Program | ||
{ | ||
static async Task Main(string[] args) | ||
{ | ||
|
||
var serviceProvider = new ServiceCollection() | ||
.AddLogging(configure => configure.AddConsole()) | ||
.BuildServiceProvider(); | ||
|
||
var logger = serviceProvider.GetService<ILogger<Program>>(); | ||
|
||
|
||
string connection = Environment.GetEnvironmentVariable("ConnectionString") | ||
?? throw new ArgumentException("Missing 'ConnectionString' env variable"); | ||
|
||
if (args.Length == 0) | ||
{ | ||
logger.LogInformation("Please provide the path to the SQL file:"); | ||
string filePath = ReadLine(); | ||
if (string.IsNullOrEmpty(filePath)) | ||
{ | ||
logger.LogError("Missing SQL file argument"); | ||
throw new ArgumentException("Missing SQL file argument"); | ||
} | ||
args = new string[] { filePath }; | ||
} | ||
|
||
try | ||
{ | ||
string _sql = System.IO.File.ReadAllText(args[0]); | ||
SqlConnection conn = new SqlConnection(connection); | ||
conn.Open(); | ||
|
||
var logMessage = new | ||
{ | ||
Message = "Connected to SQL Server: ", | ||
ServerVersion = conn.ServerVersion, | ||
OSVersion = Environment.OSVersion.VersionString | ||
}; | ||
logger.LogInformation(JsonSerializer.Serialize(logMessage)); | ||
|
||
SqlCommand cmd = new SqlCommand(_sql, conn); | ||
var qr = await cmd.ExecuteScalarAsync(); | ||
logger.LogInformation($"Query from file: {args[0]} executed successfully."); | ||
logger.LogInformation($"Result: {qr}"); | ||
conn.Close(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
logger.LogError(ex, "An error occurred while executing the SQL file."); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<EnableSdkContainerSupport>true</EnableSdkContainerSupport> | ||
<InvariantGlobalization>false</InvariantGlobalization> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.2" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |