Aiursoft.DbTools.InMemory 9.0.11

DBTools

MIT licensed Pipeline stat Test Coverage NuGet version (Aiursoft.CSTools) ManHours

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.

Installation

To install Aiursoft.DbTools to your project from nuget.org:

dotnet add package Aiursoft.DbTools

Project structure

---
title: Project dependency diagram
---

stateDiagram-v2
    Aiursoft.DbTools.InMemory --> Aiursoft.DbTools
    Aiursoft.DbTools.Sqlite --> Aiursoft.DbTools
    Aiursoft.DbTools.MySql --> 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.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
    Aiursoft.DbTools.SqlServer --> Aiursoft.DbTools

Usage

In your startup.cs:

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:
        [
            new MySqlSupportedDb(allowCache: allowCache, splitQuery: false),
            new SqliteSupportedDb(allowCache: allowCache, splitQuery: true),
            new InMemorySupportedDb()
        ]);

    services
        .AddControllersWithViews()
        .AddApplicationPart(typeof(Startup).Assembly);
}

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 hub.aiursoft.cn/mysql
  "ConnectionStrings": {
    "AllowCache": "True",
    "DbType": "MySql",
    "DefaultConnection": "Server=localhost;Database=kahla;Uid=kahla;Pwd=kahla_password;"
  }
}

Or:

{
  "ConnectionStrings": {
    "AllowCache": "False",
    "DbType": "InMemory"
  }
}

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 ..

For more usage, please check the Demo app in the demos folder!

How to contribute

There are many ways to contribute to the project: logging bugs, submitting pull requests, reporting issues, and creating suggestions.

Even if you with 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.

Showing the top 20 packages that depend on Aiursoft.DbTools.InMemory.

Packages Downloads
Aiursoft.SDK
The base class, tools and extends for Aiursoft web apps.
252
Aiursoft.DbTools.Switchable
Nuget package of 'Switchable' provided by Aiursoft
47
Aiursoft.DbTools.Switchable
Nuget package of 'Switchable' provided by Aiursoft
42
Aiursoft.DbTools.Switchable
Nuget package of 'Switchable' provided by Aiursoft
40
Aiursoft.DbTools.Switchable
Nuget package of 'Switchable' provided by Aiursoft
39
Aiursoft.DbTools.Switchable
Nuget package of 'Switchable' provided by Aiursoft
36
Aiursoft.DbTools.Switchable
Nuget package of 'Switchable' provided by Aiursoft
35
Aiursoft.DbTools.Switchable
Nuget package of 'Switchable' provided by Aiursoft
34
Aiursoft.DbTools.Switchable
Nuget package of 'Switchable' provided by Aiursoft
33
Aiursoft.DbTools.Switchable
Nuget package of 'Switchable' provided by Aiursoft
30
Aiursoft.DbTools.Switchable
Nuget package of 'Switchable' provided by Aiursoft
27
Aiursoft.DbTools.Switchable
Nuget package of 'Switchable' provided by Aiursoft
25
Aiursoft.DbTools.Switchable
Nuget package of 'Switchable' provided by Aiursoft
24
Aiursoft.DbTools.Switchable
Nuget package of 'Switchable' provided by Aiursoft
22
Aiursoft.DbTools.Switchable
Nuget package of 'Switchable' provided by Aiursoft
19
Aiursoft.DbTools.Switchable
Nuget package of 'Switchable' provided by Aiursoft
14
Aiursoft.SDK
The base class, tools and extends for Aiursoft web apps.
13

Version Downloads Last updated
9.0.11 0 02/27/2025
9.0.4 0 02/23/2025
9.0.3 0 02/12/2025
9.0.2 59 02/01/2025
9.0.1 49 01/16/2025
9.0.0 43 12/30/2024
8.0.13 218 11/13/2024
8.0.12 207 10/15/2024
8.0.11 86 10/09/2024
8.0.10 60 08/18/2024
8.0.9 74 07/10/2024
8.0.8 13 07/07/2024
8.0.7 25 06/29/2024
8.0.6 29 06/05/2024
8.0.5 47 05/16/2024
8.0.4 41 05/04/2024
8.0.3 80 03/25/2024
8.0.2 7 03/31/2024
8.0.1 5 04/28/2024
8.0.0 136 03/25/2024
7.0.19 12 04/11/2024
7.0.18 6 04/28/2024
7.0.17 5 04/28/2024
7.0.16 8 04/28/2024
7.0.15 5 04/28/2024
7.0.14 7 04/28/2024
7.0.13 4 04/28/2024
7.0.12 248 03/26/2024
7.0.11 7 04/28/2024
7.0.10 6 04/28/2024
7.0.9 8 04/28/2024
7.0.8 8 04/28/2024
7.0.7 6 04/28/2024
7.0.6 8 04/17/2024
7.0.5 10 04/17/2024
7.0.4 6 04/28/2024
7.0.3 6 04/28/2024
7.0.2 5 04/28/2024
7.0.1 6 04/28/2024
7.0.0 16 04/06/2024
6.0.32 11 04/28/2024
6.0.31 6 04/28/2024
6.0.30 4 04/28/2024
6.0.29 7 04/28/2024