@@ -20,6 +20,7 @@ package snowflake
20
20
import (
21
21
"errors"
22
22
"maps"
23
+ "net/http"
23
24
"runtime/debug"
24
25
"strings"
25
26
@@ -170,22 +171,58 @@ func quoteTblName(name string) string {
170
171
return "\" " + strings .ReplaceAll (name , "\" " , "\" \" " ) + "\" "
171
172
}
172
173
174
+ type config struct {
175
+ * gosnowflake.Config
176
+ }
177
+
178
+ // Option is a function type to set custom driver configurations.
179
+ //
180
+ // It is intended for configurations that cannot be provided from the standard options map,
181
+ // e.g. the underlying HTTP transporter.
182
+ type Option func (* config ) error
183
+
184
+ // WithTransporter sets the custom transporter to use for the Snowflake connection.
185
+ // This allows to intercept HTTP requests and responses.
186
+ func WithTransporter (transporter http.RoundTripper ) Option {
187
+ return func (cfg * config ) error {
188
+ cfg .Transporter = transporter
189
+ return nil
190
+ }
191
+ }
192
+
193
+ // Driver is the Snowflake driver interface.
194
+ //
195
+ // It extends the base adbc.Driver to provide additional options
196
+ // when creating the Snowflake database.
197
+ type Driver interface {
198
+ adbc.Driver
199
+
200
+ // NewDatabaseWithOptions creates a new Snowflake database with the provided options.
201
+ NewDatabaseWithOptions (map [string ]string , ... Option ) (adbc.Database , error )
202
+ }
203
+
204
+ var _ Driver = (* driverImpl )(nil )
205
+
173
206
type driverImpl struct {
174
207
driverbase.DriverImplBase
175
208
}
176
209
177
210
// NewDriver creates a new Snowflake driver using the given Arrow allocator.
178
- func NewDriver (alloc memory.Allocator ) adbc. Driver {
211
+ func NewDriver (alloc memory.Allocator ) Driver {
179
212
info := driverbase .DefaultDriverInfo ("Snowflake" )
180
213
if infoVendorVersion != "" {
181
214
if err := info .RegisterInfoCode (adbc .InfoVendorVersion , infoVendorVersion ); err != nil {
182
215
panic (err )
183
216
}
184
217
}
185
- return driverbase . NewDriver ( & driverImpl {DriverImplBase : driverbase .NewDriverImplBase (info , alloc )})
218
+ return & driverImpl {DriverImplBase : driverbase .NewDriverImplBase (info , alloc )}
186
219
}
187
220
188
221
func (d * driverImpl ) NewDatabase (opts map [string ]string ) (adbc.Database , error ) {
222
+ return d .NewDatabaseWithOptions (opts )
223
+ }
224
+
225
+ func (d * driverImpl ) NewDatabaseWithOptions (opts map [string ]string , optFuncs ... Option ) (adbc.Database , error ) {
189
226
opts = maps .Clone (opts )
190
227
db := & databaseImpl {
191
228
DatabaseImplBase : driverbase .NewDatabaseImplBase (& d .DriverImplBase ),
@@ -195,5 +232,12 @@ func (d *driverImpl) NewDatabase(opts map[string]string) (adbc.Database, error)
195
232
return nil , err
196
233
}
197
234
235
+ cfg := & config {Config : db .cfg }
236
+ for _ , opt := range optFuncs {
237
+ if err := opt (cfg ); err != nil {
238
+ return nil , err
239
+ }
240
+ }
241
+
198
242
return driverbase .NewDatabase (db ), nil
199
243
}
0 commit comments