682aa3907a
- refine config loading with --config and current-directory .env - improve sqlite busy handling and runtime DB tuning - restore telegram payment notification and wallet input flow - add behavior-based config and callback recovery tests
36 lines
649 B
Go
36 lines
649 B
Go
package dao
|
|
|
|
import (
|
|
"database/sql"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func configureSQLite(db *gorm.DB, maxOpenConns int) (*sql.DB, error) {
|
|
sqlDB, err := db.DB()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if maxOpenConns <= 0 {
|
|
maxOpenConns = 1
|
|
}
|
|
sqlDB.SetMaxOpenConns(maxOpenConns)
|
|
sqlDB.SetMaxIdleConns(1)
|
|
|
|
if err := db.Exec("PRAGMA journal_mode=WAL;").Error; err != nil {
|
|
return nil, err
|
|
}
|
|
if err := db.Exec("PRAGMA synchronous=NORMAL;").Error; err != nil {
|
|
return nil, err
|
|
}
|
|
if err := db.Exec("PRAGMA busy_timeout=5000;").Error; err != nil {
|
|
return nil, err
|
|
}
|
|
if err := sqlDB.Ping(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return sqlDB, nil
|
|
}
|