Universal Database Provider Architecture

One Interface.
Five Databases.
Infinite Possibilities.

PeopleWorks GPT's revolutionary multi-database support enables seamless natural language queries across SQL Server, MySQL, PostgreSQL, Oracle, and SQLite — all through a single, elegant API.

SS
My
Pg
Or
Sq

The Provider Pattern

A clean abstraction layer that separates business logic from database-specific implementations

%%{init: {'theme': 'dark', 'themeVariables': { 'primaryColor': '#6366f1', 'primaryTextColor': '#e2e8f0', 'primaryBorderColor': '#4f46e5', 'lineColor': '#64748b', 'secondaryColor': '#1e293b', 'tertiaryColor': '#0f172a', 'background': '#0f172a', 'mainBkg': '#1e293b', 'nodeBorder': '#4f46e5', 'clusterBkg': '#1e293b', 'titleColor': '#e2e8f0', 'edgeLabelBackground': '#1e293b'}}}%% flowchart TB subgraph Client["🎯 Client Layer"] NL["💬 Natural Language Query"] App["📱 Application"] end subgraph Core["⚙️ DatabaseGPT Core"] Client_Interface["IDatabaseGptClient"] GPT_Client["DatabaseGptClient"] ChatGPT["🤖 ChatGPT Integration"] end subgraph Abstraction["🔌 Abstraction Layer"] IProvider["IDatabaseGptProvider"] end subgraph Providers["🗄️ Database Providers"] SS["SQL Server Provider
T-SQL"] MY["MySQL Provider
MySQL"] PG["PostgreSQL Provider
PL/pgSQL"] OR["Oracle Provider
PL/SQL"] SQ["SQLite Provider
SQLite"] end subgraph Databases["💾 Databases"] DB_SS[("SQL Server")] DB_MY[("MySQL")] DB_PG[("PostgreSQL")] DB_OR[("Oracle")] DB_SQ[("SQLite")] end NL --> App App --> Client_Interface Client_Interface --> GPT_Client GPT_Client --> ChatGPT GPT_Client --> IProvider IProvider --> SS IProvider --> MY IProvider --> PG IProvider --> OR IProvider --> SQ SS --> DB_SS MY --> DB_MY PG --> DB_PG OR --> DB_OR SQ --> DB_SQ style Client fill:#1e293b,stroke:#6366f1,stroke-width:2px style Core fill:#1e293b,stroke:#0ea5e9,stroke-width:2px style Abstraction fill:#1e293b,stroke:#f59e0b,stroke-width:2px style Providers fill:#1e293b,stroke:#10b981,stroke-width:2px style Databases fill:#1e293b,stroke:#8b5cf6,stroke-width:2px

SQL Server

T-SQL

MySQL

MySQL

PostgreSQL

PL/pgSQL

Oracle

PL/SQL

SQLite

SQLite

The Provider Contract

Every database provider implements this unified interface for consistent behavior

C# IDatabaseGptProvider.cs
using System.Data.Common;

namespace DatabaseGpt.Abstractions;

public interface IDatabaseGptProvider : IDisposable
{
    /// <summary>The display name of the database (e.g., "SQL Server", "MySQL")</summary>
    string Name { get; }

    /// <summary>The SQL dialect used (e.g., "T-SQL", "PL/pgSQL")</summary>
    string Language { get; }

    /// <summary>Returns provider-specific query optimization hints</summary>
    Task<string?> GetQueryHintsAsync(CancellationToken cancellationToken = default);

    /// <summary>Retrieves available tables from the database schema</summary>
    Task<IEnumerable<string>> GetTablesAsync(
        IEnumerable<string> includedTables, 
        IEnumerable<string> excludedTables, 
        CancellationToken cancellationToken = default);

    /// <summary>Generates CREATE TABLE scripts for AI context</summary>
    Task<string> GetCreateTablesScriptAsync(
        IEnumerable<string> tables, 
        IEnumerable<string> excludedColumns, 
        CancellationToken cancellationToken = default);

    /// <summary>Normalizes and validates the generated query</summary>
    Task<string> NormalizeQueryAsync(
        string query, 
        CancellationToken cancellationToken = default);

    /// <summary>Executes the query and returns a data reader</summary>
    Task<DbDataReader> ExecuteQueryAsync(
        string query, 
        CancellationToken cancellationToken = default);
}
Interface Method Purpose AI Integration
Name Identifies the database engine for prompt construction 🤖 Used in system prompts: "You are querying a {Name} database"
Language Specifies the SQL dialect for code generation 🤖 Instructs AI to generate {Language} syntax
GetTablesAsync Retrieves schema metadata for table discovery 🤖 Provides available tables for AI to reference
GetCreateTablesScriptAsync Generates DDL scripts with columns and relationships 🤖 Gives AI complete schema understanding
GetQueryHintsAsync Provider-specific optimization guidance 🤖 Teaches AI database-specific best practices
NormalizeQueryAsync Validates and cleans AI-generated queries ✅ Post-processing before execution
ExecuteQueryAsync Runs the query against the actual database 📊 Returns results to the application

Provider Implementations

Each provider handles database-specific schema introspection and query execution

C# SqlServerDatabaseGptProvider.cs
public class SqlServerDatabaseGptProvider : IDatabaseGptProvider
{
    private readonly SqlConnection connection;

    // Database identification for AI prompts
    public string Name => "SQL Server";
    public string Language => "T-SQL";

    public async Task<IEnumerable<string>> GetTablesAsync(...)
    {
        // Uses INFORMATION_SCHEMA for cross-version compatibility
        var query = @"
            SELECT QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) 
            FROM INFORMATION_SCHEMA.TABLES";
        
        return await connection.QueryAsync<string>(query);
    }

    public async Task<string> GetCreateTablesScriptAsync(...)
    {
        // Generates CREATE TABLE with columns, types, and constraints
        // Compatible with SQL Server 2008 R2+ (uses CASE instead of IIF)
        var query = @"
            SELECT COLUMN_NAME, 
                   UPPER(DATA_TYPE) + 
                   CASE WHEN CHARACTER_MAXIMUM_LENGTH = -1 THEN '(MAX)' 
                        ELSE CAST(CHARACTER_MAXIMUM_LENGTH AS VARCHAR) END +
                   CASE WHEN IS_NULLABLE = 'YES' THEN ' NULL' 
                        ELSE ' NOT NULL' END
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = @table";
        
        // Also extracts foreign key relationships
        var relationships = await GetRelationshipsAsync(tables);
        
        return script + relationships;
    }
}
C# MySqlDatabaseGptProvider.cs
public class MySqlDatabaseGptProvider : IDatabaseGptProvider
{
    private readonly MySqlConnection connection;

    public string Name => "MySQL";
    public string Language => "MySQL";

    public async Task<IEnumerable<string>> GetTablesAsync(...)
    {
        // Excludes system schemas
        var query = @"
            SELECT CONCAT(TABLE_SCHEMA, '.', TABLE_NAME) AS Tables 
            FROM INFORMATION_SCHEMA.TABLES 
            WHERE TABLE_SCHEMA NOT IN 
                ('information_schema', 'mysql', 'performance_schema', 'sys')";
        
        return await connection.QueryAsync<string>(query);
    }

    public async Task<string> GetCreateTablesScriptAsync(...)
    {
        // MySQL-specific backtick quoting
        var columns = allColumns
            .Select(c => $"`{c.Column}` {c.Description}");
        
        return $"CREATE TABLE `{schema}`.`{table}` ({string.Join(", ", columns)});";
    }
}
C# OracleDatabaseGptProvider.cs
public class OracleDatabaseGptProvider : IDatabaseGptProvider
{
    private readonly OracleConnection connection;

    public string Name => "Oracle";
    public string Language => "PL/SQL";

    public async Task<IEnumerable<string>> GetTablesAsync(...)
    {
        // Uses Oracle's ALL_TABLES catalog
        var query = @"
            SELECT owner || '.' || table_name AS TABLES 
            FROM ALL_TABLES 
            WHERE owner = USER";
        
        return await connection.QueryAsync<string>(query);
    }

    public async Task<string> GetCreateTablesScriptAsync(...)
    {
        // Oracle-specific data types: VARCHAR2, NUMBER with precision/scale
        var query = @"
            SELECT DATA_TYPE || 
                   CASE WHEN DATA_TYPE IN ('VARCHAR2', 'CHAR') 
                        THEN '(' || CHAR_LENGTH || ')' 
                        WHEN DATA_TYPE = 'NUMBER' AND DATA_SCALE > 0 
                        THEN '(' || DATA_PRECISION || ',' || DATA_SCALE || ')' 
                        ELSE '' END AS DESCRIPTION
            FROM ALL_TAB_COLUMNS
            WHERE OWNER = :schema AND TABLE_NAME = :table";
        
        return await BuildScriptAsync(query);
    }
}

Provider Feature Matrix

Database-specific implementations and their capabilities

Feature SQL Server MySQL PostgreSQL Oracle SQLite
Schema Introspection
Primary Key Detection
Foreign Key Relationships
Schema Filtering N/A
Column Exclusion
Legacy Version Support 2008 R2+ 5.7+ 9.6+ 11g+ 3.x+
Identifier Quoting [brackets] `backticks` "quotes" NONE [brackets]
System Catalog INFORMATION_SCHEMA INFORMATION_SCHEMA INFORMATION_SCHEMA ALL_TABLES sqlite_schema
📅 SQL Server Version Compatibility

PeopleWorks GPT supports SQL Server versions from 2008 R2 onwards. The provider automatically uses CASE statements instead of IIF for compatibility, and generates SQL optimized for each version's capabilities.

2009
2008 R2
Level 100
2012
2012
Level 110
2014
2014
Level 120
2016
2016
Level 130
2019
2019
Level 150
2022
2022
Level 160

Easy Integration

Fluent API design makes provider configuration intuitive and type-safe

🔧

Dependency Injection

Seamlessly integrates with ASP.NET Core's built-in dependency injection system. Configure once, use everywhere with proper lifecycle management.

Resilience Pipeline

Built-in retry policies handle transient failures automatically. Configurable retry attempts with Polly integration for robust operation.

🔒

Secure by Design

Connection strings are handled securely through configuration. Only SELECT queries are allowed — INSERT, UPDATE, DELETE are blocked by design.

📊

Schema Control

Fine-grained control over which tables and columns are exposed to AI. Protect sensitive data while enabling powerful natural language queries.

C# Program.cs - SQL Server Configuration
// Configure DatabaseGPT with SQL Server provider
builder.Services.AddDatabaseGpt(
    databaseGpt =>
    {
        // Use fluent extension method for SQL Server
        databaseGpt.UseSqlServer(connectionString);
        
        // Optional: Restrict tables visible to AI
        databaseGpt.IncludedTables = ["dbo.Customers", "dbo.Orders", "dbo.Products"];
        
        // Optional: Hide sensitive columns
        databaseGpt.ExcludedColumns = ["SSN", "CreditCardNumber", "Password"];
        
        // Optional: Add business context for AI
        databaseGpt.SystemMessage = @"
            This is an e-commerce database. 
            Orders are linked to Customers via CustomerId.
            Products have a CategoryId foreign key.";
        
        // Configure retry attempts for failed queries
        databaseGpt.MaxRetries = 3;
    },
    chatGpt =>
    {
        chatGpt.UseOpenAI(apiKey);
        chatGpt.DefaultModel = "gpt-4";
    }
);
C# Other Database Providers
// MySQL Configuration
databaseGpt.UseMySql("Server=localhost;Database=shop;User=root;Password=***;");

// PostgreSQL Configuration
databaseGpt.UseNpgsql("Host=localhost;Database=shop;Username=postgres;Password=***;");

// Oracle Configuration
databaseGpt.UseOracle("Data Source=//localhost:1521/XE;User Id=system;Password=***;");

// SQLite Configuration
databaseGpt.UseSqlite("Data Source=shop.db");

// Dynamic provider selection at runtime
switch (databaseType)
{
    case "SqlServer": databaseGpt.UseSqlServer(conn); break;
    case "MySql":     databaseGpt.UseMySql(conn);     break;
    case "Postgres":  databaseGpt.UseNpgsql(conn);    break;
    case "Oracle":    databaseGpt.UseOracle(conn);    break;
    case "Sqlite":    databaseGpt.UseSqlite(conn);    break;
}

How It Works

The journey from natural language question to database results

%%{init: {'theme': 'dark', 'themeVariables': { 'primaryColor': '#6366f1', 'primaryTextColor': '#e2e8f0', 'primaryBorderColor': '#4f46e5', 'lineColor': '#64748b', 'secondaryColor': '#1e293b', 'tertiaryColor': '#0f172a'}}}%% sequenceDiagram participant U as 👤 User participant C as 🖥️ Client participant GPT as 🤖 ChatGPT participant P as 🔌 Provider participant DB as 💾 Database U->>C: "Show me top 10 customers by revenue" Note over C: Create/Load Session C->>GPT: System: "You're querying a SQL Server database
Tables: Customers, Orders, Products" C->>GPT: User: "Find relevant tables for this query" GPT-->>C: "dbo.Customers, dbo.Orders" C->>P: GetCreateTablesScriptAsync([Customers, Orders]) P->>DB: Query INFORMATION_SCHEMA DB-->>P: Column definitions, relationships P-->>C: CREATE TABLE scripts C->>GPT: "Generate T-SQL query using these tables:
[schema details]" GPT-->>C: "SELECT TOP 10 c.Name, SUM(o.Total)..." C->>P: NormalizeQueryAsync(query) P-->>C: Validated query C->>P: ExecuteQueryAsync(query) P->>DB: Execute SELECT DB-->>P: DbDataReader P-->>C: Results C-->>U: 📊 Data Table
1

💬 Natural Language Input

Users ask questions in plain English. No SQL knowledge required. The system understands context from previous questions in the session.

2

🔍 Table Discovery

AI analyzes the question and identifies which database tables contain relevant data. It considers all available tables from the provider.

3

📋 Schema Analysis

The provider generates CREATE TABLE scripts including columns, data types, constraints, and foreign key relationships for AI context.

4

⚡ Query Generation

Using schema knowledge, AI generates optimized SQL in the provider's specific dialect (T-SQL, MySQL, PL/SQL, etc.).

5

✅ Validation & Execution

The query is normalized, validated as a SELECT statement, and executed through the provider's database connection with built-in retry logic.

By The Numbers

5
Database Engines Supported
1
Unified Interface
0
SQL Knowledge Required
Query Possibilities
Package Provider Dependencies Framework
DatabaseGpt.Abstractions Core interfaces and exceptions None .NET 8.0+
DatabaseGpt Main client and DI extensions ChatGptNet, Polly .NET 8.0+
DatabaseGpt.SqlServer SQL Server Microsoft.Data.SqlClient, Dapper .NET 8.0+
DatabaseGpt.MySql MySQL MySql.Data, Dapper .NET 8.0+
DatabaseGpt.Npgsql PostgreSQL Npgsql, Dapper .NET 8.0+
DatabaseGpt.Oracle Oracle Oracle.ManagedDataAccess.Core, Dapper .NET 8.0+
DatabaseGpt.Sqlite SQLite Microsoft.Data.Sqlite, Dapper .NET 8.0+

See It In Action

The same natural language query, optimized for each database

💬 User Question

"Show me the top 5 customers who spent the most money last year"

T-SQL SQL Server Generated Query
SELECT TOP 5 
    c.[CustomerName], 
    SUM(o.[TotalAmount]) AS TotalSpent
FROM [dbo].[Customers] c
INNER JOIN [dbo].[Orders] o ON c.[CustomerId] = o.[CustomerId]
WHERE o.[OrderDate] >= DATEADD(YEAR, -1, GETDATE())
GROUP BY c.[CustomerName]
ORDER BY TotalSpent DESC
MySQL MySQL Generated Query
SELECT 
    c.`CustomerName`, 
    SUM(o.`TotalAmount`) AS TotalSpent
FROM `shop`.`Customers` c
INNER JOIN `shop`.`Orders` o ON c.`CustomerId` = o.`CustomerId`
WHERE o.`OrderDate` >= DATE_SUB(NOW(), INTERVAL 1 YEAR)
GROUP BY c.`CustomerName`
ORDER BY TotalSpent DESC
LIMIT 5
PostgreSQL PostgreSQL Generated Query
SELECT 
    c."CustomerName", 
    SUM(o."TotalAmount") AS "TotalSpent"
FROM public."Customers" c
INNER JOIN public."Orders" o ON c."CustomerId" = o."CustomerId"
WHERE o."OrderDate" >= CURRENT_DATE - INTERVAL '1 year'
GROUP BY c."CustomerName"
ORDER BY "TotalSpent" DESC
LIMIT 5
PL/SQL Oracle Generated Query
SELECT 
    CustomerName, 
    TotalSpent
FROM (
    SELECT 
        c.CustomerName, 
        SUM(o.TotalAmount) AS TotalSpent
    FROM SHOP.Customers c
    INNER JOIN SHOP.Orders o ON c.CustomerId = o.CustomerId
    WHERE o.OrderDate >= ADD_MONTHS(SYSDATE, -12)
    GROUP BY c.CustomerName
    ORDER BY TotalSpent DESC
)
WHERE ROWNUM <= 5

Ready to Transform Your Data?

Connect any supported database and start asking questions in seconds

C# Quick Start Example
// 1. Register the service
builder.Services.AddDatabaseGpt(
    db => db.UseSqlServer(connectionString),
    gpt => gpt.UseOpenAI(apiKey)
);

// 2. Inject the client
public class QueryController(IDatabaseGptClient client)
{
    // 3. Ask questions in natural language!
    public async Task<IActionResult> Query(string question)
    {
        var result = await client.ExecuteNaturalLanguageQueryAsync(
            Guid.NewGuid(),  // Session ID for conversation context
            question
        );
        
        // result.Query = Generated SQL
        // result.Reader = Data results
        
        return Ok(result);
    }
}