Skip to content

Commit b2ba138

Browse files
committed
change session mode to sqlite like api (v3.0.0)
1 parent 8980a7a commit b2ba138

File tree

7 files changed

+141
-396
lines changed

7 files changed

+141
-396
lines changed

chdb/connection.go

Lines changed: 0 additions & 80 deletions
This file was deleted.

chdb/connection_test.go

Lines changed: 0 additions & 117 deletions
This file was deleted.

chdb/driver/driver.go

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ const (
2727

2828
const (
2929
sessionOptionKey = "session"
30-
connectionOptionKey = "connection"
3130
udfPathOptionKey = "udfPath"
3231
driverTypeKey = "driverType"
3332
useUnsafeStringReaderKey = "useUnsafeStringReader"
@@ -137,13 +136,11 @@ func (e *execResult) RowsAffected() (int64, error) {
137136
type queryHandle func(string, ...string) (*chdbstable.LocalResult, error)
138137

139138
type connector struct {
140-
udfPath string
141-
driverType DriverType
142-
bufferSize int
143-
useUnsafe bool
144-
session *chdb.Session
145-
connection *chdb.Connection
146-
useConnection bool
139+
udfPath string
140+
driverType DriverType
141+
bufferSize int
142+
useUnsafe bool
143+
session *chdb.Session
147144
}
148145

149146
// Connect returns a connection to a database.
@@ -153,9 +150,7 @@ func (c *connector) Connect(ctx context.Context) (driver.Conn, error) {
153150
}
154151
cc := &conn{
155152
udfPath: c.udfPath, session: c.session,
156-
connection: c.connection,
157-
useConnection: c.useConnection,
158-
driverType: c.driverType, bufferSize: c.bufferSize,
153+
driverType: c.driverType, bufferSize: c.bufferSize,
159154
useUnsafe: c.useUnsafe,
160155
}
161156
cc.SetupQueryFun()
@@ -191,17 +186,6 @@ func NewConnect(opts map[string]string) (ret *connector, err error) {
191186
return nil, err
192187
}
193188
}
194-
connectionStr, ok := opts[connectionOptionKey]
195-
if ok {
196-
if ret.session != nil {
197-
return nil, fmt.Errorf("could not use both session & connection. please use one of the two")
198-
}
199-
ret.connection, err = chdb.NewConnection(connectionStr)
200-
if err != nil {
201-
return nil, err
202-
}
203-
ret.useConnection = true
204-
}
205189
driverType, ok := opts[driverTypeKey]
206190
if ok {
207191
ret.driverType = parseDriverType(driverType)
@@ -230,6 +214,12 @@ func NewConnect(opts map[string]string) (ret *connector, err error) {
230214
if ok {
231215
ret.udfPath = udfPath
232216
}
217+
if ret.session == nil {
218+
ret.session, err = chdb.NewSession()
219+
if err != nil {
220+
return nil, err
221+
}
222+
}
233223
return
234224
}
235225

@@ -254,14 +244,13 @@ func (d Driver) OpenConnector(name string) (driver.Connector, error) {
254244
}
255245

256246
type conn struct {
257-
udfPath string
258-
driverType DriverType
259-
bufferSize int
260-
useUnsafe bool
261-
useConnection bool
262-
session *chdb.Session
263-
connection *chdb.Connection
264-
QueryFun queryHandle
247+
udfPath string
248+
driverType DriverType
249+
bufferSize int
250+
useUnsafe bool
251+
session *chdb.Session
252+
253+
QueryFun queryHandle
265254
}
266255

267256
func prepareValues(values []driver.Value) []driver.NamedValue {
@@ -285,9 +274,7 @@ func (c *conn) SetupQueryFun() {
285274
if c.session != nil {
286275
c.QueryFun = c.session.Query
287276
}
288-
if c.connection != nil {
289-
c.QueryFun = c.connection.Query
290-
}
277+
291278
}
292279

293280
func (c *conn) Query(query string, values []driver.Value) (driver.Rows, error) {

0 commit comments

Comments
 (0)