|
| 1 | +<a href="https://chdb.io" target="_blank"> |
| 2 | + <img src="https://avatars.githubusercontent.com/u/132536224" width=130 /> |
| 3 | +</a> |
| 4 | + |
| 5 | +[](https://github.com/chdb-io/chdb-go/actions/workflows/chdb.yml) |
| 6 | + |
| 7 | +# chdb-go |
| 8 | +[chDB](https://github.com/chdb-io/chdb) go bindings and chDB cli. |
| 9 | + |
| 10 | +## Install |
| 11 | + |
| 12 | +1. Download and install [`libchdb`](https://github.com/chdb-io/chdb/releases) |
| 13 | + - run `make update_libchdb` to download and extract libchdb.so. or |
| 14 | + - run `make install` to install libchdb.so |
| 15 | +2. Build `chdb-go` |
| 16 | + - run `make build` |
| 17 | +3. Run `chdb-go` with or without persistent `--path` |
| 18 | + - run `./chdb-go` |
| 19 | + |
| 20 | +## chdb-go CLI |
| 21 | + |
| 22 | +1. Simple mode |
| 23 | +```bash |
| 24 | +./chdb-go "SELECT 123" |
| 25 | +./chdb-go "SELECT 123" JSON |
| 26 | +``` |
| 27 | +2. Interactive mode |
| 28 | +```bash |
| 29 | +./chdb-go # enter interactive mode, but data will be lost after exit |
| 30 | +./chdb-go --path /tmp/chdb # interactive persistent mode |
| 31 | +``` |
| 32 | + |
| 33 | +#### Go lib Example |
| 34 | +```go |
| 35 | +package main |
| 36 | + |
| 37 | +import ( |
| 38 | + "fmt" |
| 39 | + "github.com/chdb-io/chdb-go/chdb" |
| 40 | +) |
| 41 | + |
| 42 | +func main() { |
| 43 | + // Stateless Query (ephemeral) |
| 44 | + result := chdb.Query("SELECT version()", "CSV") |
| 45 | + fmt.Println(result) |
| 46 | + |
| 47 | + // Stateful Query (persistent) |
| 48 | + session, _ := NewSession(path) |
| 49 | + defer session.Cleanup() |
| 50 | + |
| 51 | + session.Query("CREATE DATABASE IF NOT EXISTS testdb; " + |
| 52 | + "CREATE TABLE IF NOT EXISTS testdb.testtable (id UInt32) ENGINE = MergeTree() ORDER BY id;") |
| 53 | + |
| 54 | + session.Query("USE testdb; INSERT INTO testtable VALUES (1), (2), (3);") |
| 55 | + |
| 56 | + ret := session.Query("SELECT * FROM testtable;") |
| 57 | + fmt.Println(ret) |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +### Golang API docs |
| 62 | + |
| 63 | +- See [lowApi.md](lowApi.md) for the low level APIs. |
| 64 | +- See [chdb.md](chdb.md) for high level APIs. |
0 commit comments