Flowsy.Db.Conventions.Postgres 1.0.0

There is a newer version of this package available.
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                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Flowsy.Db.Conventions.Postgres" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Flowsy.Db.Conventions.Postgres --version 1.0.0                
#r "nuget: Flowsy.Db.Conventions.Postgres, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.1 0 2/15/2025
2.0.0 24 2/14/2025
1.0.0 27 2/14/2025