Skip to content

Commit

Permalink
UPDATES
Browse files Browse the repository at this point in the history
  • Loading branch information
Anantha Raju C committed Mar 24, 2024
1 parent c3d5222 commit cb821b7
Show file tree
Hide file tree
Showing 14 changed files with 175 additions and 148 deletions.
63 changes: 54 additions & 9 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,80 @@

This application comes with the following out-of-the-box API's.

### Execute SQL
### List DB Connections

| URL | Method | Remarks | Sample Valid Request Body |
|--------------------------------------------------------------------|--------|--------------------------|---------------------------|
|`http://localhost:5000/connections` | GET |List DB Connections. | None |

### Create/Update DB Connections

| URL | Method | Remarks | Sample Valid Request Body |
|--------------------------------------------------------------------|--------|-----------------------------|---------------------------|
|`http://localhost:5000/connections` | PATCH |Create/Update DB Connections.| [JSON](#connections) |

~~~json
{
"connections": {
"localhost-test": {
"database": "test1",
"db": "test2",
"host": "localhost",
"password": "1",
"user": "default1"
}
}
}
~~~

---

### Execute SQL Directly from an endpoint

Execute SQL passed via the endpoint.

| URL | Method | Remarks | Sample Valid Request Body |
|--------------------------------------------------------------------|--------|--------------------------|---------------------------|
|`http://localhost:5000/execute_sql?format=json` | POST |Direct SQL execution. | [JSON](#login) |
|`http://localhost:5000/execute_sql?format=json&page_size=5&page=1` | POST |Direct SQL execution. | [JSON](#api) |

~~~json
{
"sql": "SELECT * FROM streaming_etl_db.geo;"
"sql": "SELECT * FROM sakila.film_category;",
"connection_name": "localhost-mysql"
}
~~~

**Supported Formats:** *xml, json, csv, tsv, xlsx*

---

### Save SQL

Save SQL to a file to be called at a later point in time.

| URL | Method | Remarks | Sample Valid Request Body |
|--------------------------------------------------------------------|--------|--------------------------|---------------------------|
|`http://localhost:5000/save_sql_to_file` | POST |Save sql to a file. | [JSON](#login) |
|`http://localhost:5000/save_sql_to_file` | PATCH |Save sql to a file. | [JSON](#login) |

~~~json
{
"sql": "SELECT * FROM sakila.actor",
"filename": "phn.sql"
"sql_query": "SELECT id FROM sakila.film_category;",
"author": "anantha",
"description": "clickhouse 22 test doc",
"tags": "test,prod",
"filename": "clickhouse query for sfc updated3.",
"query_parameters": {},
"status": "active",
"execution_history": []
}
~~~

http://localhost:5000/list_files?sort_by=name&sort_order=desc
http://localhost:5000/list_files?sort_by=datetime&sort_order=asc
http://localhost:5000/list_files?sort_by=datetime&sort_order=desc
### List Saved SQL Files

| URL | Method | Remarks | Sample Valid Request Body |
|--------------------------------------------------------------------|--------|--------------------------|---------------------------|
|`http://localhost:5000/list_files?sort_by=name&sort_order=desc` | Get | List saved Files. | |

---


30 changes: 25 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,36 @@
-->
# SQL2API

SQL to API

A Python Flask application that interacts with database to execute SQL queries and return the results in the following formats

| Database | JSON | CSV | TSV | XML | YAML | XLSX |
|----------|------|-----|-----|-----|------|------|
| MySQL |||||||
| Database | JSON | CSV | TSV | XML | YAML | XLSX |
|---------------|------|-----|-----|-----|------|------|
| MySQL |||||||
| ClickHouse | ||| | | |

Additionally, it provides endpoints for saving SQL queries to files, executing SQL queries from files, and executing SQL queries with parameters from files.

<div align="center">

[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen?logo=github)](CODE_OF_CONDUCT.md) [![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=Checkout+this+sql+to+api+application&url=https://github.com/AnanthaRajuC/SQL2API&hashtags=Python) [![Twitter Follow](https://img.shields.io/twitter/follow/anantharajuc?label=follow%20me&style=social)](https://twitter.com/anantharajuc)
</div>

<div align="center">
<sub>Built with ❤︎ by <a href="https://twitter.com/anantharajuc">Anantha Raju C</a> and <a href="https://github.com/AnanthaRajuC/SQL2API/graphs/contributors">contributors</a>
</div>

</br>

<p align="center">
<a href="https://github.com/AnanthaRajuC/SQL2API/blob/master/README.md#spring-boot-application-templatestarter-project-"><strong>Explore the docs »</strong></a>
<br />
<br />
<a href="https://github.com/AnanthaRajuC/SQL2API/issues">Report Bug</a>
·
<a href="https://github.com/AnanthaRajuC/SQL2API/issues">Request Feature</a>
</p>


## Reporting Issues/Suggest Improvements

This Project uses GitHub's integrated issue tracking system to record bugs and feature requests. If you want to raise an issue, please follow the recommendations below:
Expand Down
2 changes: 1 addition & 1 deletion SQL2API.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,4 +450,4 @@ def execute_sql_from_file():
return jsonify({'message': 'No results returned'})

if __name__ == '__main__':
app.run(debug=True)
app.run(debug=True)
29 changes: 20 additions & 9 deletions db_connections.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
{
"connections": {
"connection1": {
"localhost-mysql": {
"database": "streaming_etl_db",
"db": "mysql",
"host": "localhost",
"password": "password",
"user": "admin"
},
"connection2": {
"localhost-clickhouse": {
"database": "sakila",
"db": "clickhouse",
"host": "localhost",
"user": "user2",
"password": "password2",
"database": "database2"
"password": "root",
"user": "default"
},
"connection222": {
"database": "database222",
"host": "localhost",
"password": "password2",
"user": "user2"
"user": "user2",
"db": "mongodb"
},
"connection333": {
"database": "dbrrrr",
"host": "localhosggggggggggggt",
"database": "mycollection",
"host": "localhost",
"password": "passwogggggggggrd2",
"user": "user2"
"user": "user2",
"db": "ww"
},
"localhost-test": {
"database": "test1",
"db": "test2",
"host": "localhost",
"password": "1",
"user": "default1"
}
}
}
15 changes: 0 additions & 15 deletions saved_sql/aaa.json

This file was deleted.

28 changes: 0 additions & 28 deletions saved_sql/ccc.json

This file was deleted.

15 changes: 15 additions & 0 deletions saved_sql/clickhouse query for sfc updated..json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"1": {
"uuid": "a59bb316-ba0c-4799-80cd-0048641a2942",
"sql_query": "SELECT id FROM sakila.film_category;",
"author": "anantha",
"description": "clickhouse 2",
"tags": "test,prod",
"query_parameters": {},
"created_at": "2024-03-24 12:36:29",
"last_modified_at": "2024-03-24 12:36:29",
"status": "active",
"version": 1,
"execution_history": []
}
}
15 changes: 15 additions & 0 deletions saved_sql/clickhouse query for sfc updated1..json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"1": {
"uuid": "c3757128-019a-49db-8896-c8740b123f38",
"sql_query": "SELECT id FROM sakila.film_category;",
"author": "anantha",
"description": "clickhouse 22",
"tags": "test,prod",
"query_parameters": {},
"created_at": "2024-03-24 16:20:08",
"last_modified_at": "2024-03-24 16:20:08",
"status": "active",
"version": 1,
"execution_history": []
}
}
15 changes: 15 additions & 0 deletions saved_sql/clickhouse query for sfc updated2..json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"1": {
"uuid": "ae9354f5-4613-4fd8-8e5a-22797cf54580",
"sql_query": "SELECT id FROM sakila.film_category;",
"author": "anantha",
"description": "clickhouse 22",
"tags": "test,prod",
"query_parameters": {},
"created_at": "2024-03-24 16:20:15",
"last_modified_at": "2024-03-24 16:20:15",
"status": "active",
"version": 1,
"execution_history": []
}
}
15 changes: 15 additions & 0 deletions saved_sql/clickhouse query for sfc updated3..json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"1": {
"uuid": "9838b79f-e79f-4e02-9e24-892187e7544b",
"sql_query": "SELECT id FROM sakila.film_category;",
"author": "anantha",
"description": "clickhouse 22 test doc",
"tags": "test,prod",
"query_parameters": {},
"created_at": "2024-03-24 17:07:01",
"last_modified_at": "2024-03-24 17:07:01",
"status": "active",
"version": 1,
"execution_history": []
}
}
15 changes: 15 additions & 0 deletions saved_sql/clickhouse query for sfc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"1": {
"uuid": "8ff6edf9-cfde-4d9a-8a54-cbc1dd397bd3",
"sql_query": "SELECT * FROM sakila.film_category;",
"author": "anantha",
"description": "clickhouse 1",
"tags": "test,prod",
"query_parameters": {},
"created_at": "2024-03-24 12:34:05",
"last_modified_at": "2024-03-24 12:34:05",
"status": "active",
"version": 1,
"execution_history": []
}
}
28 changes: 0 additions & 28 deletions saved_sql/ddd.json

This file was deleted.

14 changes: 0 additions & 14 deletions saved_sql/jkl.json

This file was deleted.

Loading

0 comments on commit cb821b7

Please sign in to comment.