fix: max open conns for SQLite (#781)

This commit is contained in:
boojack 2022-12-19 18:28:15 +08:00 committed by GitHub
parent 726285e634
commit 6c17f94ef6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -43,11 +43,12 @@ func (db *DB) Open(ctx context.Context) (err error) {
}
// Connect to the database without foreign_key.
sqlDB, err := sql.Open("sqlite3", db.profile.DSN+"?_foreign_keys=0")
sqliteDB, err := sql.Open("sqlite3", db.profile.DSN+"?_foreign_keys=0")
if err != nil {
return fmt.Errorf("failed to open db with dsn: %s, err: %w", db.profile.DSN, err)
}
db.Db = sqlDB
sqliteDB.SetMaxOpenConns(1)
db.Db = sqliteDB
if db.profile.Mode == "dev" {
// In dev mode, we should migrate and seed the database.