Data.Npgsql.Extension 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Data.Npgsql.Extension --version 1.0.0                
NuGet\Install-Package Data.Npgsql.Extension -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="Data.Npgsql.Extension" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Data.Npgsql.Extension --version 1.0.0                
#r "nuget: Data.Npgsql.Extension, 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 Data.Npgsql.Extension as a Cake Addin
#addin nuget:?package=Data.Npgsql.Extension&version=1.0.0

// Install Data.Npgsql.Extension as a Cake Tool
#tool nuget:?package=Data.Npgsql.Extension&version=1.0.0                

Npgsql.Extension

Extension for Npgsql ADO.Net

Simply structure and fast write repositories to Npgsql

Includes reader with auto mapping data classes to data returned from sql query

Now only available snake_case (database) and UpperCamelCase(data class)

Main classes (interface + base realization):

  • IReader + Reader
  • IDatabaseOptions + DatabaseOptions
  • NpgsqlRepository (abstract)

Example usage with CRUD:

  • Table
create table users
(
    id       uuid        not null
        primary key,
    username varchar(100) not null
        unique
);
  • Database model
public class UserDatabase
{
    public Guid Id { get; set; }

    public String Username { get; set; } = null!;
}
  • Repository interface
public interface IUserRepository
{
    public Task<UserDatabase?> GetUserAsync(Guid id);

    public Task<Boolean> CreateUserAsync(UserDatabase userDatabase);

    public Task<Boolean> UpdateUserAsync(Guid id, UserDatabase userDatabase);

    public Task<Boolean> DeleteUserAsync(Guid id);
}
  • Repository
public class UserRepository : NpgsqlRepository, IUserRepository
{
    public UserRepository(IDatabaseOptions databaseOptions) : base(databaseOptions) { }

    public async Task<UserDatabase?> GetUserAsync(Guid id)
    {
        string query = "select * from users where id = $1";

        var parameters = new[]
        {
            new NpgsqlParameter{Value = id}
        };

        return await GetAsync<UserDatabase>(query, parameters);
    }

    public async Task<Boolean> CreateUserAsync(UserDatabase userDatabase)
    {
        string query = "insert into users(id, username)" +
                       "values($1, $2)";

        var parameters = new[]
        {
            new NpgsqlParameter{Value = userDatabase.Id},
            new NpgsqlParameter{Value = userDatabase.Username}
        };

        return await ExecuteAsync(query, parameters);
    }

    public async Task<Boolean> UpdateUserAsync(Guid id, UserDatabase userDatabase)
    {
        string query = "update users set " +
                       "username = $2" +
                       "where id = $1";

        var parameters = new[]
        {
            new NpgsqlParameter{Value = userDatabase.Id},
            new NpgsqlParameter{Value = userDatabase.Username},
        };

        return await ExecuteAsync(query, parameters);
    }

    public Task<Boolean> DeleteUserAsync(Guid id)
    {
        return DeleteAsync("users", "id", id);
    }
}
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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 was computed.  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. 
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
1.0.2 182 3/17/2024
1.0.1 499 12/9/2023
1.0.0 386 12/9/2023