ChatDB is a TypeScript-based AI-powered SQL assistant that retrieves context from a database schema and executes only SELECT
queries. It helps users interact with SQL databases efficiently using natural language, ensuring data safety by not performing any modifications (e.g., INSERT
, UPDATE
, DELETE
).
- SQL Schema Parsing – Extracts context from the database schema.
- AI-Powered Query Execution – Generates and runs
SELECT
queries. - Read-Only Mode – Ensures no modifications to the database.
- TypeScript Support – Ensures type safety and maintainability.
- Customizable Environment – Configure database connections easily.
Follow these steps to set up and run ChatDB locally.
git clone https://github.com/sleemkeen/chatdb.git
cd chatdb
2️⃣ Install Dependencies
npm install
3️⃣ Configure Environment Variables
Copy the example .env file and update it with your credentials.
cp .env.example .env
Make sure to set your read-only database connection details (e.g., DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) in the .env file.
⚠️ Important:
ChatDB only runs SELECT queries and does not modify the database.
Provide read-only access to the database to prevent unauthorized modifications.
4️⃣ Add Your SQL Schema Dump
For ChatDB to understand your database structure, you need to add your SQL schema dump to:
src/service/sql.ts
Example schema dump:
# Dump of table users
# ------------------------------------------------------------
CREATE TABLE users (
id bigint unsigned NOT NULL AUTO_INCREMENT,
first_name varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
last_name varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
username varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
referrer_code varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
email varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
password varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
phone_number varchar(25) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE KEY users_referrer_code_unique (referrer_code)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
This helps ChatDB understand the database structure before generating queries
5️⃣ (Optional) Add Your Company Information
You can optionally add details about your company to improve the context of generated queries.
Edit the aboutCompany variable in:
src/service/prompts.ts
Example:
const aboutCompany = `
Our company, Acme Corp, is a leading provider of AI-powered data solutions.
We specialize in real-time analytics and enterprise database management.
`;
This helps personalize the responses generated by ChatDB.
6️⃣ Start the Application
Run the following command to start the service:
npm run chatDB
📜 License
This project is licensed under the MIT License.
🤝 Contributing
Contributions are welcome! Feel free to open an issue or submit a pull request.