dbcore

package
v1.1.0-beta.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const DatabaseTypeSQLite = "sqlite"

DatabaseTypeSQLite is the only supported main-database driver.

View Source
const SystemVersionKey = "system_version"

SystemVersionKey 是记录“上次启动所用版本标识”的配置键(存于 configs 表)。 取代旧的 ./data/.komari-version 文件:版本标识随配置库一起备份/恢复, 也避免额外的裸文件依赖。

Variables

View Source
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 Close

func Close() error

Close 关闭底层数据库连接,供关闭流程调用。

func GetDBInstance

func GetDBInstance() *gorm.DB

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

func NormalizeDatabaseType(databaseType string) string

NormalizeDatabaseType lowercases and trims databaseType, defaulting to DatabaseTypeSQLite when empty.

func ReclaimSpace

func ReclaimSpace(ctx context.Context) error

ReclaimSpace checkpoints the main database WAL and rewrites the SQLite file.

func SetVersionID

func SetVersionID(id string)

SetVersionID 设置当前构建的版本标识(通常为 CurrentVersion+"-"+VersionHash), 用于版本升级检测与自动备份。应在 Initialize() 之前调用;为空则跳过升级备份。

func StorageSize

func StorageSize() (int64, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL