Database Adapters
Text2SQL supports multiple database systems through dedicated adapters. Each adapter implements database-specific introspection, query validation, and SQL dialect handling.Supported Databases
SQLite
Lightweight embedded database
PostgreSQL
Advanced open-source database
SQL Server
Microsoft enterprise database
MySQL
Popular open-source database
BigQuery
Google Cloud data warehouse
Adapter Comparison
| Feature | SQLite | PostgreSQL | SQL Server | MySQL | BigQuery |
|---|---|---|---|---|---|
| Schemas | No | Yes | Yes | Yes | Yes |
| Foreign Keys | Yes | Yes | Yes | Yes | Yes |
| Indexes | Yes | Yes | Yes | Yes | Limited |
| Views | Yes | Yes | Yes | Yes | Yes |
| Constraints | Yes | Yes | Yes | Yes | Yes |
| Column Stats | Yes | Yes | Yes | Yes | No |
| Row Counts | Yes | Yes | Yes | Yes | Yes |
| Transactions | Yes | Yes | Yes | Yes | No |
Common Adapter Interface
All adapters implement the same core interface:Grounding Functions
Grounding functions control what schema metadata the AI receives. All adapters support these groundings:Available Groundings
tables(config?)
Introspects tables, columns, and data types.
views(config?)
Introspects database views.
info(config?)
Provides database version and metadata.
indexes(config?)
Introspects table indexes for performance hints.
constraints(config?)
Introspects constraints (PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK).
rowCount(config?)
Counts rows and classifies table sizes (tiny, small, medium, large, huge).
columnStats(config?)
Collects column statistics (min, max, null fraction, correlation).
columnValues(config?)
Fetches distinct values for low-cardinality columns (enums).
Recommended Grounding Combinations
Minimal (Fast Introspection)
Balanced (Most Common)
Comprehensive (Slower, Maximum Context)
SQL Dialect Support
Each adapter formats SQL according to its database’s dialect:Identifier Quoting
String Escaping
LIMIT vs TOP
Schema Filtering
PostgreSQL, SQL Server, MySQL, and BigQuery support schema filtering:schemas, system schemas are excluded automatically:
- PostgreSQL:
pg_catalog,information_schema - SQL Server:
sys,INFORMATION_SCHEMA - MySQL:
information_schema,mysql,performance_schema
Error Handling
Each adapter provides database-specific error formatting:Error Types
MISSING_TABLE- Referenced table does not existINVALID_COLUMN- Referenced column does not exist or is ambiguousSYNTAX_ERROR- SQL syntax errorINVALID_FUNCTION- Function or operator not recognizedCONSTRAINT_ERROR- Constraint violationUNKNOWN_ERROR- Unclassified error
Validation
All adapters validate SQL usingEXPLAIN before execution:
Performance Considerations
Introspection Performance
Introspection speed varies by grounding:| Grounding | Speed | Notes |
|---|---|---|
tables() | Fast | Basic metadata query |
views() | Fast | Basic metadata query |
info() | Fast | Single query |
indexes() | Fast | Single query |
constraints() | Fast | Single query |
rowCount() | Slow | Counts every table |
columnStats() | Slow | Scans every column |
columnValues() | Medium | Limited by limit parameter |
Caching
Introspection results are automatically cached:version parameter:
Manual Cache Control
Adapter-Specific Features
Each adapter has unique capabilities:PostgreSQL
- Full schema support
- Advanced constraint introspection
- Column statistics from
pg_stats - Correlation and n_distinct metadata
SQLite
- Embedded database (no network latency)
- Simple constraint model
- Fast introspection
SQL Server
- Multiple schema support
- Advanced index metadata
- T-SQL dialect
MySQL
- MariaDB compatibility
- InnoDB and MyISAM support
- Character set handling
BigQuery
- Serverless execution
- Dataset and table partitioning
- Nested and repeated fields
Next Steps
SQLite Adapter
Setup and configuration for SQLite
PostgreSQL Adapter
Setup and configuration for PostgreSQL
Teachables
Inject domain knowledge
API Reference
Full adapter API documentation