|
| 1 | +# SQL Query Builder - Automatizador de Queries Multi-Database |
| 2 | + |
| 3 | +[](https://golang.org/doc/go1.20) |
| 4 | +[](https://www.python.org/downloads/) |
| 5 | +[](https://opensource.org/licenses/MIT) |
| 6 | + |
| 7 | +Um sistema robusto para automatizar a construção e execução de queries SQL em diferentes bancos de dados, com suporte especial para sistemas legados. |
| 8 | +O projeto utiliza Python (Flask/SQLAlchemy) no backend e Go no frontend. |
| 9 | + |
| 10 | +## 📋 Índice |
| 11 | + |
| 12 | +- [Características](#características) |
| 13 | +- [Requisitos](#requisitos) |
| 14 | +- [Instalação](#instalação) |
| 15 | +- [Configuração](#configuração) |
| 16 | +- [Uso](#uso) |
| 17 | +- [Exemplos](#exemplos) |
| 18 | +- [Contribuição](#contribuição) |
| 19 | +- [Licença](#licença) |
| 20 | + |
| 21 | +## ✨ Características |
| 22 | + |
| 23 | +### Backend (Python) |
| 24 | +- Suporte multi-database (MySQL, PostgreSQL, Oracle, SQL Server) |
| 25 | +- Construção dinâmica de queries com múltiplos JOINs |
| 26 | +- Pool de conexões para melhor performance |
| 27 | +- Tratamento robusto de erros |
| 28 | +- Logging configurável |
| 29 | +- Validação de dados via dataclasses |
| 30 | +- Suporte a queries complexas (WHERE, GROUP BY, ORDER BY, LIMIT) |
| 31 | + |
| 32 | +### Frontend (Go) |
| 33 | +- Interface tipo-segura para configuração de queries |
| 34 | +- Timeout configurável para requisições |
| 35 | +- Tratamento elegante de erros |
| 36 | +- Formatação automática dos resultados |
| 37 | + |
| 38 | +## 📦 Requisitos |
| 39 | + |
| 40 | +### Backend |
| 41 | +- Python 3.8+ |
| 42 | +- Flask |
| 43 | +- SQLAlchemy |
| 44 | +- Drivers de banco de dados específicos: |
| 45 | + - MySQL: `pymysql` |
| 46 | + - PostgreSQL: `psycopg2-binary` |
| 47 | + - Oracle: `cx-oracle` |
| 48 | + - SQL Server: `pyodbc` |
| 49 | + |
| 50 | +### Frontend |
| 51 | +- Go 1.20+ |
| 52 | +- Sem dependências externas além da biblioteca padrão |
| 53 | + |
| 54 | + |
| 55 | +## 🚀 Instalação |
| 56 | + |
| 57 | +1. Clone o repositório: |
| 58 | +```bash |
| 59 | +git clone https://github.com/bulletdev/sql-query-builder.git |
| 60 | +cd sql-query-builder |
| 61 | +``` |
| 62 | + |
| 63 | +2. Configure o ambiente virtual Python e instale as dependências: |
| 64 | +```bash |
| 65 | +cd backend |
| 66 | +python -m venv venv |
| 67 | +source venv/bin/activate |
| 68 | +pip install -r requirements.txt |
| 69 | +``` |
| 70 | +>> No Windows: |
| 71 | +
|
| 72 | +```bash |
| 73 | +cd backend |
| 74 | +python -m venv venv |
| 75 | +source venv\Scripts\activate |
| 76 | +pip install -r requirements.txt |
| 77 | +``` |
| 78 | + |
| 79 | +3. Configure o ambiente Go: |
| 80 | +```bash |
| 81 | +cd ../frontend |
| 82 | +go mod tidy |
| 83 | +``` |
| 84 | + |
| 85 | +## ⚙️ Configuração |
| 86 | + |
| 87 | +1. Copie o arquivo de configuração de exemplo: |
| 88 | +```bash |
| 89 | +cp backend/config.yml.example backend/config.yml |
| 90 | +``` |
| 91 | + |
| 92 | +2. Edite `config.yml` com suas configurações de banco de dados: |
| 93 | +```yaml |
| 94 | +databases: |
| 95 | + mysql: |
| 96 | + host: localhost |
| 97 | + port: 3306 |
| 98 | + pool_size: 5 |
| 99 | + timeout: 30 |
| 100 | + oracle: |
| 101 | + host: localhost |
| 102 | + port: 1521 |
| 103 | + pool_size: 5 |
| 104 | + timeout: 30 |
| 105 | +``` |
| 106 | +
|
| 107 | +## 💻 Uso |
| 108 | +
|
| 109 | +1. Inicie o backend: |
| 110 | +```bash |
| 111 | +cd backend |
| 112 | +python src/app.py |
| 113 | +``` |
| 114 | + |
| 115 | +2. Em outro terminal, execute o frontend: |
| 116 | +```bash |
| 117 | +cd frontend |
| 118 | +go run cmd/main.go |
| 119 | +``` |
| 120 | + |
| 121 | +## 📝 Exemplos |
| 122 | + |
| 123 | +### Consulta básica com JOIN (Go) |
| 124 | +```go |
| 125 | +config := QueryConfig{ |
| 126 | + DbType: "mysql", |
| 127 | + MainTable: "TGFCAB", |
| 128 | + Columns: []string{"TGFCAB.NUNOTA", "TGFPAR.NOMEPARC"}, |
| 129 | + Joins: []JoinCondition{ |
| 130 | + { |
| 131 | + Table: "TGFPAR", |
| 132 | + LeftColumn: "CODPARC", |
| 133 | + RightColumn: "CODPARC", |
| 134 | + JoinType: "left", |
| 135 | + }, |
| 136 | + }, |
| 137 | +} |
| 138 | +``` |
| 139 | + |
| 140 | +### Consulta com condições e ordenação (Python) |
| 141 | +```python |
| 142 | +query_config = QueryConfig( |
| 143 | + db_type="oracle", |
| 144 | + main_table="TGFCAB", |
| 145 | + columns=["NUNOTA", "DTNEG"], |
| 146 | + conditions=[{"expression": "DTNEG >= '2024-01-01'"}], |
| 147 | + order_by=["DTNEG DESC"], |
| 148 | + limit=100 |
| 149 | +) |
| 150 | +``` |
| 151 | + |
| 152 | +## 🤝 Contribuição |
| 153 | + |
| 154 | +1. Faça um Fork do projeto |
| 155 | +2. Crie sua Feature Branch (`git checkout -b feature/AmazingFeature`) |
| 156 | +3. Commit suas mudanças (`git commit -m 'Add some AmazingFeature'`) |
| 157 | +4. Push para a Branch (`git push origin feature/AmazingFeature`) |
| 158 | +5. Abra um Pull Request |
| 159 | + |
| 160 | +## 📄 Licença |
| 161 | + |
| 162 | +Este projeto está licenciado sob a Licença MIT - veja o arquivo [LICENSE](LICENSE) para detalhes. |
0 commit comments