Skip to content
This repository was archived by the owner on Dec 29, 2023. It is now read-only.

Commit aac22f1

Browse files
authored
Basic HTTP query server
1 parent 96e0052 commit aac22f1

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Diff for: main.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from flask import Flask, request
2+
import chdb
3+
4+
app = Flask(__name__, static_folder="public", static_url_path="")
5+
6+
@app.route('/', methods=["GET"])
7+
def clickhouse():
8+
query = request.args.get('query', default="", type=str)
9+
format = request.args.get('default_format', default="CSV", type=str)
10+
if not query:
11+
return app.send_static_file('play.html')
12+
13+
res = chdb.query(query, format)
14+
return res.get_memview().tobytes()
15+
16+
@app.route('/', methods=["POST"])
17+
def play():
18+
query = request.data
19+
format = request.args.get('default_format', default="CSV", type=str)
20+
if not query:
21+
return app.send_static_file('play.html')
22+
23+
res = chdb.query(query, format)
24+
return res.get_memview().tobytes()
25+
26+
@app.errorhandler(404)
27+
def handle_404(e):
28+
return app.send_static_file('play.html')
29+
30+
app.run(host="0.0.0.0", port=8123)

0 commit comments

Comments
 (0)