Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 67571e7

Browse files
Merge pull request #73 from thefringeninja/mysql-support
Adding MySql Support
2 parents 848a18b + 648b7db commit 67571e7

File tree

5 files changed

+82
-7
lines changed

5 files changed

+82
-7
lines changed

.dockerignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
.vscode/
1010
artifacts/
1111
build.sh
12-
build.cmd
12+
build.cmd

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ env:
88
- secure: fKxyki9JzY95G17hNHSy4dgDmH+zXIk50BR6honAz7LmsA9jGv2gg+l1AIUERH3eckdJwxze4K0e5hX88Xfn4j5nN8TnEw7Wwn7c1vjR9FxvRr5cjaJC0SVsOTZj4VC1R9Sqjzrkqv3jJDtDdz9B8aZMdEzJ+BkHwUMFxmuko2p2qabKnAonaGk5VDSTtDyvDMa0aFjKDYuB6MrnrxhfCzLk1ciyGL61SNfz0/u7Hj3xC6v4U0f0BQ9n65l5dIVn+mpuCdQ7GO0HGj0ySo7ffif3qqXXTx7ZWIl3wvf5RCp0PouA8q2dRHYYyGqhhCwuRNU7dfhS/eFtUtcITclZ/DJE86NBQGJ9tpUUhL7BJ3sNJZzbajh1F28paJgi595SKpScp4VGx3iBuDSKH4eb3cRj5TJqCUoscue8/uIZGgR4PGkGF4lbad3b7xexIk1YY/2Rwun1J0N7tqS0rej3ZRZBtipMF64NrVnt9dZzgsIlssZ0W2NvG0vcLX6DUdeZaR0diz8bUl1DXrMFxAUQ/QYxilvaESmCslRElzlb+5eaqQTG5lSP5l6f3ZcKAhvcUGggu9t3vjzpEq3zFa5dorCyK+es1ASNlwZtZr8in9oYkvam9aiDkZD8cEc+9u+qxvnX9w3MsA0P047YCMQGgwRl5dpizoySC3wr52voK7I=
99
- secure: HvSSWjsLR6qFi9/iHMKKoVUT4BDN7h4QjKHLvcrznwpfojrA1+nIlIwgcaIkxi5WClsoPmwW8YInPlyIyV+37+SaNK4sxB2puzwaC3iHBi6Ql38q+olsLdCE8u+DcfEcnzQo8pinNoyBLRjBgHjTAbrwIkLETNOZchss4A4UVhvPSznuNz5imlZxp4LqZ2pW/YcaLeCMQzuJHt5iRM6O4CMu7O4kMP/SPQXIXcqqYWI+o4um1JFO5juXBXtrhcTkOHfvGjqZghwma1F3v7zLHtqrbGBxaTLGNj0EIWPQhQEE5wDpvAqLEZcySl0ZjsPQUJd2Uxi9b8mWM1x6WaZTu9uqIy5t9lkCwUkEAwc/LUXZxwL0oi8HncgJvu7Q5KwVn375sJ0CER0Vn1FO8jphnMbpfkqUmbZmkwoIAUENNNYyGEp6zoNnRvaFQTjEW4bL2huPS0g3BgC2xyh8d5ZsPykIgQXlM8EEA2BZkd+ep2rKjOPT94rs5V5IPuVi9FYzFIsc2kpEkKZO/38j6pEAdCVIZp1m0+KRlLNQ9FeaI+xtil95V5ALIEXpc44o5OuUSoxt5ZirYaGSJtUtxo8E+HqpNL5WrTUeE8+aZos6Tu7jF63U2ehwg5xR6EubvrBjWvSHsQKcwDfdeHK2m15S/mVlahpwyyoCASAJtV7mRJI=
1010
matrix:
11-
- LIBRARY_VERSION=1.2.0-beta.3.19 CONTAINER_RUNTIME_VERSION=2.2.4 CONTAINER_RUNTIME=alpine3.9 RUNTIME=alpine-x64
12-
- LIBRARY_VERSION=1.2.0-beta.3.19 CONTAINER_RUNTIME_VERSION=2.2.4 CONTAINER_RUNTIME=alpine3.8 RUNTIME=alpine-x64
13-
- LIBRARY_VERSION=1.2.0-beta.3.19 CONTAINER_RUNTIME_VERSION=2.2.4 CONTAINER_RUNTIME=bionic RUNTIME=ubuntu.18.04-x64
14-
- LIBRARY_VERSION=1.2.0-beta.3.19 CONTAINER_RUNTIME_VERSION=2.2.4 CONTAINER_RUNTIME=stretch-slim RUNTIME=debian.9-x64
11+
- LIBRARY_VERSION=1.2.0-beta.3.21 CONTAINER_RUNTIME_VERSION=2.2.4 CONTAINER_RUNTIME=alpine3.9 RUNTIME=alpine-x64
12+
- LIBRARY_VERSION=1.2.0-beta.3.21 CONTAINER_RUNTIME_VERSION=2.2.4 CONTAINER_RUNTIME=alpine3.8 RUNTIME=alpine-x64
13+
- LIBRARY_VERSION=1.2.0-beta.3.21 CONTAINER_RUNTIME_VERSION=2.2.4 CONTAINER_RUNTIME=bionic RUNTIME=ubuntu.18.04-x64
14+
- LIBRARY_VERSION=1.2.0-beta.3.21 CONTAINER_RUNTIME_VERSION=2.2.4 CONTAINER_RUNTIME=stretch-slim RUNTIME=debian.9-x64
1515
git:
1616
depth: false
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
version: '3.1'
2+
3+
services:
4+
sql-stream-store:
5+
container_name: sss-example-server
6+
#image: sqlstreamstore/server:1.2.0-beta.3.21-alpine3.9
7+
image: sql-stream-store-server
8+
ports:
9+
- "5000:80"
10+
networks:
11+
- app-network
12+
- db-network
13+
environment:
14+
- SQLSTREAMSTORE_PROVIDER=mysql
15+
- SQLSTREAMSTORE_CONNECTION_STRING=Host=database;Port=3306;User Id=root;Database=example;Pooling=false;
16+
depends_on:
17+
- database
18+
19+
database:
20+
container_name: sss-example-mysql
21+
image: mysql:5.6
22+
ports:
23+
- "3306:3306"
24+
networks:
25+
- db-network
26+
environment:
27+
- MYSQL_ALLOW_EMPTY_PASSWORD=1
28+
29+
networks:
30+
app-network:
31+
driver: bridge
32+
db-network:
33+
driver: bridge

src/SqlStreamStore.Server/SqlStreamStore.Server.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
66
<LangVersion>latest</LangVersion>
77
<CrossGenDuringPublish>false</CrossGenDuringPublish>
8-
<LibraryVersion Condition="$(LibraryVersion) == ''">1.2.0-beta.3.21+build.442</LibraryVersion>
8+
<LibraryVersion Condition="$(LibraryVersion) == ''">1.2.0-beta.3.21</LibraryVersion>
99
</PropertyGroup>
1010
<ItemGroup>
1111
<PackageReference Include="ILLink.Tasks" Version="0.1.5-preview-1841731" />
@@ -18,6 +18,7 @@
1818
<PackageReference Include="Serilog.AspNetCore" Version="2.1.1" />
1919
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
2020
<PackageReference Include="SqlStreamStore.MsSql" Version="$(LibraryVersion)" />
21+
<PackageReference Include="SqlStreamStore.MySql" Version="$(LibraryVersion)" />
2122
<PackageReference Include="SqlStreamStore.Postgres" Version="$(LibraryVersion)" />
2223
<PackageReference Include="SqlStreamStore.HAL" Version="$(LibraryVersion)" />
2324
</ItemGroup>

src/SqlStreamStore.Server/SqlStreamStoreFactory.cs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Text;
55
using System.Threading;
66
using System.Threading.Tasks;
7+
using MySql.Data.MySqlClient;
78
using Npgsql;
89
using Serilog;
910
using SqlStreamStore.Infrastructure;
@@ -21,14 +22,16 @@ private delegate Task<IStreamStore> CreateStreamStore(
2122

2223
private const string postgres = nameof(postgres);
2324
private const string mssql = nameof(mssql);
25+
private const string mysql = nameof(mysql);
2426
private const string inmemory = nameof(inmemory);
2527

2628
private static readonly IDictionary<string, CreateStreamStore> s_factories
2729
= new Dictionary<string, CreateStreamStore>
2830
{
2931
[inmemory] = CreateInMemoryStreamStore,
3032
[postgres] = CreatePostgresStreamStore,
31-
[mssql] = CreateMssqlStreamStore
33+
[mssql] = CreateMssqlStreamStore,
34+
[mysql] = CreateMySqlStreamStore
3235
};
3336

3437
public SqlStreamStoreFactory(SqlStreamStoreServerConfiguration configuration)
@@ -110,6 +113,44 @@ CREATE DATABASE [{connectionStringBuilder.InitialCatalog}]
110113
return streamStore;
111114
}
112115

116+
private static async Task<IStreamStore> CreateMySqlStreamStore(
117+
string connectionString,
118+
string _,
119+
CancellationToken cancellationToken)
120+
{
121+
var connectionStringBuilder = new MySqlConnectionStringBuilder(connectionString);
122+
var settings = new MySqlStreamStoreSettings(connectionString);
123+
124+
var streamStore = new MySqlStreamStore(settings);
125+
126+
try
127+
{
128+
using (var connection = new MySqlConnection(new MySqlConnectionStringBuilder(connectionString)
129+
{
130+
Database = null
131+
}.ConnectionString))
132+
{
133+
await connection.OpenAsync(cancellationToken).NotOnCapturedContext();
134+
135+
using (var command = new MySqlCommand(
136+
$"CREATE DATABASE IF NOT EXISTS `{connectionStringBuilder.Database}`",
137+
connection))
138+
{
139+
await command.ExecuteNonQueryAsync(cancellationToken).NotOnCapturedContext();
140+
}
141+
}
142+
143+
await streamStore.CreateSchemaIfNotExists(cancellationToken);
144+
}
145+
catch (SqlException ex)
146+
{
147+
SchemaCreationFailed(streamStore.GetSchemaCreationScript, ex);
148+
throw;
149+
}
150+
151+
return streamStore;
152+
}
153+
113154
private static async Task<IStreamStore> CreatePostgresStreamStore(
114155
string connectionString,
115156
string schema,

0 commit comments

Comments
 (0)