Skip to content

Commit b897f14

Browse files
update docs
1 parent 1dafcc2 commit b897f14

File tree

5 files changed

+90
-24
lines changed

5 files changed

+90
-24
lines changed

chdb-purego/chdb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func (c *connection) Query(queryStr string, formatStr string) (result ChdbResult
141141
return newChdbResult(res), nil
142142
}
143143

144-
// Query implements ChdbConn.
144+
// QueryStreaming implements ChdbConn.
145145
func (c *connection) QueryStreaming(queryStr string, formatStr string) (result ChdbStreamResult, err error) {
146146

147147
if c.conn == nil {

chdb-purego/types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,24 @@ type ChdbResult interface {
5555
}
5656

5757
type ChdbStreamResult interface {
58+
// GetNext returns the next chunk of data from the stream.
59+
// The chunk is a ChdbResult object that can be used to read the data.
60+
// If there are no more chunks, it returns nil.
5861
GetNext() ChdbResult
62+
// Error returns the error message if there was an error during the streaming process.
5963
Error() error
64+
// Cancel cancels the streaming process and frees the underlying memory.
6065
Cancel()
66+
// Free frees the underlying memory and closes the stream.
6167
Free()
6268
}
6369

6470
type ChdbConn interface {
6571
//Query executes the given queryStr in the underlying clickhouse connection, and output the result in the given formatStr
6672
Query(queryStr string, formatStr string) (result ChdbResult, err error)
73+
// QueryStreaming executes the given queryStr in the underlying clickhouse connection, and output the result in the given formatStr
74+
// The result is a stream of data that can be read in chunks.
75+
// This is useful for large datasets that cannot be loaded into memory all at once.
6776
QueryStreaming(queryStr string, formatStr string) (result ChdbStreamResult, err error)
6877
//Ready returns a boolean indicating if the connections is successfully established.
6978
Ready() bool

chdb.md

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import "github.com/chdb-io/chdb-go/chdb"
99
## Index
1010

1111
- [func Query\(queryStr string, outputFormats ...string\) \(result chdbpurego.ChdbResult, err error\)](<#Query>)
12+
- [func QueryStream\(queryStr string, outputFormats ...string\) \(result chdbpurego.ChdbStreamResult, err error\)](<#QueryStream>)
1213
- [type Session](<#Session>)
1314
- [func NewSession\(paths ...string\) \(\*Session, error\)](<#NewSession>)
1415
- [func \(s \*Session\) Cleanup\(\)](<#Session.Cleanup>)
@@ -17,19 +18,29 @@ import "github.com/chdb-io/chdb-go/chdb"
1718
- [func \(s \*Session\) IsTemp\(\) bool](<#Session.IsTemp>)
1819
- [func \(s \*Session\) Path\(\) string](<#Session.Path>)
1920
- [func \(s \*Session\) Query\(queryStr string, outputFormats ...string\) \(result chdbpurego.ChdbResult, err error\)](<#Session.Query>)
21+
- [func \(s \*Session\) QueryStream\(queryStr string, outputFormats ...string\) \(result chdbpurego.ChdbStreamResult, err error\)](<#Session.QueryStream>)
2022

2123

2224
<a name="Query"></a>
23-
## func [Query](<https://github.com/chdb-io/chdb-go/blob/main/chdb/wrapper.go#L8>)
25+
## func [Query](<https://github.com/s0und0fs1lence/chdb-go/blob/main/chdb/wrapper.go#L8>)
2426

2527
```go
2628
func Query(queryStr string, outputFormats ...string) (result chdbpurego.ChdbResult, err error)
2729
```
2830

2931
Query calls query\_conn with a default in\-memory session and default output format of "CSV" if not provided.
3032

33+
<a name="QueryStream"></a>
34+
## func [QueryStream](<https://github.com/s0und0fs1lence/chdb-go/blob/main/chdb/wrapper.go#L23>)
35+
36+
```go
37+
func QueryStream(queryStr string, outputFormats ...string) (result chdbpurego.ChdbStreamResult, err error)
38+
```
39+
40+
Query calls query\_conn with a default in\-memory session and default output format of "CSV" if not provided.
41+
3142
<a name="Session"></a>
32-
## type [Session](<https://github.com/chdb-io/chdb-go/blob/main/chdb/session.go#L15-L20>)
43+
## type [Session](<https://github.com/s0und0fs1lence/chdb-go/blob/main/chdb/session.go#L14-L19>)
3344

3445

3546

@@ -40,7 +51,7 @@ type Session struct {
4051
```
4152

4253
<a name="NewSession"></a>
43-
### func [NewSession](<https://github.com/chdb-io/chdb-go/blob/main/chdb/session.go#L25>)
54+
### func [NewSession](<https://github.com/s0und0fs1lence/chdb-go/blob/main/chdb/session.go#L24>)
4455

4556
```go
4657
func NewSession(paths ...string) (*Session, error)
@@ -49,7 +60,7 @@ func NewSession(paths ...string) (*Session, error)
4960
NewSession creates a new session with the given path. If path is empty, a temporary directory is created. Note: The temporary directory is removed when Close is called.
5061

5162
<a name="Session.Cleanup"></a>
52-
### func \(\*Session\) [Cleanup](<https://github.com/chdb-io/chdb-go/blob/main/chdb/session.go#L77>)
63+
### func \(\*Session\) [Cleanup](<https://github.com/s0und0fs1lence/chdb-go/blob/main/chdb/session.go#L86>)
5364

5465
```go
5566
func (s *Session) Cleanup()
@@ -58,7 +69,7 @@ func (s *Session) Cleanup()
5869
Cleanup closes the session and removes the directory.
5970

6071
<a name="Session.Close"></a>
61-
### func \(\*Session\) [Close](<https://github.com/chdb-io/chdb-go/blob/main/chdb/session.go#L67>)
72+
### func \(\*Session\) [Close](<https://github.com/s0und0fs1lence/chdb-go/blob/main/chdb/session.go#L76>)
6273

6374
```go
6475
func (s *Session) Close()
@@ -71,7 +82,7 @@ temporary directory is created when NewSession was called with an empty path.
7182
```
7283

7384
<a name="Session.ConnStr"></a>
74-
### func \(\*Session\) [ConnStr](<https://github.com/chdb-io/chdb-go/blob/main/chdb/session.go#L88>)
85+
### func \(\*Session\) [ConnStr](<https://github.com/s0und0fs1lence/chdb-go/blob/main/chdb/session.go#L99>)
7586

7687
```go
7788
func (s *Session) ConnStr() string
@@ -80,7 +91,7 @@ func (s *Session) ConnStr() string
8091
ConnStr returns the current connection string used for the underlying connection
8192

8293
<a name="Session.IsTemp"></a>
83-
### func \(\*Session\) [IsTemp](<https://github.com/chdb-io/chdb-go/blob/main/chdb/session.go#L93>)
94+
### func \(\*Session\) [IsTemp](<https://github.com/s0und0fs1lence/chdb-go/blob/main/chdb/session.go#L104>)
8495

8596
```go
8697
func (s *Session) IsTemp() bool
@@ -89,7 +100,7 @@ func (s *Session) IsTemp() bool
89100
IsTemp returns whether the session is temporary.
90101

91102
<a name="Session.Path"></a>
92-
### func \(\*Session\) [Path](<https://github.com/chdb-io/chdb-go/blob/main/chdb/session.go#L83>)
103+
### func \(\*Session\) [Path](<https://github.com/s0und0fs1lence/chdb-go/blob/main/chdb/session.go#L94>)
93104

94105
```go
95106
func (s *Session) Path() string
@@ -98,12 +109,21 @@ func (s *Session) Path() string
98109
Path returns the path of the session.
99110

100111
<a name="Session.Query"></a>
101-
### func \(\*Session\) [Query](<https://github.com/chdb-io/chdb-go/blob/main/chdb/session.go#L56>)
112+
### func \(\*Session\) [Query](<https://github.com/s0und0fs1lence/chdb-go/blob/main/chdb/session.go#L54>)
102113

103114
```go
104115
func (s *Session) Query(queryStr string, outputFormats ...string) (result chdbpurego.ChdbResult, err error)
105116
```
106117

107118
Query calls \`query\_conn\` function with the current connection and a default output format of "CSV" if not provided.
108119

120+
<a name="Session.QueryStream"></a>
121+
### func \(\*Session\) [QueryStream](<https://github.com/s0und0fs1lence/chdb-go/blob/main/chdb/session.go#L65>)
122+
123+
```go
124+
func (s *Session) QueryStream(queryStr string, outputFormats ...string) (result chdbpurego.ChdbStreamResult, err error)
125+
```
126+
127+
QueryStream calls \`query\_conn\` function with the current connection and a default output format of "CSV" if not provided. The result is a stream of data that can be read in chunks. This is useful for large datasets that cannot be loaded into memory all at once.
128+
109129
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)

chdb/session.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ func (s *Session) Query(queryStr string, outputFormats ...string) (result chdbpu
5959
return s.conn.Query(queryStr, outputFormat)
6060
}
6161

62-
// Query calls `query_conn` function with the current connection and a default output format of "CSV" if not provided.
62+
// QueryStream calls `query_conn` function with the current connection and a default output format of "CSV" if not provided.
63+
// The result is a stream of data that can be read in chunks.
64+
// This is useful for large datasets that cannot be loaded into memory all at once.
6365
func (s *Session) QueryStream(queryStr string, outputFormats ...string) (result chdbpurego.ChdbStreamResult, err error) {
6466
outputFormat := "CSV" // Default value
6567
if len(outputFormats) > 0 {

lowApi.md

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,24 @@ import "github.com/chdb-io/chdb-go/chdb-purego"
1010

1111
- [type ChdbConn](<#ChdbConn>)
1212
- [func NewConnection\(argc int, argv \[\]string\) \(ChdbConn, error\)](<#NewConnection>)
13+
- [func NewConnectionFromConnString\(conn\_string string\) \(ChdbConn, error\)](<#NewConnectionFromConnString>)
1314
- [type ChdbResult](<#ChdbResult>)
14-
- [func RawQuery\(argc int, argv \[\]string\) \(result ChdbResult, err error\)](<#RawQuery>)
15+
- [type ChdbStreamResult](<#ChdbStreamResult>)
1516

1617

1718
<a name="ChdbConn"></a>
18-
## type [ChdbConn](<https://github.com/chdb-io/chdb-go/blob/main/chdb-purego/types.go#L53-L60>)
19+
## type [ChdbConn](<https://github.com/s0und0fs1lence/chdb-go/blob/main/chdb-purego/types.go#L70-L81>)
1920

2021

2122

2223
```go
2324
type ChdbConn interface {
2425
//Query executes the given queryStr in the underlying clickhouse connection, and output the result in the given formatStr
2526
Query(queryStr string, formatStr string) (result ChdbResult, err error)
27+
// QueryStreaming executes the given queryStr in the underlying clickhouse connection, and output the result in the given formatStr
28+
// The result is a stream of data that can be read in chunks.
29+
// This is useful for large datasets that cannot be loaded into memory all at once.
30+
QueryStreaming(queryStr string, formatStr string) (result ChdbStreamResult, err error)
2631
//Ready returns a boolean indicating if the connections is successfully established.
2732
Ready() bool
2833
//Close the connection and free the underlying allocated memory
@@ -31,15 +36,35 @@ type ChdbConn interface {
3136
```
3237

3338
<a name="NewConnection"></a>
34-
### func [NewConnection](<https://github.com/chdb-io/chdb-go/blob/main/chdb-purego/chdb.go#L188>)
39+
### func [NewConnection](<https://github.com/s0und0fs1lence/chdb-go/blob/main/chdb-purego/chdb.go#L195>)
3540

3641
```go
3742
func NewConnection(argc int, argv []string) (ChdbConn, error)
3843
```
3944

40-
Session will keep the state of query. If path is None, it will create a temporary directory and use it as the database path and the temporary directory will be removed when the session is closed. You can also pass in a path to create a database at that path where will keep your data.
45+
NewConnection is the low level function to create a new connection to the chdb server. using NewConnectionFromConnString is recommended.
4146

42-
You can also use a connection string to pass in the path and other parameters. Examples:
47+
Deprecated: Use NewConnectionFromConnString instead. This function will be removed in a future version.
48+
49+
Session will keep the state of query. If path is None, it will create a temporary directory and use it as the database path and the temporary directory will be removed when the session is closed. You can also pass in a path to create a database at that path where will keep your data. This is a thin wrapper around the connect\_chdb C API. the argc and argv should be like:
50+
51+
- argc = 1, argv = \[\]string\{"\-\-path=/tmp/chdb"\}
52+
- argc = 2, argv = \[\]string\{"\-\-path=/tmp/chdb", "\-\-readonly=1"\}
53+
54+
Important:
55+
56+
- There can be only one session at a time. If you want to create a new session, you need to close the existing one.
57+
- Creating a new session will close the existing one.
58+
- You need to ensure that the path exists before creating a new session. Or you can use NewConnectionFromConnString.
59+
60+
<a name="NewConnectionFromConnString"></a>
61+
### func [NewConnectionFromConnString](<https://github.com/s0und0fs1lence/chdb-go/blob/main/chdb-purego/chdb.go#L269>)
62+
63+
```go
64+
func NewConnectionFromConnString(conn_string string) (ChdbConn, error)
65+
```
66+
67+
NewConnectionFromConnString creates a new connection to the chdb server using a connection string. You can use a connection string to pass in the path and other parameters. Examples:
4368

4469
- ":memory:" \(for in\-memory database\)
4570
- "test.db" \(for relative path\)
@@ -67,13 +92,12 @@ Important:
6792
- Creating a new session will close the existing one.
6893
6994
<a name="ChdbResult"></a>
70-
## type [ChdbResult](<https://github.com/chdb-io/chdb-go/blob/main/chdb-purego/types.go#L34-L51>)
95+
## type [ChdbResult](<https://github.com/s0und0fs1lence/chdb-go/blob/main/chdb-purego/types.go#L39-L55>)
7196
7297
7398
7499
```go
75100
type ChdbResult interface {
76-
// Raw bytes result buffer, used for reading the result of clickhouse query
77101
Buf() []byte
78102
// String rapresentation of the the buffer
79103
String() string
@@ -88,17 +112,28 @@ type ChdbResult interface {
88112
// If the query had any error during execution, here you can retrieve the cause.
89113
Error() error
90114
// Free the query result and all the allocated memory
91-
Free() error
115+
Free()
92116
}
93117
```
94118

95-
<a name="RawQuery"></a>
96-
### func [RawQuery](<https://github.com/chdb-io/chdb-go/blob/main/chdb-purego/chdb.go#L145>)
119+
<a name="ChdbStreamResult"></a>
120+
## type [ChdbStreamResult](<https://github.com/s0und0fs1lence/chdb-go/blob/main/chdb-purego/types.go#L57-L68>)
121+
122+
97123

98124
```go
99-
func RawQuery(argc int, argv []string) (result ChdbResult, err error)
125+
type ChdbStreamResult interface {
126+
// GetNext returns the next chunk of data from the stream.
127+
// The chunk is a ChdbResult object that can be used to read the data.
128+
// If there are no more chunks, it returns nil.
129+
GetNext() ChdbResult
130+
// Error returns the error message if there was an error during the streaming process.
131+
Error() error
132+
// Cancel cancels the streaming process and frees the underlying memory.
133+
Cancel()
134+
// Free frees the underlying memory and closes the stream.
135+
Free()
136+
}
100137
```
101138

102-
RawQuery will execute the given clickouse query without using any session.
103-
104139
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)

0 commit comments

Comments
 (0)