diff --git a/README.md b/README.md index 137deeb..1b7203d 100644 --- a/README.md +++ b/README.md @@ -5,16 +5,9 @@ [![.github/workflows/release.yml](https://github.com/chdb-io/chdb-server/actions/workflows/release.yml/badge.svg)](https://github.com/chdb-io/chdb-server/actions/workflows/release.yml) # chdb-server -[chDB](https://github.com/auxten/chdb) + basic API server in a docker container, for fast testing and feature validation. - -> chdb-server queries default to stateless. Stateful sessions can be generated with Basic HTTP Auth. - -![image](https://github.com/chdb-io/chdb-server/assets/1423657/dee938a2-ec2a-4b4a-87a9-458a6db791a0) - - - -### [Play with Public Demo](https://chdb.fly.dev/) +[chDB](https://github.com/auxten/chdb) + basic HTTP/s API server in a docker container, _pretending to be ClickHouse_ +### [Public Demo](https://chdb.fly.dev/)
@@ -25,13 +18,21 @@

-### Docker Demo +### Docker Setup ``` docker run --rm -p 8123:8123 ghcr.io/chdb-io/chdb-server:latest ```
+### Stateless & Stateful Sessions + +> chdb-server queries default to stateless. Stateful sessions can be paired with Basic HTTP Auth. + +![image](https://github.com/chdb-io/chdb-server/assets/1423657/dee938a2-ec2a-4b4a-87a9-458a6db791a0) + +
+ ### ClickHouse Play chdb-server is compatible with the ClickHouse Play query interface: diff --git a/main.py b/main.py index bb57fb5..2c0e3c3 100644 --- a/main.py +++ b/main.py @@ -56,7 +56,7 @@ def clickhouse(): if database: query = f"USE {database}; {query}".encode() - result, errmsg = chdb_query_with_errmsg(query, format) + result, errmsg = chdb_query_with_errmsg(query.strip(), format) if len(errmsg) == 0: return result, 200 return errmsg, 400 @@ -64,18 +64,18 @@ def clickhouse(): @app.route('/', methods=["POST"]) @auth.login_required def play(): - query = request.get_data() or None - query_param = request.args.get('query', default="", type=str) + query = request.args.get('query', default=None, type=str) + body = request.get_data() or None format = request.args.get('default_format', default="TSV", type=str) database = request.args.get('database', default="", type=str) - if not query and query_param: - query = f"{query_param}".encode() + if query is None: + query = b"" + else: + query = query.encode('utf-8') + if body is not None: + query = query + "\n".encode('utf-8') + body - elif query and query_param: - query_param = f"{query_param} ".encode() - query = query_param + query - if not query: return "Error: no query parameter provided", 400 @@ -83,7 +83,7 @@ def play(): database = f"USE {database}; ".encode() query = database + query - result, errmsg = chdb_query_with_errmsg(query, format) + result, errmsg = chdb_query_with_errmsg(query.strip(), format) if len(errmsg) == 0: return result, 200 return errmsg, 400