Skip to content

TheyCallMeErick/DbDumper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DbDumper

A Terminal User Interface (TUI) tool for executing SQL queries and generating 100% offline HTML reports.

  ____  _     ____
 |  _ \| |__ |  _ \ _   _ _ __ ___  _ __   ___ _ __
 | | | | '_ \| | | | | | | '_ ` _ \| '_ \ / _ \ '__|
 | |_| | |_) | |_| | |_| | | | | | | |_) |  __/ |
 |____/|_.__/|____/ \__,_|_| |_| |_| .__/ \___|_|
                                    |_|

Features

  • 🗄️ Multi-provider — SQLite & PostgreSQL out of the box (easily extensible)
  • 🎨 Beautiful TUI — powered by Spectre.Console
  • 📊 Rich HTML reports — dark-themed, sortable, filterable, paginated, 100% self-contained (no CDN)
  • 💉 Dependency InjectionMicrosoft.Extensions.DependencyInjection
  • 🏗️ Strategy pattern — add new providers by implementing IDbProvider
  • Dapper — lightweight, fast query execution

Architecture

DbDumper/
├── Program.cs                          # Composition root (DI setup)
├── src/
│   ├── Core/
│   │   ├── Interfaces/
│   │   │   ├── IDbProvider.cs          # Strategy interface
│   │   │   ├── IQueryService.cs        # Orchestration interface
│   │   │   └── IReportGenerator.cs     # Report strategy interface
│   │   └── Models/
│   │       ├── QueryResult.cs          # Rich result with metadata
│   │       └── ConnectionProfile.cs    # Config model + DbDumperOptions
│   ├── Providers/
│   │   ├── DbProviderBase.cs           # Abstract base (Dapper logic)
│   │   ├── SqliteProvider.cs           # SQLite implementation
│   │   └── PostgresProvider.cs         # PostgreSQL implementation
│   ├── Services/
│   │   └── QueryService.cs             # Provider resolution + execution
│   ├── Reports/
│   │   └── HtmlReportGenerator.cs      # Fully self-contained HTML reports
│   ├── TUI/
│   │   └── DbDumperApp.cs              # Spectre.Console TUI loop
│   └── ServiceCollectionExtensions.cs  # DI registration
└── config/
    └── appsettings.json                # Connections & settings

Design Patterns

Pattern Where
Strategy IDbProvider — each DB engine is a swappable strategy
Strategy IReportGenerator — swappable report format
Factory / Registry QueryService resolves the correct IDbProvider at runtime
Options DbDumperOptions bound via IOptions<T>
DI / IoC Full Microsoft.Extensions.DependencyInjection wiring

Getting Started

Prerequisites

Run

cd DbDumper
dotnet run

Configuration

Edit config/appsettings.json:

{
  "DbDumper": {
    "ReportsOutputPath": "./reports",
    "QueryTimeoutSeconds": 30,
    "Connections": [
      {
        "Alias": "local-sqlite",
        "Provider": "sqlite",
        "ConnectionString": "Data Source=./data/sample.db"
      },
      {
        "Alias": "my-postgres",
        "Provider": "postgres",
        "ConnectionString": "Host=localhost;Database=mydb;Username=user;Password=pass"
      }
    ]
  }
}

You can also override any setting with environment variables prefixed with DBDUMPER_:

DBDUMPER_DbDumper__QueryTimeoutSeconds=60 dotnet run

Adding a New Provider

  1. Create src/Providers/MySqlProvider.cs implementing DbProviderBase:
public sealed class MySqlProvider : DbProviderBase
{
    public override string ProviderName => "MySQL";
    public override string ProviderKey  => "mysql";

    public override async Task<IDbConnection> OpenConnectionAsync(
        string connectionString, CancellationToken cancellationToken = default)
    {
        var conn = new MySqlConnection(connectionString);
        await conn.OpenAsync(cancellationToken);
        return conn;
    }
}
  1. Register it in ServiceCollectionExtensions.cs:
services.AddSingleton<IDbProvider, MySqlProvider>();
  1. Add a connection entry in appsettings.json with "Provider": "mysql".

HTML Report Features

Generated reports are 100% self-contained — no internet connection required:

  • 🌑 Dark theme with syntax-aware column rendering
  • 🔍 Client-side row filtering (instant, no server)
  • ↕️ Sortable columns (click header, supports numeric sort)
  • 📄 Client-side pagination (100 rows/page)
  • 📋 Query metadata: provider, alias, elapsed time, row/column counts
  • 💾 The full SQL query is embedded in the report

QueryResult Model

public sealed class QueryResult
{
    public required string                Query           { get; init; }
    public required string                ProviderName    { get; init; }
    public required string                ConnectionAlias { get; init; }
    public required List<string>          Columns         { get; init; }
    public required IEnumerable<dynamic>  Rows            { get; init; }
    public          int                   RowCount        { get; init; }
    public required DateTimeOffset        ExecutedAt      { get; init; }
    public required TimeSpan              Elapsed         { get; init; }
    public          bool                  IsSuccess       { get; init; }
    public          string?               ErrorMessage    { get; init; }
    public          string?               ReportTitle     { get; set; }
}

About

TUI para execução de consultas SQL/NoSQL e geração de relatórios HTML offline com funcionalidades de filtro e ordenação. Projeto de teste feito completamente utilizando IA no processo de desenvolvimento.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages