mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-06 04:01:05 +09:00
Clean up legacy copied&pasted code, introduce the unique "database connection" function. Move migration testing helper function PrepareTestEnv to a separate package. By the way, remove "shadow connection secrets" tricks: showing connection string on UI is useless --------- Co-authored-by: Nicolas <bircni@icloud.com>
35 lines
895 B
Go
35 lines
895 B
Go
//go:build sqlite
|
|
|
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package db
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
)
|
|
|
|
func init() {
|
|
setting.SupportedDatabaseTypes = append(setting.SupportedDatabaseTypes, "sqlite3")
|
|
makeSQLiteConnStr = makeSQLiteConnStrMattnCGO
|
|
}
|
|
|
|
func makeSQLiteConnStrMattnCGO(opts SQLiteConnStrOptions) (string, string, error) {
|
|
var params []string
|
|
params = append(params, "cache=shared")
|
|
params = append(params, "mode=rwc")
|
|
params = append(params, "_busy_timeout="+strconv.Itoa(opts.BusyTimeout))
|
|
params = append(params, "_txlock=immediate")
|
|
if opts.JournalMode != "" {
|
|
params = append(params, "_journal_mode="+opts.JournalMode)
|
|
}
|
|
connStr := fmt.Sprintf("file:%s?%s", opts.FilePath, strings.Join(params, "&"))
|
|
return "sqlite3", connStr, nil
|
|
}
|