{"id":27726390,"url":"https://github.com/nextgengk/chatdb-server","last_synced_at":"2026-05-09T14:10:04.993Z","repository":{"id":289515516,"uuid":"971521082","full_name":"NextGenGk/ChatDB-Server","owner":"NextGenGk","description":"ChatDBServer - Your Personal Database Assistant","archived":false,"fork":false,"pushed_at":"2025-04-24T16:31:36.000Z","size":40,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-27T22:57:16.773Z","etag":null,"topics":["cloud","data-science","javascript","nodejs","opena","openrouter-api","postgres","react","render","server","webapplication"],"latest_commit_sha":null,"homepage":"https://chatdb-server.onrender.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NextGenGk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-23T16:41:03.000Z","updated_at":"2025-04-24T16:31:39.000Z","dependencies_parsed_at":"2025-04-23T17:46:50.242Z","dependency_job_id":"510ab7b2-b2f3-4f73-be39-46d8318240e6","html_url":"https://github.com/NextGenGk/ChatDB-Server","commit_stats":null,"previous_names":["nextgengk/chatdb-server"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NextGenGk%2FChatDB-Server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NextGenGk%2FChatDB-Server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NextGenGk%2FChatDB-Server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NextGenGk%2FChatDB-Server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NextGenGk","download_url":"https://codeload.github.com/NextGenGk/ChatDB-Server/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251219824,"owners_count":21554455,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloud","data-science","javascript","nodejs","opena","openrouter-api","postgres","react","render","server","webapplication"],"created_at":"2025-04-27T22:57:20.550Z","updated_at":"2026-05-09T14:10:04.942Z","avatar_url":"https://github.com/NextGenGk.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PostgreSQL Natural Language Query API\n\nThis project provides a RESTful API service that allows users to query PostgreSQL databases using natural language. The system leverages AI to transform natural language requests into valid SQL queries.\n\n## Features\n\n- 🔍 Query PostgreSQL databases using natural language\n- 🗄️ Create databases and tables via dedicated endpoints\n- 👥 User management functionality (CRUD operations)\n- 🧠 AI-powered natural language to SQL conversion via OpenRouter API\n- 📊 Schema introspection for context-aware SQL generation\n\n## Prerequisites\n\n- Node.js (v14+)\n- PostgreSQL server\n- OpenRouter API key\n\n## Installation\n\n### Step 1: Clone the repository\n\n```bash\ngit clone https://github.com/yourusername/postgres-nl-query-api.git\ncd postgres-nl-query-api\n```\n\n### Step 2: Install dependencies\n\n```bash\nnpm install\n```\n\n### Step 3: Set up environment variables\n\nCreate a `.env` file in the project root directory:\n\n```bash\ncp .env.example .env\n```\n\nEdit the `.env` file with your database credentials and API key:\n\n```\n# PostgreSQL Configuration\nDB_HOST=localhost\nDB_PORT=5432\nDB_USER=postgres\nDB_PASSWORD=your_password\nDB_NAME=your_default_database\n\n# API Keys\nOPENROUTER_API_KEY=your_openrouter_api_key\n\n# Server Configuration\nPORT=5000\n```\n\n### Step 4: Start the server\n\n```bash\nnode index.js\n```\n\nThe server will start on port 5000 (or the port specified in your `.env` file).\n\n## Project Structure\n\n```\n├── index.js           # Main application entry point\n├── db.js              # Database connection and operations\n├── openrouter.js      # OpenRouter API integration\n├── .env               # Environment variables (create from .env.example)\n├── .env.example       # Environment variables template\n└── README.md          # Project documentation\n```\n\n## API Endpoints\n\n### Base URL\n\n```\nhttp://localhost:5000\n```\n\n### Basic Endpoints\n\n| Method | Endpoint | Description |\n|--------|----------|-------------|\n| GET | / | Check if the server is running |\n| GET | /data | Fetch all users from the database |\n| POST | /add-user | Add a new user to the database |\n\n### Natural Language Query\n\n| Method | Endpoint | Description |\n|--------|----------|-------------|\n| POST | /natural-language | Execute a natural language query |\n\n**Request Body:**\n```json\n{\n  \"command\": \"Show me all users older than 25\"\n}\n```\n\n**Response:**\n```json\n{\n  \"sql\": \"SELECT * FROM users WHERE age \u003e 25;\",\n  \"operationType\": \"read\",\n  \"result\": [\n    {\n      \"id\": 1,\n      \"name\": \"John Doe\",\n      \"email\": \"john@example.com\",\n      \"age\": 30\n    }\n  ],\n  \"rowCount\": 1\n}\n```\n\n### Database Management\n\n| Method | Endpoint | Description |\n|--------|----------|-------------|\n| POST | /create-database | Create a new database with optional tables |\n| POST | /extract-create-tables | Extract table creation statements from SQL |\n\n**Request Body for /create-database:**\n```json\n{\n  \"dbName\": \"analysis\",\n  \"tables\": [\n    \"CREATE TABLE market (id SERIAL PRIMARY KEY, name VARCHAR(255), value NUMERIC);\"\n  ]\n}\n```\n\n**Response:**\n```json\n{\n  \"message\": \"Database 'analysis' created successfully with specified tables\"\n}\n```\n\n## Usage Examples\n\n### Creating a Database with Tables\n\n```bash\ncurl -X POST http://localhost:5000/create-database \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"dbName\": \"analytics\", \"tables\": [\"CREATE TABLE metrics (id SERIAL PRIMARY KEY, name VARCHAR(255), value NUMERIC);\"]}'\n```\n\n### Querying with Natural Language\n\n```bash\ncurl -X POST http://localhost:5000/natural-language \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"command\": \"Find all users with gmail email addresses\"}'\n```\n\n### Adding a New User\n\n```bash\ncurl -X POST http://localhost:5000/add-user \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"name\": \"Jane Smith\", \"email\": \"jane@example.com\", \"age\": 28}'\n```\n\n## Implementation Notes\n\n### Database Operations (db.js)\n\nThe `db.js` module handles all database-related operations:\n\n- Creating database connections\n- Executing SQL queries\n- Retrieving schema information\n- Creating databases and tables\n\n### OpenRouter Integration (openrouter.js)\n\nThe `openrouter.js` module manages interactions with the OpenRouter API:\n\n- Converting natural language to SQL\n- Analyzing SQL query types\n- Detecting unsupported operations (like CREATE DATABASE within transactions)\n\n### Main Application (index.js)\n\nThe `index.js` file sets up the Express server and API routes:\n\n- Configuring middleware\n- Managing HTTP requests and responses\n- Coordinating between the database and OpenRouter services\n\n## Error Handling\n\nThe API provides detailed error messages to help diagnose issues:\n\n- Database connection problems\n- SQL execution errors\n- Natural language processing failures\n- Input validation errors\n\n## Limitations\n\n- CREATE DATABASE commands cannot be executed within transactions in PostgreSQL\n- Complex joins or very specialized SQL features might need manual refinement\n- Performance depends on the OpenRouter API response time\n\n## License\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnextgengk%2Fchatdb-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnextgengk%2Fchatdb-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnextgengk%2Fchatdb-server/lists"}