Fix SQLite driver name mismatch causing "unknown driver" errors (#252)

* fix: Use correct SQLite driver name 'sqlite3' instead of 'sqlite'

The ncruces/go-sqlite3 driver registers as 'sqlite3', but doctor.go
and example code were using 'sqlite', causing 'unknown driver' errors.

This fix corrects all sql.Open() calls to use the proper driver name:
- cmd/bd/doctor.go: 6 instances fixed
- docs/EXTENDING.md: 2 documentation examples updated
- examples/bd-example-extension-go/: Fixed example code and README

Fixes #230

Amp-Thread-ID: https://ampcode.com/threads/T-1e8c5473-cb79-4457-be07-4517bfdb73f4
Co-authored-by: Amp <amp@ampcode.com>

* Revert CGO_ENABLED back to 0 for pure-Go SQLite driver

The ncruces/go-sqlite3 driver is pure-Go and doesn't require CGO.
The previous change to CGO_ENABLED=1 in commit f9771cd was an
attempted fix for #230, but the real issue was the driver name
mismatch ('sqlite' vs 'sqlite3'), which is now fixed.

Benefits of CGO_ENABLED=0:
- Simpler cross-compilation (no C toolchain required)
- Smaller binaries
- Faster builds
- Matches the intended design of the pure-Go driver

---------

Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Matteo Landi
2025-11-07 23:19:14 +01:00
committed by GitHub
parent 2db2203630
commit 64742cd574
5 changed files with 10 additions and 10 deletions

View File

@@ -13,7 +13,7 @@ builds:
main: ./cmd/bd
binary: bd
env:
- CGO_ENABLED=1
- CGO_ENABLED=0
goos:
- linux
- darwin

View File

@@ -314,7 +314,7 @@ func checkIDFormat(path string) doctorCheck {
}
// Open database
db, err := sql.Open("sqlite", dbPath+"?mode=ro")
db, err := sql.Open("sqlite3", dbPath+"?mode=ro")
if err != nil {
return doctorCheck{
Name: "Issue IDs",
@@ -400,7 +400,7 @@ func checkCLIVersion() doctorCheck {
}
func getDatabaseVersionFromPath(dbPath string) string {
db, err := sql.Open("sqlite", dbPath+"?mode=ro")
db, err := sql.Open("sqlite3", dbPath+"?mode=ro")
if err != nil {
return "unknown"
}
@@ -785,7 +785,7 @@ func checkDatabaseJSONLSync(path string) doctorCheck {
jsonlCount, jsonlPrefixes, jsonlErr := countJSONLIssues(jsonlPath)
// Single database open for all queries (instead of 3 separate opens)
db, err := sql.Open("sqlite", dbPath)
db, err := sql.Open("sqlite3", dbPath)
if err != nil {
// Database can't be opened. If JSONL has issues, suggest recovery.
if jsonlErr == nil && jsonlCount > 0 {
@@ -990,7 +990,7 @@ func checkPermissions(path string) doctorCheck {
dbPath := filepath.Join(beadsDir, beads.CanonicalDatabaseName)
if _, err := os.Stat(dbPath); err == nil {
// Try to open database
db, err := sql.Open("sqlite", dbPath)
db, err := sql.Open("sqlite3", dbPath)
if err != nil {
return doctorCheck{
Name: "Permissions",
@@ -1038,7 +1038,7 @@ func checkDependencyCycles(path string) doctorCheck {
}
// Open database to check for cycles
db, err := sql.Open("sqlite", dbPath)
db, err := sql.Open("sqlite3", dbPath)
if err != nil {
return doctorCheck{
Name: "Dependency Cycles",

View File

@@ -84,7 +84,7 @@ CREATE INDEX IF NOT EXISTS idx_checkpoints_execution ON myapp_checkpoints(execut
`
func InitializeMyAppSchema(dbPath string) error {
db, err := sql.Open("sqlite", dbPath)
db, err := sql.Open("sqlite3", dbPath)
if err != nil {
return err
}
@@ -572,7 +572,7 @@ if dbPath == "" {
}
// Open your own connection to the same database
db, err := sql.Open("sqlite", dbPath)
db, err := sql.Open("sqlite3", dbPath)
if err != nil {
log.Fatal(err)
}

View File

@@ -182,7 +182,7 @@ jsonlPath := beads.FindJSONLPath(dbPath)
```go
// Open same database for extension tables
db, err := sql.Open("sqlite", dbPath)
db, err := sql.Open("sqlite3", dbPath)
// Initialize extension schema
_, err = db.Exec(Schema)

View File

@@ -30,7 +30,7 @@ func main() {
// Open bd storage + extension database
store, _ := beads.NewSQLiteStorage(*dbPath)
defer store.Close()
db, _ := sql.Open("sqlite", *dbPath)
db, _ := sql.Open("sqlite3", *dbPath)
defer db.Close()
db.Exec("PRAGMA journal_mode=WAL")
db.Exec("PRAGMA busy_timeout=5000")