dbagent-cli 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dbagent_cli-0.1.0/PKG-INFO +242 -0
- dbagent_cli-0.1.0/README.md +218 -0
- dbagent_cli-0.1.0/dbagent/__init__.py +5 -0
- dbagent_cli-0.1.0/dbagent/agent/generator.py +264 -0
- dbagent_cli-0.1.0/dbagent/agent/pipeline.py +259 -0
- dbagent_cli-0.1.0/dbagent/agent/validator.py +116 -0
- dbagent_cli-0.1.0/dbagent/cli.py +717 -0
- dbagent_cli-0.1.0/dbagent/config.py +89 -0
- dbagent_cli-0.1.0/dbagent/connectors/base.py +75 -0
- dbagent_cli-0.1.0/dbagent/connectors/factory.py +25 -0
- dbagent_cli-0.1.0/dbagent/connectors/mongo.py +237 -0
- dbagent_cli-0.1.0/dbagent/connectors/relational.py +472 -0
- dbagent_cli-0.1.0/dbagent/llm/auto_setup.py +269 -0
- dbagent_cli-0.1.0/dbagent/llm/base.py +37 -0
- dbagent_cli-0.1.0/dbagent/llm/factory.py +73 -0
- dbagent_cli-0.1.0/dbagent/llm/gemini_provider.py +110 -0
- dbagent_cli-0.1.0/dbagent/llm/groq_provider.py +99 -0
- dbagent_cli-0.1.0/dbagent/llm/mock_provider.py +42 -0
- dbagent_cli-0.1.0/dbagent/llm/ollama_provider.py +145 -0
- dbagent_cli-0.1.0/dbagent/llm/openrouter_provider.py +100 -0
- dbagent_cli-0.1.0/dbagent/schema/formatter.py +123 -0
- dbagent_cli-0.1.0/dbagent/schema/models.py +72 -0
- dbagent_cli-0.1.0/dbagent/schema/selector.py +70 -0
- dbagent_cli-0.1.0/dbagent/ui/console.py +77 -0
- dbagent_cli-0.1.0/dbagent/ui/viewer.py +93 -0
- dbagent_cli-0.1.0/dbagent_cli.egg-info/PKG-INFO +242 -0
- dbagent_cli-0.1.0/dbagent_cli.egg-info/SOURCES.txt +35 -0
- dbagent_cli-0.1.0/dbagent_cli.egg-info/dependency_links.txt +1 -0
- dbagent_cli-0.1.0/dbagent_cli.egg-info/entry_points.txt +3 -0
- dbagent_cli-0.1.0/dbagent_cli.egg-info/requires.txt +18 -0
- dbagent_cli-0.1.0/dbagent_cli.egg-info/top_level.txt +1 -0
- dbagent_cli-0.1.0/pyproject.toml +43 -0
- dbagent_cli-0.1.0/setup.cfg +4 -0
- dbagent_cli-0.1.0/tests/test_cli.py +426 -0
- dbagent_cli-0.1.0/tests/test_connectors.py +108 -0
- dbagent_cli-0.1.0/tests/test_generator.py +73 -0
- dbagent_cli-0.1.0/tests/test_schema.py +97 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dbagent-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Universal Database Introspection and Script Generation AI Agent (CLI)
|
|
5
|
+
Author: DB-Agent Team
|
|
6
|
+
Requires-Python: >=3.9
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: typer>=0.9.0
|
|
9
|
+
Requires-Dist: rich>=13.0.0
|
|
10
|
+
Requires-Dist: prompt-toolkit>=3.0.0
|
|
11
|
+
Requires-Dist: pydantic>=2.0.0
|
|
12
|
+
Requires-Dist: sqlalchemy>=2.0.0
|
|
13
|
+
Requires-Dist: requests>=2.28.0
|
|
14
|
+
Requires-Dist: httpx>=0.24.0
|
|
15
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
16
|
+
Provides-Extra: all
|
|
17
|
+
Requires-Dist: psycopg2-binary>=2.9.0; extra == "all"
|
|
18
|
+
Requires-Dist: pymysql>=1.0.0; extra == "all"
|
|
19
|
+
Requires-Dist: pymongo>=4.0.0; extra == "all"
|
|
20
|
+
Requires-Dist: duckdb>=0.9.0; extra == "all"
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
23
|
+
Requires-Dist: pytest-asyncio>=0.20.0; extra == "dev"
|
|
24
|
+
|
|
25
|
+
# โก DB-Agent
|
|
26
|
+
|
|
27
|
+
> **Universal Database Introspector & AI Script Generator CLI**
|
|
28
|
+
> *100% Free, Standalone, and runs with Local (Ollama) or Free Cloud AI models.*
|
|
29
|
+
|
|
30
|
+
`db-agent` connects to any database using provided credentials or connection URLs, introspects the complete schema (tables, columns, data types, primary/foreign keys, indexes, and sample values), and generates dialect-specific SQL queries, migrations, ETL data pipelines, and backend APIs from natural language instructions.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## ๐ Key Features
|
|
35
|
+
|
|
36
|
+
- **Universal Database Support**:
|
|
37
|
+
- **Relational**: PostgreSQL, MySQL, MariaDB, SQLite, Microsoft SQL Server (MSSQL), Oracle, DuckDB, Snowflake.
|
|
38
|
+
- **Document DBs**: MongoDB (schema inference via document sampling).
|
|
39
|
+
- **100% Free & Standalone AI Engine**:
|
|
40
|
+
- **Ollama (Local & Offline)**: Zero cost, private, runs on your machine (`qwen2.5-coder`, `llama3.2`, `deepseek-r1`, `mistral`).
|
|
41
|
+
- **Google Gemini (Free Tier)**: Direct access to `gemini-2.0-flash` & `gemini-1.5-flash`.
|
|
42
|
+
- **Groq (Free Ultra-Fast Tier)**: `llama-3.3-70b-versatile`, `qwen-2.5-32b`.
|
|
43
|
+
- **OpenRouter (Free Community Models)**: Free open models.
|
|
44
|
+
- **Deep Schema Introspection**:
|
|
45
|
+
- Auto-discovers tables, views, primary keys, foreign key relations, unique/composite indexes, nullability, defaults, comments, and row counts.
|
|
46
|
+
- Generates schema catalogs in Rich terminal tables, Markdown, or JSON.
|
|
47
|
+
- **Smart Script & Code Generation**:
|
|
48
|
+
- **Dialect-Specific SQL**: Joins, subqueries, CTEs, window functions.
|
|
49
|
+
- **Database Migrations**: Alembic (Python), Flyway, Prisma, raw SQL DDL.
|
|
50
|
+
- **ETL & Data Pipelines**: Python (Pandas/Polars/SQLAlchemy), CSV/JSON exporters.
|
|
51
|
+
- **Backend REST APIs**: FastAPI CRUD endpoints, Pydantic schemas.
|
|
52
|
+
- **Interactive Multi-Turn REPL & Safe Execution**:
|
|
53
|
+
- Multi-turn terminal chat with live database schema loaded in memory.
|
|
54
|
+
- Safe query dry-run and results preview with detection of destructive statements.
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## ๐ Quick Start
|
|
59
|
+
|
|
60
|
+
### 1. Installation
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
# Clone the repository
|
|
64
|
+
cd fearless-fermi
|
|
65
|
+
|
|
66
|
+
# Install dependencies and editable CLI package
|
|
67
|
+
pip install -e .
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### 2. Supported AI Providers (Zero Cost)
|
|
71
|
+
|
|
72
|
+
You can run DB-Agent using any free option:
|
|
73
|
+
|
|
74
|
+
| Provider | Type | Setup | Recommended Model |
|
|
75
|
+
|---|---|---|---|
|
|
76
|
+
| **Ollama** | 100% Local & Offline | Run `ollama serve` | `qwen2.5-coder` or `llama3.2` |
|
|
77
|
+
| **Google Gemini** | Free Cloud API | Get free key at [Google AI Studio](https://aistudio.google.com) | `gemini-2.0-flash` |
|
|
78
|
+
| **Groq** | Free Fast Cloud API | Get free key at [Groq Console](https://console.groq.com) | `llama-3.3-70b-versatile` |
|
|
79
|
+
| **OpenRouter** | Free Open Models | Get free key at [OpenRouter](https://openrouter.ai) | `meta-llama/llama-3.3-70b-instruct:free` |
|
|
80
|
+
|
|
81
|
+
Set keys via environment variables or use the interactive setup wizard:
|
|
82
|
+
```bash
|
|
83
|
+
# Interactive setup wizard
|
|
84
|
+
db-agent config
|
|
85
|
+
|
|
86
|
+
# Or set directly in your shell / .env file
|
|
87
|
+
export GEMINI_API_KEY="your-gemini-api-key"
|
|
88
|
+
# or
|
|
89
|
+
export GROQ_API_KEY="your-groq-api-key"
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## ๐ป CLI Commands & Usage
|
|
95
|
+
|
|
96
|
+
### 1. Connect & Save with an Alias (`connect` or `--alias`)
|
|
97
|
+
|
|
98
|
+
Save your connection credentials under an alias so you don't need to retype the URL each time:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
# Connect and save with an alias name
|
|
102
|
+
db-agent connect postgresql://user:password@localhost:5432/mydb --alias prod_db
|
|
103
|
+
|
|
104
|
+
# Connect to a local SQLite file with an alias
|
|
105
|
+
db-agent connect ecommerce_demo.db --alias my_shop
|
|
106
|
+
|
|
107
|
+
# Or scan and save alias in one step
|
|
108
|
+
db-agent scan --db postgresql://user:pass@localhost:5432/analytics --alias analytics_db
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
After saving with an alias, you can use that alias directly anywhere in place of the connection URL:
|
|
112
|
+
```bash
|
|
113
|
+
db-agent scan --db prod_db
|
|
114
|
+
db-agent chat --db prod_db
|
|
115
|
+
db-agent generate "Show total revenue this month" --db prod_db
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### 2. Introspect and Scan Database (`scan`)
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
# Scan a local SQLite database
|
|
122
|
+
db-agent scan --db ecommerce_demo.db
|
|
123
|
+
|
|
124
|
+
# Scan a PostgreSQL database
|
|
125
|
+
db-agent scan --db postgresql://user:password@localhost:5432/mydb
|
|
126
|
+
|
|
127
|
+
# Drill down into a specific table's columns and indexes
|
|
128
|
+
db-agent scan --db ecommerce_demo.db --table products
|
|
129
|
+
|
|
130
|
+
# Export schema catalog to JSON or Markdown
|
|
131
|
+
db-agent scan --db ecommerce_demo.db --export schema_catalog.md
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### 2. Generate Scripts & Code (`generate`)
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
# Generate an optimized SQL analytical query
|
|
138
|
+
db-agent generate "Calculate customer lifetime value and total orders per country" --db ecommerce_demo.db
|
|
139
|
+
|
|
140
|
+
# Generate a Python ETL script to export sales data to CSV
|
|
141
|
+
db-agent generate "Write a Pandas ETL script to export all completed orders to sales.csv" --db ecommerce_demo.db --type etl --output etl_export.py
|
|
142
|
+
|
|
143
|
+
# Generate a FastAPI CRUD backend for products and categories
|
|
144
|
+
db-agent generate "Generate FastAPI CRUD routes for products" --db ecommerce_demo.db --type api --output api_routes.py
|
|
145
|
+
|
|
146
|
+
# Generate an Alembic migration
|
|
147
|
+
db-agent generate "Add loyalty_points column to users table" --db ecommerce_demo.db --type migration
|
|
148
|
+
|
|
149
|
+
# Generate and execute SQL query directly (with safety checks)
|
|
150
|
+
db-agent generate "Find top 5 highest priced active products" --db ecommerce_demo.db --run
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### 3. Interactive Terminal Chat REPL (`chat`)
|
|
154
|
+
|
|
155
|
+
Start an interactive session with the database schema held in context:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
db-agent chat --db ecommerce_demo.db
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Inside the interactive chat:
|
|
162
|
+
- Ask questions: `> Show me total sales grouped by category`
|
|
163
|
+
- Execute last query: `> :run`
|
|
164
|
+
- Export last code: `> :export report_query.sql`
|
|
165
|
+
- View database tables: `> :tables`
|
|
166
|
+
- View single table detail: `> :table products`
|
|
167
|
+
- Exit session: `> :exit`
|
|
168
|
+
|
|
169
|
+
### 4. Execute Queries Safely (`run`)
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
db-agent run "SELECT username, country FROM users WHERE role = 'admin'" --db ecommerce_demo.db
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### 5. Manage Database Connection Profiles (`profiles`)
|
|
176
|
+
|
|
177
|
+
Save your database connection strings so you don't need to retype them:
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
db-agent config
|
|
181
|
+
# Prompts you to add a profile (e.g. 'analytics_prod', 'local_dev')
|
|
182
|
+
|
|
183
|
+
# List saved profiles
|
|
184
|
+
db-agent profiles
|
|
185
|
+
|
|
186
|
+
# Use saved profile in any command
|
|
187
|
+
db-agent scan --db analytics_prod
|
|
188
|
+
db-agent chat --db analytics_prod
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### 6. Check Available AI Models (`models`)
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
db-agent models
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## ๐งช Running Tests
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
pytest -v
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## ๐ Project Structure
|
|
208
|
+
|
|
209
|
+
```
|
|
210
|
+
.
|
|
211
|
+
โโโ pyproject.toml # Build config & dependencies
|
|
212
|
+
โโโ README.md # Documentation
|
|
213
|
+
โโโ scripts/
|
|
214
|
+
โ โโโ seed_demo_db.py # Realistic demo database generator
|
|
215
|
+
โโโ dbagent/
|
|
216
|
+
โ โโโ cli.py # Typer CLI application & REPL
|
|
217
|
+
โ โโโ config.py # Profile & credential manager
|
|
218
|
+
โ โโโ connectors/ # Universal database connectors
|
|
219
|
+
โ โ โโโ base.py # Abstract DB connector interface
|
|
220
|
+
โ โ โโโ relational.py # SQLAlchemy universal connector (PG, MySQL, SQLite, MSSQL, Oracle, DuckDB)
|
|
221
|
+
โ โ โโโ mongo.py # MongoDB introspector & sampling
|
|
222
|
+
โ โ โโโ factory.py # Connector factory
|
|
223
|
+
โ โโโ schema/ # Schema catalog & context builder
|
|
224
|
+
โ โ โโโ models.py # Pydantic schema data models
|
|
225
|
+
โ โ โโโ formatter.py # Markdown/compact schema formatters
|
|
226
|
+
โ โ โโโ selector.py # Smart table selector for large schemas
|
|
227
|
+
โ โโโ llm/ # 100% Free & Standalone LLM providers
|
|
228
|
+
โ โ โโโ base.py # Base LLM provider
|
|
229
|
+
โ โ โโโ ollama_provider.py # Local offline Ollama client
|
|
230
|
+
โ โ โโโ gemini_provider.py # Google Gemini Free API client
|
|
231
|
+
โ โ โโโ groq_provider.py # Groq Free API client
|
|
232
|
+
โ โ โโโ openrouter_provider.py # OpenRouter Free models
|
|
233
|
+
โ โ โโโ mock_provider.py # Offline fallback provider
|
|
234
|
+
โ โ โโโ factory.py # LLM provider factory
|
|
235
|
+
โ โโโ agent/ # AI Script Generation & Validation
|
|
236
|
+
โ โ โโโ generator.py # Prompt templates & generator engine
|
|
237
|
+
โ โ โโโ validator.py # SQL syntax & safety validator
|
|
238
|
+
โ โโโ ui/ # Rich terminal UI
|
|
239
|
+
โ โโโ console.py # Console banners, badges & code syntax
|
|
240
|
+
โ โโโ viewer.py # Rich schema visualizer tables
|
|
241
|
+
โโโ tests/ # Automated test suite (100% passing)
|
|
242
|
+
```
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
# โก DB-Agent
|
|
2
|
+
|
|
3
|
+
> **Universal Database Introspector & AI Script Generator CLI**
|
|
4
|
+
> *100% Free, Standalone, and runs with Local (Ollama) or Free Cloud AI models.*
|
|
5
|
+
|
|
6
|
+
`db-agent` connects to any database using provided credentials or connection URLs, introspects the complete schema (tables, columns, data types, primary/foreign keys, indexes, and sample values), and generates dialect-specific SQL queries, migrations, ETL data pipelines, and backend APIs from natural language instructions.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## ๐ Key Features
|
|
11
|
+
|
|
12
|
+
- **Universal Database Support**:
|
|
13
|
+
- **Relational**: PostgreSQL, MySQL, MariaDB, SQLite, Microsoft SQL Server (MSSQL), Oracle, DuckDB, Snowflake.
|
|
14
|
+
- **Document DBs**: MongoDB (schema inference via document sampling).
|
|
15
|
+
- **100% Free & Standalone AI Engine**:
|
|
16
|
+
- **Ollama (Local & Offline)**: Zero cost, private, runs on your machine (`qwen2.5-coder`, `llama3.2`, `deepseek-r1`, `mistral`).
|
|
17
|
+
- **Google Gemini (Free Tier)**: Direct access to `gemini-2.0-flash` & `gemini-1.5-flash`.
|
|
18
|
+
- **Groq (Free Ultra-Fast Tier)**: `llama-3.3-70b-versatile`, `qwen-2.5-32b`.
|
|
19
|
+
- **OpenRouter (Free Community Models)**: Free open models.
|
|
20
|
+
- **Deep Schema Introspection**:
|
|
21
|
+
- Auto-discovers tables, views, primary keys, foreign key relations, unique/composite indexes, nullability, defaults, comments, and row counts.
|
|
22
|
+
- Generates schema catalogs in Rich terminal tables, Markdown, or JSON.
|
|
23
|
+
- **Smart Script & Code Generation**:
|
|
24
|
+
- **Dialect-Specific SQL**: Joins, subqueries, CTEs, window functions.
|
|
25
|
+
- **Database Migrations**: Alembic (Python), Flyway, Prisma, raw SQL DDL.
|
|
26
|
+
- **ETL & Data Pipelines**: Python (Pandas/Polars/SQLAlchemy), CSV/JSON exporters.
|
|
27
|
+
- **Backend REST APIs**: FastAPI CRUD endpoints, Pydantic schemas.
|
|
28
|
+
- **Interactive Multi-Turn REPL & Safe Execution**:
|
|
29
|
+
- Multi-turn terminal chat with live database schema loaded in memory.
|
|
30
|
+
- Safe query dry-run and results preview with detection of destructive statements.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## ๐ Quick Start
|
|
35
|
+
|
|
36
|
+
### 1. Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# Clone the repository
|
|
40
|
+
cd fearless-fermi
|
|
41
|
+
|
|
42
|
+
# Install dependencies and editable CLI package
|
|
43
|
+
pip install -e .
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### 2. Supported AI Providers (Zero Cost)
|
|
47
|
+
|
|
48
|
+
You can run DB-Agent using any free option:
|
|
49
|
+
|
|
50
|
+
| Provider | Type | Setup | Recommended Model |
|
|
51
|
+
|---|---|---|---|
|
|
52
|
+
| **Ollama** | 100% Local & Offline | Run `ollama serve` | `qwen2.5-coder` or `llama3.2` |
|
|
53
|
+
| **Google Gemini** | Free Cloud API | Get free key at [Google AI Studio](https://aistudio.google.com) | `gemini-2.0-flash` |
|
|
54
|
+
| **Groq** | Free Fast Cloud API | Get free key at [Groq Console](https://console.groq.com) | `llama-3.3-70b-versatile` |
|
|
55
|
+
| **OpenRouter** | Free Open Models | Get free key at [OpenRouter](https://openrouter.ai) | `meta-llama/llama-3.3-70b-instruct:free` |
|
|
56
|
+
|
|
57
|
+
Set keys via environment variables or use the interactive setup wizard:
|
|
58
|
+
```bash
|
|
59
|
+
# Interactive setup wizard
|
|
60
|
+
db-agent config
|
|
61
|
+
|
|
62
|
+
# Or set directly in your shell / .env file
|
|
63
|
+
export GEMINI_API_KEY="your-gemini-api-key"
|
|
64
|
+
# or
|
|
65
|
+
export GROQ_API_KEY="your-groq-api-key"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## ๐ป CLI Commands & Usage
|
|
71
|
+
|
|
72
|
+
### 1. Connect & Save with an Alias (`connect` or `--alias`)
|
|
73
|
+
|
|
74
|
+
Save your connection credentials under an alias so you don't need to retype the URL each time:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# Connect and save with an alias name
|
|
78
|
+
db-agent connect postgresql://user:password@localhost:5432/mydb --alias prod_db
|
|
79
|
+
|
|
80
|
+
# Connect to a local SQLite file with an alias
|
|
81
|
+
db-agent connect ecommerce_demo.db --alias my_shop
|
|
82
|
+
|
|
83
|
+
# Or scan and save alias in one step
|
|
84
|
+
db-agent scan --db postgresql://user:pass@localhost:5432/analytics --alias analytics_db
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
After saving with an alias, you can use that alias directly anywhere in place of the connection URL:
|
|
88
|
+
```bash
|
|
89
|
+
db-agent scan --db prod_db
|
|
90
|
+
db-agent chat --db prod_db
|
|
91
|
+
db-agent generate "Show total revenue this month" --db prod_db
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### 2. Introspect and Scan Database (`scan`)
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
# Scan a local SQLite database
|
|
98
|
+
db-agent scan --db ecommerce_demo.db
|
|
99
|
+
|
|
100
|
+
# Scan a PostgreSQL database
|
|
101
|
+
db-agent scan --db postgresql://user:password@localhost:5432/mydb
|
|
102
|
+
|
|
103
|
+
# Drill down into a specific table's columns and indexes
|
|
104
|
+
db-agent scan --db ecommerce_demo.db --table products
|
|
105
|
+
|
|
106
|
+
# Export schema catalog to JSON or Markdown
|
|
107
|
+
db-agent scan --db ecommerce_demo.db --export schema_catalog.md
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### 2. Generate Scripts & Code (`generate`)
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
# Generate an optimized SQL analytical query
|
|
114
|
+
db-agent generate "Calculate customer lifetime value and total orders per country" --db ecommerce_demo.db
|
|
115
|
+
|
|
116
|
+
# Generate a Python ETL script to export sales data to CSV
|
|
117
|
+
db-agent generate "Write a Pandas ETL script to export all completed orders to sales.csv" --db ecommerce_demo.db --type etl --output etl_export.py
|
|
118
|
+
|
|
119
|
+
# Generate a FastAPI CRUD backend for products and categories
|
|
120
|
+
db-agent generate "Generate FastAPI CRUD routes for products" --db ecommerce_demo.db --type api --output api_routes.py
|
|
121
|
+
|
|
122
|
+
# Generate an Alembic migration
|
|
123
|
+
db-agent generate "Add loyalty_points column to users table" --db ecommerce_demo.db --type migration
|
|
124
|
+
|
|
125
|
+
# Generate and execute SQL query directly (with safety checks)
|
|
126
|
+
db-agent generate "Find top 5 highest priced active products" --db ecommerce_demo.db --run
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### 3. Interactive Terminal Chat REPL (`chat`)
|
|
130
|
+
|
|
131
|
+
Start an interactive session with the database schema held in context:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
db-agent chat --db ecommerce_demo.db
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Inside the interactive chat:
|
|
138
|
+
- Ask questions: `> Show me total sales grouped by category`
|
|
139
|
+
- Execute last query: `> :run`
|
|
140
|
+
- Export last code: `> :export report_query.sql`
|
|
141
|
+
- View database tables: `> :tables`
|
|
142
|
+
- View single table detail: `> :table products`
|
|
143
|
+
- Exit session: `> :exit`
|
|
144
|
+
|
|
145
|
+
### 4. Execute Queries Safely (`run`)
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
db-agent run "SELECT username, country FROM users WHERE role = 'admin'" --db ecommerce_demo.db
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### 5. Manage Database Connection Profiles (`profiles`)
|
|
152
|
+
|
|
153
|
+
Save your database connection strings so you don't need to retype them:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
db-agent config
|
|
157
|
+
# Prompts you to add a profile (e.g. 'analytics_prod', 'local_dev')
|
|
158
|
+
|
|
159
|
+
# List saved profiles
|
|
160
|
+
db-agent profiles
|
|
161
|
+
|
|
162
|
+
# Use saved profile in any command
|
|
163
|
+
db-agent scan --db analytics_prod
|
|
164
|
+
db-agent chat --db analytics_prod
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### 6. Check Available AI Models (`models`)
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
db-agent models
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## ๐งช Running Tests
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
pytest -v
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## ๐ Project Structure
|
|
184
|
+
|
|
185
|
+
```
|
|
186
|
+
.
|
|
187
|
+
โโโ pyproject.toml # Build config & dependencies
|
|
188
|
+
โโโ README.md # Documentation
|
|
189
|
+
โโโ scripts/
|
|
190
|
+
โ โโโ seed_demo_db.py # Realistic demo database generator
|
|
191
|
+
โโโ dbagent/
|
|
192
|
+
โ โโโ cli.py # Typer CLI application & REPL
|
|
193
|
+
โ โโโ config.py # Profile & credential manager
|
|
194
|
+
โ โโโ connectors/ # Universal database connectors
|
|
195
|
+
โ โ โโโ base.py # Abstract DB connector interface
|
|
196
|
+
โ โ โโโ relational.py # SQLAlchemy universal connector (PG, MySQL, SQLite, MSSQL, Oracle, DuckDB)
|
|
197
|
+
โ โ โโโ mongo.py # MongoDB introspector & sampling
|
|
198
|
+
โ โ โโโ factory.py # Connector factory
|
|
199
|
+
โ โโโ schema/ # Schema catalog & context builder
|
|
200
|
+
โ โ โโโ models.py # Pydantic schema data models
|
|
201
|
+
โ โ โโโ formatter.py # Markdown/compact schema formatters
|
|
202
|
+
โ โ โโโ selector.py # Smart table selector for large schemas
|
|
203
|
+
โ โโโ llm/ # 100% Free & Standalone LLM providers
|
|
204
|
+
โ โ โโโ base.py # Base LLM provider
|
|
205
|
+
โ โ โโโ ollama_provider.py # Local offline Ollama client
|
|
206
|
+
โ โ โโโ gemini_provider.py # Google Gemini Free API client
|
|
207
|
+
โ โ โโโ groq_provider.py # Groq Free API client
|
|
208
|
+
โ โ โโโ openrouter_provider.py # OpenRouter Free models
|
|
209
|
+
โ โ โโโ mock_provider.py # Offline fallback provider
|
|
210
|
+
โ โ โโโ factory.py # LLM provider factory
|
|
211
|
+
โ โโโ agent/ # AI Script Generation & Validation
|
|
212
|
+
โ โ โโโ generator.py # Prompt templates & generator engine
|
|
213
|
+
โ โ โโโ validator.py # SQL syntax & safety validator
|
|
214
|
+
โ โโโ ui/ # Rich terminal UI
|
|
215
|
+
โ โโโ console.py # Console banners, badges & code syntax
|
|
216
|
+
โ โโโ viewer.py # Rich schema visualizer tables
|
|
217
|
+
โโโ tests/ # Automated test suite (100% passing)
|
|
218
|
+
```
|