Skip to content

Commit

Permalink
Add SQL generator
Browse files Browse the repository at this point in the history
  • Loading branch information
mderriey committed Feb 19, 2021
1 parent 86623d4 commit 514d8f2
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Dapper" Version="2.0.78" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="2.1.1" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/AzureIdentityLivestream.PeopleGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static async Task Main()
.Build();

var people = await PersonCreator.CreateRandomPeople(30);
await BlobPeopleGenerator.CreatePeople(configuration, people);
await SqlPeopleGenerator.CreatePeople(configuration, people);
}
}
}
23 changes: 23 additions & 0 deletions src/AzureIdentityLivestream.PeopleGenerator/SqlPeopleGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Dapper;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Configuration;

namespace AzureIdentityLivestream.PeopleGenerator
{
public static class SqlPeopleGenerator
{
public static async Task CreatePeople(IConfiguration configuration, IReadOnlyList<Person> people)
{
await using var sqlConnection = new SqlConnection(configuration.GetValue<string>("SqlConnectionString"));

foreach (var person in people)
{
await sqlConnection.ExecuteScalarAsync(
"INSERT INTO [dbo].[Person] ([FirstName], [LastName], [Age]) VALUES (@firstName, @lastName, @age)",
new { person.FirstName, person.LastName, person.Age });
}
}
}
}
3 changes: 2 additions & 1 deletion src/AzureIdentityLivestream.PeopleGenerator/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"StorageConnectionString": "UseDevelopmentStorage=true"
"StorageConnectionString": "UseDevelopmentStorage=true",
"SqlConnectionString": "Data Source=(localdb)\\azureidentitylivestream; Initial Catalog=azure-identity-livestream; Integrated Security=SSPI"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/****** Object: Table [dbo].[Person] Script Date: 17/02/21 14:24:52 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Person](
[Id] [int] IDENTITY(1,1) NOT NULL,
[FirstName] [nvarchar](100) NOT NULL,
[LastName] [nvarchar](100) NOT NULL,
[Age] [int] NOT NULL,
CONSTRAINT [PK_Person] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO

0 comments on commit 514d8f2

Please sign in to comment.