Database Agent is a Node.js application that intelligently generates SQL queries and interacts with your database to fetch, filter, and deliver data on demand. It streamlines data access by translating user requests into optimized SQL commands, enabling seamless integration and automation.
Follow these steps to run the app locally.
git clone https://github.com/minhajul/database-agent.git
cd database-agent
npm install
We're using Docker Compose to run the PostgreSQL database. Simply start Docker and run the command below to get your database up and running.
docker-compose up --build -d
Run this cp .env.example .env
command to create a .env
file with the example from .env.example
:
DATABASE_URL=postgresql://admin:admin@localhost:5431/postgres
AZURE_OPENAI_ENDPOINT=
AZURE_OPENAI_DEPLOYMENT=
AZURE_OPENAI_API_KEY=
AZURE_API_VERSION=
Also, run the below command to migrate the database:
npm run generate
npm run migrate
We're using Drizzle to interact with the PostgreSQL database. To modify the database schema, update schema.js
and run npm run migrate
to apply the changes.
npm run start
Send a POST request to api/database-agents
endpoint with a natural language query:
{
"prompt": "give me the total number of users."
}
Response:
{
"status": "ok",
"data": {
"success": true,
"data": {
"command": "SELECT",
"rowCount": 1,
"oid": null,
"rows": [
{
"count": "10"
}
]
}
}
}