2023-06-06 12:37:54 +01:00
|
|
|
# GORM SQLite Driver
|
|
|
|
|
|
2023-06-07 18:03:27 +01:00
|
|
|
[](https://pkg.go.dev/github.com/ncruces/go-sqlite3/gormlite)
|
|
|
|
|
|
2023-06-06 12:37:54 +01:00
|
|
|
## Usage
|
|
|
|
|
|
|
|
|
|
```go
|
|
|
|
|
import (
|
|
|
|
|
_ "github.com/ncruces/go-sqlite3/embed"
|
|
|
|
|
"github.com/ncruces/go-sqlite3/gormlite"
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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(
|
2023-06-24 02:18:56 +01:00
|
|
|
"file:gorm.db?_pragma=busy_timeout(10000)&_pragma=foreign_keys(1)"),
|
2023-06-06 12:37:54 +01:00
|
|
|
&gorm.Config{})
|
|
|
|
|
```
|