File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -2282,3 +2282,28 @@ func (rc *SQLiteRows) nextSyncLocked(dest []driver.Value) error {
2282
2282
}
2283
2283
return nil
2284
2284
}
2285
+
2286
+ // SQLiteConnector implements driver.Connector for custom connection handling.
2287
+ type SQLiteConnector struct {
2288
+ DSN string
2289
+ DriverInstance * SQLiteDriver
2290
+ }
2291
+
2292
+ // Connect implements driver.Connector.
2293
+ func (c * SQLiteConnector ) Connect (ctx context.Context ) (driver.Conn , error ) {
2294
+ // Context is ignored for now, as SQLiteDriver.Open does not use it.
2295
+ return c .DriverInstance .Open (c .DSN )
2296
+ }
2297
+
2298
+ // Driver returns the underlying driver.
2299
+ func (c * SQLiteConnector ) Driver () driver.Driver {
2300
+ return c .DriverInstance
2301
+ }
2302
+
2303
+ // NewConnector returns a new SQLiteConnector.
2304
+ func NewConnector (dsn string ) * SQLiteConnector {
2305
+ return & SQLiteConnector {
2306
+ DSN : dsn ,
2307
+ DriverInstance : & SQLiteDriver {},
2308
+ }
2309
+ }
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ package sqlite3
10
10
11
11
import (
12
12
"bytes"
13
+ "context"
13
14
"database/sql"
14
15
"database/sql/driver"
15
16
"errors"
@@ -2586,3 +2587,14 @@ func benchmarkQueryParallel(b *testing.B) {
2586
2587
}
2587
2588
})
2588
2589
}
2590
+
2591
+ func TestSQLiteConnector (t * testing.T ) {
2592
+ connector := NewConnector (":memory:" )
2593
+ db := sql .OpenDB (connector )
2594
+ defer db .Close ()
2595
+
2596
+ ctx := context .Background ()
2597
+ if err := db .PingContext (ctx ); err != nil {
2598
+ t .Fatalf ("PingContext failed: %v" , err )
2599
+ }
2600
+ }
You can’t perform that action at this time.
0 commit comments