SQLite Adapter
The SQLite adapter provides lightweight embedded database support for Text2SQL. Perfect for local development, testing, and single-file databases.Installation
Basic Usage
Configuration Options
Execute Function
Theexecute function receives SQL and returns query results.
Using better-sqlite3
Using node-sqlite3
Custom Validation
By default, validation usesEXPLAIN to check SQL syntax. You can provide a custom validator:
Grounding Functions
All SQLite grounding functions are available:SQLite-Specific Features
No Schema Support
SQLite does not have separate schemas. All tables are in a single namespace:Identifier Quoting
SQLite uses double quotes for identifiers:String Escaping
SQLite escapes single quotes by doubling them:LIMIT Clause
SQLite uses LIMIT for row limits:Error Handling
SQLite errors are automatically classified:| Error Pattern | Type | Suggestion |
|---|---|---|
no such table: X | MISSING_TABLE | Check the database schema for the correct table name |
no such column: X | INVALID_COLUMN | Check the table schema for correct column names |
ambiguous column name: X | INVALID_COLUMN | Use table aliases to disambiguate |
near "X": syntax error | SYNTAX_ERROR | Review query structure, keywords, and punctuation |
no tables specified | SYNTAX_ERROR | Add FROM clause |
attempt to write a readonly database | CONSTRAINT_ERROR | Database is read-only |
Complete Example
sqlite-example.ts
In-Memory Databases
Perfect for testing:Read-Only Databases
Open database in read-only mode:Performance Tips
1. Use Indexes
SQLite benefits greatly from indexes:2. Enable WAL Mode
Write-Ahead Logging improves concurrency:3. Optimize Introspection
Minimize grounding functions for faster startup:4. Prepare Statements
Reuse prepared statements:Limitations
No Advanced Constraints
SQLite has limited constraint support:- No CHECK constraints with subqueries
- No partial indexes (before SQLite 3.8)
- No generated columns (before SQLite 3.31)
Limited ALTER TABLE
SQLite cannot:- Drop columns (before SQLite 3.35)
- Modify column types
- Add constraints to existing tables
No Stored Procedures
SQLite does not support:- Stored procedures
- User-defined functions (in SQL)
- Triggers with multiple statements
Best Practices
1. Use Transactions
2. Close Connections
3. Backup Regularly
Next Steps
PostgreSQL Adapter
Setup for PostgreSQL databases
Teachables
Inject domain knowledge
Getting Started
Complete getting started guide
API Reference
Full adapter API documentation