Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyDatabaseTypeNormalization() string
- func Close() error
- func GetDBInstance() *gorm.DB
- func Initialize() error
- func IsSQLite() bool
- func NormalizeDatabaseType(databaseType string) string
- func ReclaimSpace(ctx context.Context) error
- func SetVersionID(id string)
- func StorageSize() (int64, error)
- func SupportedDatabaseTypes() string
Constants ¶
const DatabaseTypeSQLite = "sqlite"
DatabaseTypeSQLite is the only supported main-database driver.
const SystemVersionKey = "system_version"
SystemVersionKey 是记录“上次启动所用版本标识”的配置键(存于 configs 表)。 取代旧的 ./data/.komari-version 文件:版本标识随配置库一起备份/恢复, 也避免额外的裸文件依赖。
Variables ¶
var ( // DatabaseType and DatabaseFile are populated from the -t/--db-type and // -d/--database startup flags (see cmd/root.go) before Initialize runs. DatabaseType string DatabaseFile string )
Functions ¶
func ApplyDatabaseTypeNormalization ¶
func ApplyDatabaseTypeNormalization() string
ApplyDatabaseTypeNormalization normalizes the package-level DatabaseType in place and returns the normalized value.
func GetDBInstance ¶
GetDBInstance 返回全局数据库实例。 为兼容既有大量调用点,这里保留“出错即退出”的语义; 需要错误处理的启动流程应优先调用 Initialize()。
func Initialize ¶
func Initialize() error
Initialize 显式初始化数据库连接与表结构,仅执行一次。 与 GetDBInstance 不同,Initialize 返回错误而非直接退出进程, 便于启动生命周期统一处理错误、以及在测试/CLI 命令中做隔离。
func IsSQLite ¶
func IsSQLite() bool
IsSQLite reports whether the configured database type is SQLite.
func NormalizeDatabaseType ¶
NormalizeDatabaseType lowercases and trims databaseType, defaulting to DatabaseTypeSQLite when empty.
func ReclaimSpace ¶
ReclaimSpace checkpoints the main database WAL and rewrites the SQLite file.
func SetVersionID ¶
func SetVersionID(id string)
SetVersionID 设置当前构建的版本标识(通常为 CurrentVersion+"-"+VersionHash), 用于版本升级检测与自动备份。应在 Initialize() 之前调用;为空则跳过升级备份。
func StorageSize ¶
StorageSize returns the bytes occupied by the main SQLite database and its WAL/SHM sidecar files.
func SupportedDatabaseTypes ¶
func SupportedDatabaseTypes() string
SupportedDatabaseTypes lists the database types Initialize accepts.
Types ¶
This section is empty.