Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solve database is locked error #18

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ func init() {
Logger: logger.Discard,
})
checkErr(err)

// According to https://github.com/mattn/go-sqlite3/issues/274#issuecomment-191597862,
// solve "database is locked" error using `db.SetMaxOpenConns(1)`
sqlDB, err := DB.DB()
checkErr(err)
sqlDB.SetMaxOpenConns(1)

DB.AutoMigrate(&ProxyURL{})

}

func CreateProxyURL(url string) error {
Expand Down Expand Up @@ -93,6 +101,7 @@ func RandomProxyURL(regionFlag int, strategyFlag int) (pu string, markUnavail fu
switch regionFlag {
case 1:
tx = DB.Raw(fmt.Sprintf("SELECT * FROM %s WHERE available = ? AND can_bypass_gfw = ? ORDER BY RANDOM() LIMIT 1;", proxyURL.TableName()), true, false).Scan(&proxyURL)

case 2:
tx = DB.Raw(fmt.Sprintf("SELECT * FROM %s WHERE available = ? AND can_bypass_gfw = ? ORDER BY RANDOM() LIMIT 1;", proxyURL.TableName()), true, true).Scan(&proxyURL)
default:
Expand Down