Supported Databases
DBHub currently supports the following database systems:- PostgreSQL - Open-source relational database with advanced features
- MySQL - Popular open-source relational database
- MariaDB - MySQL-compatible database with enhanced features
- SQL Server - Microsoft’s enterprise relational database
- SQLite - Lightweight embedded database
Connector Architecture
ConnectorRegistry Pattern
DBHub uses a registry pattern to dynamically register and manage database connectors. Each connector registers itself at module load time:postgres://orpostgresql://→ PostgreSQL connectormysql://→ MySQL connectormariadb://→ MariaDB connectorsqlserver://→ SQL Server connectorsqlite://→ SQLite connector
Connection Management
TheConnectorManager class (src/connectors/manager.ts:16) handles database connections and supports:
- Multi-source connections: Connect to multiple databases simultaneously with unique IDs
- Lazy connection: Defer connection until first use to improve startup time
- SSH tunneling: Secure connections through bastion hosts
- Connection pooling: Efficient resource usage for network databases
Connector Interface
All connectors implement theConnector interface (src/connectors/interface.ts:106) which defines:
Core Methods
connect(dsn, initScript?, config?)- Establish database connectiondisconnect()- Close database connectionclone()- Create new instance for multi-source support
Schema Discovery
getSchemas()- List all schemas/databasesgetTables(schema?)- List tables in a schemagetTableSchema(tableName, schema?)- Get column informationgetTableIndexes(tableName, schema?)- Get index informationgetTableComment(tableName, schema?)- Get table description (optional)getTableRowCount(tableName, schema?)- Get estimated row count (optional)
Stored Procedures
getStoredProcedures(schema?, routineType?)- List procedures/functionsgetStoredProcedureDetail(procedureName, schema?)- Get procedure details
Query Execution
executeSQL(sql, options, parameters?)- Execute SQL with options and parameters
Common Connection Options
All connectors support these connection options viaConnectorConfig (src/connectors/interface.ts:58):
Timeouts
SSL/TLS Modes
All network databases support SSL via thesslmode query parameter:
sslmode=disable- No SSL connection (default for development)sslmode=require- SSL without certificate verification- Other values - SSL with certificate verification
Read-Only Mode
PostgreSQL-Specific Options
search_path becomes the default for discovery methods.
DSN Format Overview
Each connector uses a URL-based DSN format:SSH Tunnel Support
All network databases can connect through SSH tunnels for secure access:Building Custom Connectors
To extend DBHub with a new database connector:- Create a new directory:
src/connectors/{database-type}/ - Implement
ConnectorandDSNParserinterfaces fromsrc/connectors/interface.ts - Register your connector:
- Add your connector type to the
ConnectorTypeunion insrc/connectors/interface.ts:4
src/connectors/.
Multi-Statement Support
Connectors handle multi-statement SQL differently:- PostgreSQL: Uses transactions for consistency (src/connectors/postgres/index.ts:569)
- MySQL/MariaDB: Native multi-statement support enabled by default
- SQL Server: Limited multi-statement support
- SQLite: Executes statements individually, tracks changes
Error Handling
All connectors follow consistent error handling:- DSN parsing errors include obfuscated DSN and expected format
- Connection errors include specific database error messages
- Query errors log SQL and parameters (when available)
- All errors preserve stack traces for debugging
Performance Optimizations
Connection Pooling
Network databases (PostgreSQL, MySQL, MariaDB, SQL Server) use connection pools:- PostgreSQL:
pg.Pool - MySQL:
mysql2.createPool() - MariaDB:
mariadb.createPool() - SQL Server:
mssql.ConnectionPool
Row Count Estimation
For large tables, connectors provide fast row count estimation using catalog statistics:- PostgreSQL:
pg_class.reltuples(src/connectors/postgres/index.ts:337) - SQL Server: System catalog statistics
- MySQL/MariaDB/SQLite: Use
COUNT(*)as fallback
Query Result Limiting
ThemaxRows option applies database-native LIMIT clauses to avoid fetching unnecessary data:
Next Steps
- Configure your first connection: Configuration Guide
- Explore connector-specific features:
- PostgreSQL - Schemas, full-text search, JSON operations
- MySQL - IAM authentication, multi-database support
- MariaDB - MySQL compatibility with enhancements
- SQL Server - Named instances, Azure AD authentication
- SQLite - Embedded databases, in-memory mode
- Set up secure connections: SSH Tunnels