Skip to content

pb1803/NL2SQL-AI-Agent-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nl2sql_agent

NL2SQL Agent — a small C++ CLI that converts natural-language questions into SQL and executes them against a MySQL server (Connector/C++ X DevAPI). It integrates a Large Language Model (Gemini) to translate questions into SQL and prints formatted query results.

Features

  • Natural-language to SQL conversion using Gemini-compatible client
  • Executes queries using MySQL Connector/C++ X DevAPI (mysqlx)
  • Interactive CLI with database selection and query execution
  • Safe-by-default: reads secrets (DB password, API key) from environment variables

Requirements

  • C++17 toolchain (MSVC on Windows recommended)
  • CMake 3.20+
  • vcpkg-installed dependencies: libcurl, nlohmann-json, OpenSSL, MySQL Connector/C++ (X DevAPI)
  • MySQL server with X Plugin enabled (default port 33060)

Environment variables

  • GEMINI_API_KEY — Your Gemini API key (required)
  • DB_PASS — MySQL password for the DB_USER (required at runtime)

Quick start (Windows PowerShell)

# Set environment variables (temporary for this shell)
$env:GEMINI_API_KEY = 'your_gemini_key'
$env:DB_PASS = 'your_mysql_password'

# Build (out of source recommended)
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release

# Run
.\build\Release\nl2sql_agent.exe

When the agent starts, it lists available databases and prompts you to select one. Then type natural-language questions (e.g., "How many employees work in France?") and the agent will generate SQL and execute it against the selected database.

Development notes

  • The project uses mysqlx (Connector/C++ X DevAPI). If you installed via vcpkg, ensure vcpkg toolchain is used during CMake configure.
  • Secrets are intentionally read from environment variables for safety. Avoid committing credentials.

Next improvements (suggested)

  • Add confirmation step for destructive queries (DELETE/UPDATE/ALTER)
  • Add a mock/offline mode for unit testing SQL generation without an LLM or DB
  • Support OAuth-based Authorization header for Gemini if required

License

This repository has no license declared. Add LICENSE if you wish to make usage terms explicit.

About

NL2SQL Agent — a small C++ CLI that converts natural-language questions into SQL and executes them against a MySQL server (Connector/C++ X DevAPI). It integrates a Large Language Model (Gemini) to translate questions into SQL and prints formatted query results.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors