-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Based on the answer from Npgsql team it seems that's safe to use Npgs…
…qlDataSource all ahead, so applied that Postgres Database management
- Loading branch information
1 parent
9a07569
commit d8dd57f
Showing
7 changed files
with
83 additions
and
59 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
35 changes: 35 additions & 0 deletions
35
src/Weasel.Postgresql/Connections/DefaultNpgsqlDataSourceFactory.cs
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,35 @@ | ||
using JasperFx.Core; | ||
using Npgsql; | ||
|
||
namespace Weasel.Postgresql.Connections; | ||
|
||
public class DefaultNpgsqlDataSourceFactory: INpgsqlDataSourceFactory | ||
{ | ||
private readonly Cache<string, NpgsqlDataSourceBuilder> builderCache = new(); | ||
|
||
public DefaultNpgsqlDataSourceFactory(Func<string, NpgsqlDataSourceBuilder> dataSourceBuilderFactory) | ||
{ | ||
builderCache.OnMissing = dataSourceBuilderFactory; | ||
} | ||
|
||
public DefaultNpgsqlDataSourceFactory(): this(connectionString => new NpgsqlDataSourceBuilder(connectionString)) | ||
{ | ||
} | ||
|
||
public NpgsqlDataSource Create(string connectionString) | ||
{ | ||
var builder = builderCache[connectionString]; | ||
|
||
return builder.Build(); | ||
} | ||
|
||
public NpgsqlDataSource Create(string masterConnectionString, string databaseName) | ||
{ | ||
var connectionString = new NpgsqlConnectionStringBuilder(masterConnectionString) { Database = databaseName } | ||
.ConnectionString; | ||
|
||
var builder = builderCache[connectionString]; | ||
|
||
return builder.Build(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Weasel.Postgresql/Connections/INpgsqlDataSourceFactory.cs
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,11 @@ | ||
using Npgsql; | ||
|
||
namespace Weasel.Postgresql.Connections; | ||
|
||
public interface INpgsqlDataSourceFactory | ||
{ | ||
NpgsqlDataSource Create(string connectionString); | ||
|
||
|
||
NpgsqlDataSource Create(string masterConnectionString, string databaseName); | ||
} |
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