The problem was mentioned in https://github.com/go-gorm/gorm/issues/6468, gorm.io/driver/sqlite depends on github.com/mattn/go-sqlite3 which is a cgo lib and requires gcc to build a binary.
Reproduction
sqlite3 example.db
go run .
package main
import (
"fmt"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
func Init(filename string) (*gorm.DB, error) {
database, err := gorm.Open(sqlite.Open(filename), &gorm.Config{})
if err != nil {
return nil, err
}
return database, nil
}
func main() {
database, err := Init("example.db")
if database == nil {
fmt.Println(err)
return
}
}
Runtime error
[error] failed to initialize database, got error Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires
cgo to work. This is a stub
Reference issues
Manual workaround can be found at https://github.com/mattn/go-sqlite3/issues/855.
There's a feature request for pure go driver implementation use at https://github.com/go-gorm/sqlite/issues/160
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨