Pure-go (without cgo) implementation of SQLite driver for GORM
This driver has SQLite embedded, you don't need to install one separately.
import (
"github.com/glebarez/sqlite"
"gorm.io/gorm"
)
db, err := gorm.Open(sqlite.Open("sqlite.db"), &gorm.Config{})
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
Foreign-key constraint is disabled by default in SQLite. To activate it, use connection URL parameter:
db, err := gorm.Open(sqlite.Open(":memory:?_pragma=foreign_keys(1)"), &gorm.Config{})
More info: https://www.sqlite.org/foreignkeys.html
This driver tracks go-gorm/sqlite. The last upstream commit merged here is 525c431. Upstream behaviour fixes get ported, so migration and DDL parsing behave the same on both drivers.
Three differences are deliberate and stay:
github.com/glebarez/go-sqlite and modernc.org/sqlite rather than github.com/mattn/go-sqlite3DriverName defaults to sqlite, not upstream's sqlite3Translate reads the SQLite extended result code off the driver error, rather than marshalling the error to JSON and matching on field namesAnything that does not depend on the backend goes upstream first and comes back here as a port. First one: go-gorm/sqlite#247.
The standard GORM driver for SQLite has one major drawback: it is based on a Go-bindings of SQLite C-source (this is called cgo). This fact imposes following restrictions on Go developers:
go command to work properly (go run, go test, etc.).Instead, this driver is based on pure-Go implementation of SQLite (https://gitlab.com/cznic/sqlite), which is basically an original SQLite C-source AST, translated into Go! So, you may be sure you're using the original SQLite implementation under the hood.
Yes, The CI pipeline of this driver employs whole test base of GORM, which includes more than 12k tests (see badge on the page-top). Testing is run against latest major releases of Go:
In following environments:
Well, it's slower than CGo implementation, but not terribly. See the bechmark of underlying pure-Go driver vs CGo implementation.
Overall
Maintained
Code review
Go module
Latest release
Releases this year
2,812 followers · starred Jan 2022
3,416 followers · starred Jan 2022
100 followers · starred Jun 2025
373 followers · starred Nov 2024
Pure-go (without cgo) implementation of SQLite driver for GORM
This driver has SQLite embedded, you don't need to install one separately.
import (
"github.com/glebarez/sqlite"
"gorm.io/gorm"
)
db, err := gorm.Open(sqlite.Open("sqlite.db"), &gorm.Config{})
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
Foreign-key constraint is disabled by default in SQLite. To activate it, use connection URL parameter:
db, err := gorm.Open(sqlite.Open(":memory:?_pragma=foreign_keys(1)"), &gorm.Config{})
More info: https://www.sqlite.org/foreignkeys.html
This driver tracks go-gorm/sqlite. The last upstream commit merged here is 525c431. Upstream behaviour fixes get ported, so migration and DDL parsing behave the same on both drivers.
Three differences are deliberate and stay:
github.com/glebarez/go-sqlite and modernc.org/sqlite rather than github.com/mattn/go-sqlite3DriverName defaults to sqlite, not upstream's sqlite3Translate reads the SQLite extended result code off the driver error, rather than marshalling the error to JSON and matching on field namesAnything that does not depend on the backend goes upstream first and comes back here as a port. First one: go-gorm/sqlite#247.
The standard GORM driver for SQLite has one major drawback: it is based on a Go-bindings of SQLite C-source (this is called cgo). This fact imposes following restrictions on Go developers:
go command to work properly (go run, go test, etc.).Instead, this driver is based on pure-Go implementation of SQLite (https://gitlab.com/cznic/sqlite), which is basically an original SQLite C-source AST, translated into Go! So, you may be sure you're using the original SQLite implementation under the hood.
Yes, The CI pipeline of this driver employs whole test base of GORM, which includes more than 12k tests (see badge on the page-top). Testing is run against latest major releases of Go:
In following environments:
Well, it's slower than CGo implementation, but not terribly. See the bechmark of underlying pure-Go driver vs CGo implementation.
Overall
Maintained
Code review
Go module
Latest release
Releases this year
2,812 followers · starred Jan 2022
3,416 followers · starred Jan 2022
100 followers · starred Jun 2025
373 followers · starred Nov 2024