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

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Nov 11, 2023
2 parents 9065665 + 901cdef commit 6ba2c54
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)

<br>

Expand All @@ -25,13 +18,21 @@
<br><br>


### Docker Demo
### Docker Setup
```
docker run --rm -p 8123:8123 ghcr.io/chdb-io/chdb-server:latest
```

<br>

### 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)

<br>

### ClickHouse Play
chdb-server is compatible with the ClickHouse Play query interface:
<a href="https://chdb.fly.dev/?user=default#U0VMRUNUCiAgICB0b3duLAogICAgZGlzdHJpY3QsCiAgICBjb3VudCgpIEFTIGMsCiAgICByb3VuZChhdmcocHJpY2UpKSBBUyBwcmljZQpGUk9NIHVybCgnaHR0cHM6Ly9kYXRhc2V0cy1kb2N1bWVudGF0aW9uLnMzLmV1LXdlc3QtMy5hbWF6b25hd3MuY29tL2hvdXNlX3BhcnF1ZXQvaG91c2VfMC5wYXJxdWV0JykKR1JPVVAgQlkKICAgIHRvd24sCiAgICBkaXN0cmljdApMSU1JVCAxMA==" target="_blank">
Expand Down
20 changes: 10 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,34 +56,34 @@ 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

@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

if database:
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
Expand Down

0 comments on commit 6ba2c54

Please sign in to comment.