Flowsy.Db.Conventions.Postgres
1.0.0
See the version list below for details.
dotnet add package Flowsy.Db.Conventions.Postgres --version 1.0.0
NuGet\Install-Package Flowsy.Db.Conventions.Postgres -Version 1.0.0
<PackageReference Include="Flowsy.Db.Conventions.Postgres" Version="1.0.0" />
paket add Flowsy.Db.Conventions.Postgres --version 1.0.0
#r "nuget: Flowsy.Db.Conventions.Postgres, 1.0.0"
// Install Flowsy.Db.Conventions.Postgres as a Cake Addin #addin nuget:?package=Flowsy.Db.Conventions.Postgres&version=1.0.0 // Install Flowsy.Db.Conventions.Postgres as a Cake Tool #tool nuget:?package=Flowsy.Db.Conventions.Postgres&version=1.0.0
Flowsy Db Conventions Postgres
This package extends the Flowsy Db Conventions library with PostgreSQL specific conventions.
Enum Mapping
The DbEnumMapping
class is used to map a .NET enum type to a Postgres enum type and it has the following properties:
- RuntimeType: The .NET enum type.
- DatabaseTypeName: The name of the Postgres enum type.
- DatabaseSchemaName: The name of the schema where the Postgres enum type is defined.
- EnumNameTranslator: The name translator to use when converting enum names between .NET and database.
DbEnumNameTranslator
The DbEnumNameTranslator
class is used to translate enum names between .NET and database. It has the following properties:
- TypeNameStyle: The style to use when converting enum type names.
- MemberNameStyle: The style to use when converting enum member names.
DbPostgresConnectionFactory
The DbPostgresConnectionFactory
class is used to create connections to a PostgreSQL database.
It can be instantiated using a DbPostgresConnectionFactoryOptions
object that contains the following properties:
- ConnectionOptions: A dictionary of
DbConnectionOptions
objects. - EnumMappings: A list of
DbEnumMapping
objects. - EnumNameTranslator: A
DbEnumNameTranslator
object. This will be the default translator if any of the mappings do not have its own translator.
DbPostgresConnectionFactoryOptions options;
// Configure options
using var factory = new DbPostgresConnectionFactory(options);
using var connection = factory.GetConnection("MyDatabase1");
// Use the connection
Dependency Injection
Configuration
{
"Databases": {
"MyDatabase1": {
"ProviderInvariantName": "Npgsql",
"ConnectionString": "Server=pg.example.com;Database=my_database1;User Id=myuser;Password=mypassword;"
}
}
}
Registering the Connection Factory
// using ...
var builder = WebApplication.CreateBuilder(args);
// Register services
// ...
// Register database provider factories required by the application
DbProvider.Register("Npgsql", DbProviderFamily.PostgreSql, NpgsqlFactory.Instance);
builder.Services.AddPostgresConnectionFactory((factoryOptions, serviceProvider) =>
{
// Obtain the configuration service
var configuration = serviceProvider.GetRequiredService<IConfiguration>();
// Get connection options from configuration
var connectionOptions = configuration.GetConnectionOptions("Databases");
// Set the connection options in the factory options
// Each key of the connectionOptions dictionary will be used to identify
// the connection options when asking the IDbConnectionFactory for a connection.
factoryOptions.ConnectionOptions = connectionOptions;
factoryOptions.EnumMappings =
[
new DbEnumMapping(typeof(UserStatus), "user_status", "security"),
new DbEnumMapping(typeof(RoleType), "role_type", "security")
];
factoryOptions.EnumNameTranslator = new DbEnumNameTranslator(
typeNameStyle: CaseStyle.LowerSnakeCase,
memberNameStyle: CaseStyle.LowerSnakeCase
);
});
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net6.0
- Flowsy.Db.Conventions (>= 4.0.2)
- Npgsql (>= 9.0.2)
-
net8.0
- Flowsy.Db.Conventions (>= 4.0.2)
- Npgsql (>= 9.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.