diff --git a/go.work.sum b/go.work.sum index 792a87e9..68204aa0 100644 --- a/go.work.sum +++ b/go.work.sum @@ -1,4 +1,4 @@ -github.com/ncruces/go-sqlite3 v0.9.1/go.mod h1:jFoUbaCDNUS1KN5ZgFxN7bgcWoWfO0EOKeik9QAHZ08= +github.com/ncruces/go-sqlite3 v0.10.2/go.mod h1:8aGu9/G8lLZbvO6TXA0FXTP2liIefFmbpeXuhG4nJLw= golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= diff --git a/gormlite/README.md b/gormlite/README.md index 768a5b40..d4943a9b 100644 --- a/gormlite/README.md +++ b/gormlite/README.md @@ -14,13 +14,4 @@ import ( db, err := gorm.Open(gormlite.Open("gorm.db"), &gorm.Config{}) ``` -Checkout [https://gorm.io](https://gorm.io) for details. - -### Foreign-key constraint activation - -Foreign-key constraint is disabled by default in SQLite. To activate it, use connection URL parameter: -```go -db, err := gorm.Open(gormlite.Open( - "file:gorm.db?_pragma=busy_timeout(10000)&_pragma=foreign_keys(1)"), - &gorm.Config{}) -``` \ No newline at end of file +Checkout [https://gorm.io](https://gorm.io) for details. \ No newline at end of file diff --git a/gormlite/go.mod b/gormlite/go.mod index 22743fd0..ce6edadd 100644 --- a/gormlite/go.mod +++ b/gormlite/go.mod @@ -3,14 +3,14 @@ module github.com/ncruces/go-sqlite3/gormlite go 1.21 require ( - github.com/ncruces/go-sqlite3 v0.9.1 + github.com/ncruces/go-sqlite3 v0.10.2 gorm.io/gorm v1.25.5 ) require ( github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect - github.com/ncruces/julianday v0.1.5 // indirect + github.com/ncruces/julianday v1.0.0 // indirect github.com/tetratelabs/wazero v1.5.0 // indirect - golang.org/x/sys v0.13.0 // indirect + golang.org/x/sys v0.14.0 // indirect ) diff --git a/gormlite/go.sum b/gormlite/go.sum index e5fff6ea..cd925a35 100644 --- a/gormlite/go.sum +++ b/gormlite/go.sum @@ -2,15 +2,15 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= -github.com/ncruces/go-sqlite3 v0.9.1 h1:kV7Zy+ZNyHMfMyZeWc1Yyq+wtgYZDZdp2qAA/wfeMWo= -github.com/ncruces/go-sqlite3 v0.9.1/go.mod h1:jFoUbaCDNUS1KN5ZgFxN7bgcWoWfO0EOKeik9QAHZ08= -github.com/ncruces/julianday v0.1.5 h1:hDJ9ejiMp3DHsoZ5KW4c1lwfMjbARS7u/gbYcd0FBZk= -github.com/ncruces/julianday v0.1.5/go.mod h1:Dusn2KvZrrovOMJuOt0TNXL6tB7U2E8kvza5fFc9G7g= +github.com/ncruces/go-sqlite3 v0.10.2 h1:TBAhgQFU4rRyqeH1xKrvgAPmflZt0QEjDEJtETIo4vs= +github.com/ncruces/go-sqlite3 v0.10.2/go.mod h1:8aGu9/G8lLZbvO6TXA0FXTP2liIefFmbpeXuhG4nJLw= +github.com/ncruces/julianday v1.0.0 h1:fH0OKwa7NWvniGQtxdJRxAgkBMolni2BjDHaWTxqt7M= +github.com/ncruces/julianday v1.0.0/go.mod h1:Dusn2KvZrrovOMJuOt0TNXL6tB7U2E8kvza5fFc9G7g= github.com/tetratelabs/wazero v1.5.0 h1:Yz3fZHivfDiZFUXnWMPUoiW7s8tC1sjdBtlJn08qYa0= github.com/tetratelabs/wazero v1.5.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= +golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= gorm.io/gorm v1.25.5 h1:zR9lOiiYf09VNh5Q1gphfyia1JpiClIWG9hQaxB/mls= gorm.io/gorm v1.25.5/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= diff --git a/gormlite/sqlite.go b/gormlite/sqlite.go index db1eb3c4..99c7f43d 100644 --- a/gormlite/sqlite.go +++ b/gormlite/sqlite.go @@ -13,6 +13,7 @@ import ( "gorm.io/gorm/migrator" "gorm.io/gorm/schema" + "github.com/ncruces/go-sqlite3" "github.com/ncruces/go-sqlite3/driver" ) @@ -39,7 +40,9 @@ func (dialector _Dialector) Initialize(db *gorm.DB) (err error) { if dialector.Conn != nil { db.ConnPool = dialector.Conn } else { - conn, err := driver.Open(dialector.DSN, nil) + conn, err := driver.Open(dialector.DSN, func(c *sqlite3.Conn) error { + return c.Exec("PRAGMA foreign_keys = ON") + }) if err != nil { return err } diff --git a/gormlite/tests.patch b/gormlite/tests.patch index 01269e39..fbfac710 100644 --- a/gormlite/tests.patch +++ b/gormlite/tests.patch @@ -20,12 +20,3 @@ diff --git a/tests/tests_test.go b/tests/tests_test.go "gorm.io/driver/sqlserver" "gorm.io/gorm" "gorm.io/gorm/logger" -@@ -89,7 +91,7 @@ func OpenTestConnection(cfg *gorm.Config) (db *gorm.DB, err error) { - db, err = gorm.Open(mysql.Open(dbDSN), cfg) - default: - log.Println("testing sqlite3...") -- db, err = gorm.Open(sqlite.Open(filepath.Join(os.TempDir(), "gorm.db?_foreign_keys=on")), cfg) -+ db, err = gorm.Open(sqlite.Open("file:"+filepath.Join(os.TempDir(), "gorm.db")+"?_pragma=busy_timeout(1000)&_pragma=foreign_keys(1)"), cfg) - } - - if err != nil {