Aiursoft.DbTools.PostgreSql
10.0.45
dotnet add package Aiursoft.DbTools.PostgreSql --version 10.0.45
NuGet\Install-Package Aiursoft.DbTools.PostgreSql -Version 10.0.45
<PackageReference Include="Aiursoft.DbTools.PostgreSql" Version="10.0.45" />
<PackageVersion Include="Aiursoft.DbTools.PostgreSql" Version="10.0.45" />
<PackageReference Include="Aiursoft.DbTools.PostgreSql" />
paket add Aiursoft.DbTools.PostgreSql --version 10.0.45
#r "nuget: Aiursoft.DbTools.PostgreSql, 10.0.45"
#:package Aiursoft.DbTools.PostgreSql@10.0.45
#addin nuget:?package=Aiursoft.DbTools.PostgreSql&version=10.0.45
#tool nuget:?package=Aiursoft.DbTools.PostgreSql&version=10.0.45
Aiursoft DbTools
<a name="dbtools"></a>
DbTools are Aiursoft's common database tools. It simplifies the process of registering DbContext and updating database. So your application can easily switch from different database types without editing the code.
Overview
What is DbTools?
Register and migrate Entity Framework Core contexts with selectable database providers and optional connection configuration.
Installation
Add the package to your .NET project:
<a name="how-to-install"></a>
Run the following command to install Aiursoft.DbTools.Switchable to your ASP.NET Core project from nuget.org:
dotnet add package Aiursoft.DbTools.Switchable
Run the following command to install Aiursoft.DbTools.InMemory to your database implementation project from nuget.org:
dotnet add package Aiursoft.DbTools.InMemory
All database implementation projects must reference a single AbstractDb project. And you need to define and use the abstract class YourDbContext in it.
Make sure your project dependency is as follows:
---
title: Project dependency diagram
---
stateDiagram-v2
Aiursoft.DbTools.InMemory --> Aiursoft.DbTools
Aiursoft.DbTools.Sqlite --> Aiursoft.DbTools
Aiursoft.DbTools.MySql --> Aiursoft.DbTools
Aiursoft.DbTools.PostgreSql --> Aiursoft.DbTools
Aiursoft.DbTools.Switchable --> Aiursoft.DbTools
Demo.Entities --> Aiursoft.DbTools
Demo.Sqlite --> Aiursoft.DbTools.Sqlite
Demo.Sqlite --> Demo.Entities
Demo.MySql --> Aiursoft.DbTools.MySql
Demo.MySql --> Demo.Entities
Demo.PostgreSql --> Aiursoft.DbTools.PostgreSql
Demo.PostgreSql --> Demo.Entities
Demo.InMemory --> Aiursoft.DbTools.InMemory
Demo.InMemory --> Demo.Entities
Demo.WebApp --> Aiursoft.DbTools.Switchable
Demo.WebApp --> Demo.InMemory
Demo.WebApp --> Demo.MySql
Demo.WebApp --> Demo.Sqlite
Demo.WebApp --> Demo.PostgreSql
Aiursoft.DbTools.SqlServer --> Aiursoft.DbTools
Requires .NET 10 or later.
Usage
Start with this complete console Program.cs after installing the package:
using Aiursoft.DbTools.InMemory;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
var services = new ServiceCollection();
services.AddAiurInMemoryDb<ExampleDbContext>();
using var provider = services.BuildServiceProvider();
using var scope = provider.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<ExampleDbContext>();
await db.Database.EnsureCreatedAsync();
Console.WriteLine(db.Database.ProviderName);
public class ExampleDbContext(DbContextOptions<ExampleDbContext> options) : DbContext(options);
Install Aiursoft.DbTools.InMemory for the self-contained in-memory example above. For a production provider and switchable host, follow the original registration and migration walkthrough:
<a name="usage"></a>
MySQL provider migration
<a name="mysql-provider-migration"></a>
Aiursoft.DbTools.MySql version 10.0.33 uses
Microting.EntityFrameworkCore.MySql version 10.0.12, replacing
Aiursoft.EntityFrameworkCore.MySql. This stable release promotes the provider
used in 10.0.33-preview.1 without further provider or API changes:
dotnet add package Aiursoft.DbTools.MySql --version 10.0.33
The AddAiurMySqlWithCache API and connection settings are unchanged. The new
provider requires EF Core 10.0.12 or later within the 10.0.x series and
MySqlConnector 2.6.2 or later. Align any directly referenced EF Core packages
before upgrading. Remove direct references to the previous MySQL provider so
that the application resolves only one provider. Code using provider-specific
Pomelo.EntityFrameworkCore.MySql namespaces or assembly names needs to use
their Microting.EntityFrameworkCore.MySql equivalents.
Keep existing migration files, model snapshots and __EFMigrationsHistory.
Provider replacement alone should not require a schema migration. Validate each
application against a restored database backup: check for unexpected model
changes, inspect migration SQL, compare existing data and exercise its queries
and writes. If the provider detects a model change, investigate it before
applying a migration. The Template and synthetic-ledger experiment does not
establish compatibility for every application's model.
Roll out the upgrade to selected applications first. Keep the previous package and application build available for rollback, and validate provider replacement separately from business schema changes.
In your startup.cs:
// In your Web project
public void ConfigureServices(IConfiguration configuration, IWebHostEnvironment environment, IServiceCollection services)
{
var (connectionString, dbType, allowCache) = configuration.GetDbSettings();
services.AddSwitchableRelationalDatabase(
dbType: EntryExtends.IsInUnitTests() ? "InMemory": dbType,
connectionString: connectionString,
supportedDbs:
[
// These comes from your database implementation projects.
new MySqlSupportedDb(allowCache: allowCache, splitQuery: false),
new SqliteSupportedDb(allowCache: allowCache, splitQuery: true),
new PostgreSqlSupportedDb(allowCache: allowCache, splitQuery: false),
new InMemorySupportedDb()
]);
services
.AddControllersWithViews()
.AddApplicationPart(typeof(Startup).Assembly);
}
See Configuration for the complete SQLite, MySQL, PostgreSQL and in-memory settings.
Simple, isn't it?
Your database project need to be different with your web project, you need the following command to generate migrations:
cd ./Demo.MySql
dotnet ef migrations add Init --context "MySqlContext" -s ../Demo.WebApp/Demo.WebApp.csproj
cd ..
cd ./Demo.Sqlite
dotnet ef migrations add Init --context "SqliteContext" -s ../Demo.WebApp/Demo.WebApp.csproj
cd ..
cd ./Demo.PostgreSql
dotnet ef migrations add Init --context "PostgreSqlContext" -s ../Demo.WebApp/Demo.WebApp.csproj
cd ..
For more usage, please check the Demo app in the demos folder!
Custom Database Connection Configuration
<a name="custom-database-connection-configuration"></a>
You can configure the underlying database connection using the onConnectionOpen parameter. This is available for all relational databases (SQLite, MySQL, PostgreSQL, SQL Server).
For example, when using SQLite, you can register custom SQL functions:
services.AddAiurSqliteWithCache<AppDbContext>(
connectionString,
allowCache: true,
splitQuery: false,
onConnectionOpen: (connection) =>
{
// Cast to the specific connection type if needed
if (connection is Microsoft.Data.Sqlite.SqliteConnection sqliteConnection)
{
sqliteConnection.CreateFunction("MyCustomFunction", (int x) => x * 2);
}
});
This callback is invoked every time a database connection is opened.
Configuration
In your appsettings.json:
{
"ConnectionStrings": {
"AllowCache": "True",
"DbType": "Sqlite",
"DefaultConnection": "DataSource=app.db;Cache=Shared"
}
}
Or:
{
// sudo docker run -d --name db -e MYSQL_RANDOM_ROOT_PASSWORD=true -e MYSQL_DATABASE=kahla -e MYSQL_USER=kahla -e MYSQL_PASSWORD=kahla_password -p 3306:3306 mysql
"ConnectionStrings": {
"AllowCache": "True",
"DbType": "MySql",
"DefaultConnection": "Server=localhost;Database=kahla;Uid=kahla;Pwd=kahla_password;"
}
}
Or:
{
// sudo docker run --name kahla-postgres -e POSTGRES_DB=kahla -e POSTGRES_USER=kahla -e POSTGRES_PASSWORD=kahla_password -p 5432:5432 -d postgres:latest
"ConnectionStrings": {
"AllowCache": "True",
"DbType": "PostgreSql",
"DefaultConnection": "Server=localhost;Database=kahla;Uid=kahla;Pwd=kahla_password;"
}
}
Or:
{
"ConnectionStrings": {
"AllowCache": "False",
"DbType": "InMemory"
}
}
Registration and migration
Keep provider-specific contexts and migration projects separate from the web application as shown in Usage. GetDbSettings() reads the ConnectionStrings section; the original four configurations are preserved above. Use the existing demo projects to verify provider-specific migrations against disposable data.
Development
Install the .NET 10 SDK.
From the repository root, restore, build and test:
dotnet restore Aiursoft.DbTools.sln
dotnet build Aiursoft.DbTools.sln --no-restore
dotnet test Aiursoft.DbTools.sln --no-restore
Run ./lint.sh for the existing static checks.
How to contribute
<a name="how-to-contribute"></a>
There are many ways to contribute to the project: logging bugs, submitting pull requests, reporting issues, and creating suggestions.
Even if you have push rights on the repository, you should create a personal fork and create feature branches there when you need them. This keeps the main repository clean and your workflow cruft out of sight.
We're also interested in your feedback on the future of this project. You can submit a suggestion or feature request through the issue tracker. To make this process more effective, we're asking that these include more information to help define them more clearly.
License
Licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Aiursoft.DbTools (>= 10.0.32)
- EFCoreSecondLevelCacheInterceptor.MemoryCache (>= 5.6.2)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 10.0.4)
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 |
|---|---|---|
| 10.0.45 | 50 | 11/20/2026 |
| 10.0.44 | 97 | 11/15/2026 |
| 10.0.43 | 95 | 11/15/2026 |
| 10.0.42 | 91 | 11/11/2026 |
| 10.0.41 | 88 | 11/10/2026 |
| 10.0.40 | 121 | 10/26/2026 |
| 10.0.39 | 104 | 10/25/2026 |
| 10.0.38 | 110 | 10/23/2026 |
| 10.0.36 | 105 | 10/19/2026 |
| 10.0.35 | 102 | 10/14/2026 |
| 10.0.34 | 134 | 9/19/2026 |
| 10.0.33 | 126 | 9/14/2026 |
| 10.0.32 | 142 | 9/9/2026 |
| 10.0.31 | 173 | 8/20/2026 |
| 10.0.30 | 132 | 8/12/2026 |
| 10.0.29 | 142 | 7/17/2026 |
| 10.0.28 | 155 | 7/15/2026 |
| 10.0.27 | 141 | 7/11/2026 |
| 10.0.26 | 145 | 7/10/2026 |
| 10.0.25 | 139 | 7/8/2026 |