30
30
./chdb-go --path /tmp/chdb # interactive persistent mode
31
31
```
32
32
33
- 3 . Shortcuts
34
-
35
- - ` \l ` to list databases;
36
- - ` \dt dbname ` to list tables in database;
37
-
38
33
``` bash
39
34
chdb-io/chdb-go [main] » ./chdb-go
40
35
Enter your SQL commands; type ' exit' to quit.
41
36
:) CREATE DATABASE IF NOT EXISTS testdb;
42
37
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
- :) \d t testdb
62
- ┏━━━━━━━━━━━┓
63
- ┃ name ┃
64
- ┡━━━━━━━━━━━┩
65
- │ testtable │
66
- └───────────┘
67
38
68
39
```
69
40
@@ -72,34 +43,50 @@ Enter your SQL commands; type 'exit' to quit.
72
43
package main
73
44
74
45
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"
77
51
)
78
52
79
53
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
+ }
95
86
}
96
87
```
97
88
98
89
### Golang API docs
99
90
100
91
- See [ lowApi.md] ( lowApi.md ) for the low level APIs.
101
92
- 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 )
0 commit comments