Database Queries¶
SQL from your AI. Three functions. Any database.
The db.* pack gives LLMs direct database access - explore tables, inspect schemas, run queries.
Available Functions¶
| Function | Purpose |
|---|---|
db.tables(project) |
List all tables in a database |
db.schema(project, table) |
Get table schema |
db.query(project, sql) |
Execute SQL query |
Setup¶
Configure database connections in ot-serve.yaml:
projects:
myapp:
path: /path/to/project
attrs:
db_url: postgresql://localhost/myapp
demo:
path: .
attrs:
db_url: sqlite:///demo/db/northwind.db
Basic Usage¶
List Tables¶
Get Schema¶
Run Query¶
Configuration¶
| Setting | Default | Description |
|---|---|---|
db.max_chars |
4000 | Maximum output characters |
Override in config:
Supported Databases¶
Any SQLAlchemy-compatible database:
- SQLite:
sqlite:///path/to/db.db - PostgreSQL:
postgresql://user:pass@host/db - MySQL:
mysql://user:pass@host/db
Security Notes¶
- Queries are read-only by default
- Use parameterized queries for user input
- Configure
max_charsto prevent excessive output