Skip to content

Commit b5e3bce

Browse files
committed
Fix example
1 parent 83e3408 commit b5e3bce

File tree

3 files changed

+40
-53
lines changed

3 files changed

+40
-53
lines changed

README.md

Lines changed: 37 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -30,40 +30,11 @@
3030
./chdb-go --path /tmp/chdb # interactive persistent mode
3131
```
3232

33-
3. Shortcuts
34-
35-
- `\l` to list databases;
36-
- `\dt dbname` to list tables in database;
37-
3833
```bash
3934
chdb-io/chdb-go [main] » ./chdb-go
4035
Enter your SQL commands; type 'exit' to quit.
4136
:) CREATE DATABASE IF NOT EXISTS testdb;
4237

43-
:) \l
44-
┏━━━━━━━━━━━━━━━━━━━━┓
45-
┃ name ┃
46-
┡━━━━━━━━━━━━━━━━━━━━┩
47-
│ INFORMATION_SCHEMA │
48-
├────────────────────┤
49-
│ _local │
50-
├────────────────────┤
51-
│ information_schema │
52-
├────────────────────┤
53-
│ system │
54-
├────────────────────┤
55-
│ testdb │
56-
└────────────────────┘
57-
58-
:) CREATE TABLE IF NOT EXISTS testdb.testtable (id UInt32) ENGINE = MergeTree()
59-
:-] ORDER BY id;
60-
61-
:) \dt testdb
62-
┏━━━━━━━━━━━┓
63-
┃ name ┃
64-
┡━━━━━━━━━━━┩
65-
│ testtable │
66-
└───────────┘
6738

6839
```
6940

@@ -72,34 +43,50 @@ Enter your SQL commands; type 'exit' to quit.
7243
package main
7344

7445
import (
75-
"fmt"
76-
"github.com/chdb-io/chdb-go/chdb"
46+
"fmt"
47+
"os"
48+
"path/filepath"
49+
50+
"github.com/chdb-io/chdb-go/chdb"
7751
)
7852

7953
func main() {
80-
// Stateless Query (ephemeral)
81-
result := chdb.Query("SELECT version()", "CSV")
82-
fmt.Println(result)
83-
84-
// Stateful Query (persistent)
85-
session, _ := NewSession(path)
86-
defer session.Cleanup()
87-
88-
session.Query("CREATE DATABASE IF NOT EXISTS testdb; " +
89-
"CREATE TABLE IF NOT EXISTS testdb.testtable (id UInt32) ENGINE = MergeTree() ORDER BY id;")
90-
91-
session.Query("USE testdb; INSERT INTO testtable VALUES (1), (2), (3);")
92-
93-
ret := session.Query("SELECT * FROM testtable;")
94-
fmt.Println(ret)
54+
// Stateless Query (ephemeral)
55+
result, err := chdb.Query("SELECT version()", "CSV")
56+
if err != nil {
57+
fmt.Println(err)
58+
}
59+
fmt.Println(result)
60+
61+
tmp_path := filepath.Join(os.TempDir(), "chdb_test")
62+
defer os.RemoveAll(tmp_path)
63+
// Stateful Query (persistent)
64+
session, _ := chdb.NewSession(tmp_path)
65+
defer session.Cleanup()
66+
67+
_, err = session.Query("CREATE DATABASE IF NOT EXISTS testdb; " +
68+
"CREATE TABLE IF NOT EXISTS testdb.testtable (id UInt32) ENGINE = MergeTree() ORDER BY id;")
69+
if err != nil {
70+
fmt.Println(err)
71+
return
72+
}
73+
74+
_, err = session.Query("USE testdb; INSERT INTO testtable VALUES (1), (2), (3);")
75+
if err != nil {
76+
fmt.Println(err)
77+
return
78+
}
79+
80+
ret, err := session.Query("SELECT * FROM testtable;")
81+
if err != nil {
82+
fmt.Println(err)
83+
} else {
84+
fmt.Println(ret)
85+
}
9586
}
9687
```
9788

9889
### Golang API docs
9990

10091
- See [lowApi.md](lowApi.md) for the low level APIs.
10192
- See [chdb.md](chdb.md) for high level APIs.
102-
103-
### Thanks
104-
105-
- cli implementation is based on [clickhouse-cli](https://github.com/memlimit/clickhouse-cli)

chdbstable/chdb.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extern "C" {
1010
#endif
1111

1212
#define CHDB_EXPORT __attribute__((visibility("default")))
13-
struct CHDB_EXPORT local_result
13+
struct local_result
1414
{
1515
char * buf;
1616
size_t len;
@@ -20,7 +20,7 @@ struct CHDB_EXPORT local_result
2020
uint64_t bytes_read;
2121
};
2222

23-
struct CHDB_EXPORT local_result_v2
23+
struct local_result_v2
2424
{
2525
char * buf;
2626
size_t len;

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func interactiveMode(session *chdb.Session) {
8282
os.Exit(0)
8383
}
8484

85-
result, err := chdb.Query(query, "CSV")
85+
result, err := session.Query(query, "CSV")
8686
if err != nil {
8787
fmt.Println(err)
8888
return

0 commit comments

Comments
 (0)