Skip to content

Commit 4079f4a

Browse files
committed
Add driver.Connector implementation for SQLite (#1001)
1 parent 5071c16 commit 4079f4a

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

sqlite3_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2597,4 +2597,47 @@ func TestSQLiteConnector(t *testing.T) {
25972597
if err := db.PingContext(ctx); err != nil {
25982598
t.Fatalf("PingContext failed: %v", err)
25992599
}
2600+
2601+
// Test basic query
2602+
_, err := db.ExecContext(ctx, "CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT)")
2603+
if err != nil {
2604+
t.Fatalf("CREATE TABLE failed: %v", err)
2605+
}
2606+
2607+
_, err = db.ExecContext(ctx, "INSERT INTO test (name) VALUES (?)", "Alice")
2608+
if err != nil {
2609+
t.Fatalf("INSERT failed: %v", err)
2610+
}
2611+
2612+
var name string
2613+
err = db.QueryRowContext(ctx, "SELECT name FROM test WHERE id = 1").Scan(&name)
2614+
if err != nil {
2615+
t.Fatalf("SELECT failed: %v", err)
2616+
}
2617+
if name != "Alice" {
2618+
t.Errorf("Expected name 'Alice', got '%s'", name)
2619+
}
2620+
}
2621+
2622+
func TestSQLiteConnectorContextCancellation(t *testing.T) {
2623+
connector := NewConnector(":memory:")
2624+
ctx, cancel := context.WithCancel(context.Background())
2625+
cancel()
2626+
2627+
conn, err := connector.Connect(ctx)
2628+
if err == nil {
2629+
conn.Close()
2630+
t.Error("Expected error on canceled context, got nil")
2631+
}
2632+
}
2633+
2634+
func TestSQLiteConnectorDriver(t *testing.T) {
2635+
driver := &SQLiteDriver{}
2636+
connector := &SQLiteConnector{
2637+
DSN: ":memory:",
2638+
DriverInstance: driver,
2639+
}
2640+
if connector.Driver() != driver {
2641+
t.Errorf("Driver() returned %v, want %v", connector.Driver(), driver)
2642+
}
26002643
}

0 commit comments

Comments
 (0)