Skip to content

Commit f1aaefc

Browse files
committed
fix session tests, remove RawQuery, fix docs
1 parent 67d0538 commit f1aaefc

File tree

3 files changed

+56
-25
lines changed

3 files changed

+56
-25
lines changed

chdb-purego/chdb.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -141,22 +141,6 @@ func (c *connection) Ready() bool {
141141
return false
142142
}
143143

144-
// RawQuery will execute the given clickouse query without using any session.
145-
func RawQuery(argc int, argv []string) (result ChdbResult, err error) {
146-
res := queryStableV2(argc, argv)
147-
if res == nil {
148-
// According to the C ABI of chDB v1.2.0, the C function query_stable_v2
149-
// returns nil if the query returns no data. This is not an error. We
150-
// will change this behavior in the future.
151-
return newChdbResult(res), nil
152-
}
153-
if res.error_message != nil {
154-
return nil, errors.New(ptrToGoString(res.error_message))
155-
}
156-
157-
return newChdbResult(res), nil
158-
}
159-
160144
// Session will keep the state of query.
161145
// If path is None, it will create a temporary directory and use it as the database path
162146
// and the temporary directory will be removed when the session is closed.

chdb.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import "github.com/chdb-io/chdb-go/chdb"
2020

2121

2222
<a name="Query"></a>
23-
## func [Query](<https://github.com/agoncear-mwb/chdb-go/blob/main/chdb/wrapper.go#L8>)
23+
## func [Query](<https://github.com/chdb-io/chdb-go/blob/main/chdb/wrapper.go#L8>)
2424

2525
```go
2626
func Query(queryStr string, outputFormats ...string) (result chdbpurego.ChdbResult, err error)
@@ -29,7 +29,7 @@ func Query(queryStr string, outputFormats ...string) (result chdbpurego.ChdbResu
2929
Query calls query\_conn with a default in\-memory session and default output format of "CSV" if not provided.
3030

3131
<a name="Session"></a>
32-
## type [Session](<https://github.com/agoncear-mwb/chdb-go/blob/main/chdb/session.go#L15-L20>)
32+
## type [Session](<https://github.com/chdb-io/chdb-go/blob/main/chdb/session.go#L15-L20>)
3333

3434

3535

@@ -40,7 +40,7 @@ type Session struct {
4040
```
4141

4242
<a name="NewSession"></a>
43-
### func [NewSession](<https://github.com/agoncear-mwb/chdb-go/blob/main/chdb/session.go#L25>)
43+
### func [NewSession](<https://github.com/chdb-io/chdb-go/blob/main/chdb/session.go#L25>)
4444

4545
```go
4646
func NewSession(paths ...string) (*Session, error)
@@ -49,7 +49,7 @@ func NewSession(paths ...string) (*Session, error)
4949
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.
5050

5151
<a name="Session.Cleanup"></a>
52-
### func \(\*Session\) [Cleanup](<https://github.com/agoncear-mwb/chdb-go/blob/main/chdb/session.go#L77>)
52+
### func \(\*Session\) [Cleanup](<https://github.com/chdb-io/chdb-go/blob/main/chdb/session.go#L77>)
5353

5454
```go
5555
func (s *Session) Cleanup()
@@ -58,7 +58,7 @@ func (s *Session) Cleanup()
5858
Cleanup closes the session and removes the directory.
5959

6060
<a name="Session.Close"></a>
61-
### func \(\*Session\) [Close](<https://github.com/agoncear-mwb/chdb-go/blob/main/chdb/session.go#L67>)
61+
### func \(\*Session\) [Close](<https://github.com/chdb-io/chdb-go/blob/main/chdb/session.go#L67>)
6262

6363
```go
6464
func (s *Session) Close()
@@ -71,7 +71,7 @@ temporary directory is created when NewSession was called with an empty path.
7171
```
7272

7373
<a name="Session.ConnStr"></a>
74-
### func \(\*Session\) [ConnStr](<https://github.com/agoncear-mwb/chdb-go/blob/main/chdb/session.go#L88>)
74+
### func \(\*Session\) [ConnStr](<https://github.com/chdb-io/chdb-go/blob/main/chdb/session.go#L88>)
7575

7676
```go
7777
func (s *Session) ConnStr() string
@@ -80,7 +80,7 @@ func (s *Session) ConnStr() string
8080
ConnStr returns the current connection string used for the underlying connection
8181

8282
<a name="Session.IsTemp"></a>
83-
### func \(\*Session\) [IsTemp](<https://github.com/agoncear-mwb/chdb-go/blob/main/chdb/session.go#L93>)
83+
### func \(\*Session\) [IsTemp](<https://github.com/chdb-io/chdb-go/blob/main/chdb/session.go#L93>)
8484

8585
```go
8686
func (s *Session) IsTemp() bool
@@ -89,7 +89,7 @@ func (s *Session) IsTemp() bool
8989
IsTemp returns whether the session is temporary.
9090

9191
<a name="Session.Path"></a>
92-
### func \(\*Session\) [Path](<https://github.com/agoncear-mwb/chdb-go/blob/main/chdb/session.go#L83>)
92+
### func \(\*Session\) [Path](<https://github.com/chdb-io/chdb-go/blob/main/chdb/session.go#L83>)
9393

9494
```go
9595
func (s *Session) Path() string
@@ -98,7 +98,7 @@ func (s *Session) Path() string
9898
Path returns the path of the session.
9999

100100
<a name="Session.Query"></a>
101-
### func \(\*Session\) [Query](<https://github.com/agoncear-mwb/chdb-go/blob/main/chdb/session.go#L56>)
101+
### func \(\*Session\) [Query](<https://github.com/chdb-io/chdb-go/blob/main/chdb/session.go#L56>)
102102

103103
```go
104104
func (s *Session) Query(queryStr string, outputFormats ...string) (result chdbpurego.ChdbResult, err error)

chdb/session_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package chdb
22

33
import (
44
"os"
5+
"path/filepath"
56
"testing"
67
)
78

@@ -50,3 +51,49 @@ func TestSessionCleanup(t *testing.T) {
5051
t.Errorf("Session directory should be removed after Cleanup: %s", session.Path())
5152
}
5253
}
54+
55+
func TestQuery(t *testing.T) {
56+
session, _ := NewSession()
57+
defer session.Cleanup()
58+
59+
session.Query("CREATE DATABASE IF NOT EXISTS testdb; " +
60+
"CREATE TABLE IF NOT EXISTS testdb.testtable (id UInt32) ENGINE = MergeTree() ORDER BY id;")
61+
62+
session.Query("USE testdb; INSERT INTO testtable VALUES (1), (2), (3);")
63+
64+
ret, err := session.Query("SELECT * FROM testtable;")
65+
if err != nil {
66+
t.Errorf("Query failed: %s", err)
67+
}
68+
if string(ret.Buf()) != "1\n2\n3\n" {
69+
t.Errorf("Query result should be 1\n2\n3\n, got %s", string(ret.Buf()))
70+
}
71+
}
72+
73+
func TestSessionPathAndIsTemp(t *testing.T) {
74+
// Create a new session and check its Path and IsTemp
75+
session, _ := NewSession()
76+
77+
if session.Path() == "" {
78+
t.Errorf("Session path should not be empty")
79+
}
80+
81+
if !session.IsTemp() {
82+
t.Errorf("Session should be temporary")
83+
}
84+
session.Close()
85+
86+
// Create a new session with a specific path and check its Path and IsTemp
87+
path := filepath.Join(os.TempDir(), "chdb_test2")
88+
defer os.RemoveAll(path)
89+
session, _ = NewSession(path)
90+
defer session.Cleanup()
91+
92+
if session.Path() != path {
93+
t.Errorf("Session path should be %s, got %s", path, session.Path())
94+
}
95+
96+
if session.IsTemp() {
97+
t.Errorf("Session should not be temporary")
98+
}
99+
}

0 commit comments

Comments
 (0)