{"id":50870093,"url":"https://github.com/fadhlidev/text2sql","last_synced_at":"2026-06-15T04:30:50.641Z","repository":{"id":355197304,"uuid":"1227108950","full_name":"fadhlidev/text2sql","owner":"fadhlidev","description":"Secure natural language to SQL API with multi-database and multi-LLM support","archived":false,"fork":false,"pushed_at":"2026-05-02T10:17:26.000Z","size":62,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-02T12:13:29.262Z","etag":null,"topics":["golang","llm","sql"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fadhlidev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","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,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2026-05-02T08:04:10.000Z","updated_at":"2026-05-02T10:16:44.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/fadhlidev/text2sql","commit_stats":null,"previous_names":["fadhlidev/text2sql"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/fadhlidev/text2sql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fadhlidev%2Ftext2sql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fadhlidev%2Ftext2sql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fadhlidev%2Ftext2sql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fadhlidev%2Ftext2sql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fadhlidev","download_url":"https://codeload.github.com/fadhlidev/text2sql/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fadhlidev%2Ftext2sql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34348291,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-15T02:00:07.085Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["golang","llm","sql"],"created_at":"2026-06-15T04:30:50.164Z","updated_at":"2026-06-15T04:30:50.635Z","avatar_url":"https://github.com/fadhlidev.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Text2SQL\n\nText2SQL is a powerful, secure, and multi-dialect API that converts natural language questions into executable SQL queries. It automatically introspects your database schema and uses advanced LLMs to generate precise, read-only queries with natural language explanations.\n\n## Features\n\n- **Multi-Dialect Support**: Works with PostgreSQL, MySQL, and SQLite.\n- **Multi-LLM Agnostic**: Supports OpenAI, Anthropic (Claude), Google Gemini, and Azure OpenAI.\n- **Views \u0026 Stored Procedures**: Automatically detects and utilizes database Views and Functions/Procedures in query generation.\n- **Explainable SQL**: Every generated query includes a natural language explanation of how it works.\n- **Performance Caching**: Built-in caching layer supporting **Redis** and **In-Memory** backends to reduce LLM costs and latency.\n- **Security First**: \n  - Strictly enforces `SELECT` / `WITH` queries only.\n  - Blocklist for dangerous keywords (DROP, DELETE, etc.).\n  - Hard 10-second query timeout.\n- **Automatic Introspection**: Automatically reads your tables and columns—no manual schema definition required.\n- **Production Ready**: Minimal Docker image (~15MB) and Fiber-powered REST API.\n\n## Installation\n\n### Using Nix (Recommended)\n```bash\nnix develop\ngo run main.go\n```\n\n### Using Docker\n```bash\ndocker build -t text2sql .\ndocker run -p 3000:3000 --env-file .env text2sql\n```\n\n## Configuration\n\nThe application is configured entirely via environment variables. Create a `.env` file in the root directory:\n\n### 1. Database Configuration\n| Variable | Description | Example |\n|----------|-------------|---------|\n| `DB_URI` | Connection string | `postgres://user:pass@localhost:5432/db` |\n\n*Dialect is automatically inferred from the URI prefix (`postgres`, `mysql`, or `sqlite`).*\n\n### 2. LLM Configuration\n| Variable | Description | Options |\n|----------|-------------|---------|\n| `LLM_PROVIDER` | The AI provider to use | `openai`, `anthropic`, `gemini`, `azure-openai` |\n| `LLM_MODEL` | Specific model ID | `gpt-4o`, `claude-3-5-sonnet-20240620`, etc. |\n\n#### Provider-Specific Keys\n- **OpenAI**: `OPENAI_API_KEY`\n- **Anthropic**: `ANTHROPIC_API_KEY`\n- **Gemini**: `GEMINI_API_KEY`\n- **Azure OpenAI**: `AZURE_OPENAI_API_KEY`, `AZURE_OPENAI_ENDPOINT`, `AZURE_OPENAI_DEPLOYMENT_ID`\n\n### 3. Caching Configuration\n| Variable | Description | Example |\n|----------|-------------|---------|\n| `REDIS_URI` | Redis connection string | `redis://localhost:6379` |\n\n*If `REDIS_URI` is not provided, the application falls back to an auto-cleaning in-memory cache.*\n\n## API Usage\n\n### `POST /query`\nConvert a question to SQL and execute it.\n\n**Request Body:**\n```json\n{\n  \"question\": \"how many customers joined last month?\"\n}\n```\n\n**Response (Success):**\n```json\n{\n  \"sql\": \"SELECT COUNT(*) FROM customers WHERE created_at \u003e '2026-04-01' LIMIT 100\",\n  \"explanation\": \"I am counting the total number of records in the customers table where the creation date is within the last month.\",\n  \"result\": [\n    { \"count\": 142 }\n  ]\n}\n```\n\n**Response (Error):**\n```json\n{\n  \"error\": \"unanswerable: no column 'joined_at' found in table 'customers'\",\n  \"stage\": \"generate\"\n}\n```\n\n### `GET /health`\nReturns `{\"status\": \"ok\"}`.\n\n## Development\n\nSee [CONTRIBUTING.md](./CONTRIBUTING.md) for details on setting up the development environment and running tests.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffadhlidev%2Ftext2sql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffadhlidev%2Ftext2sql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffadhlidev%2Ftext2sql/lists"}