storage

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package storage 提供持久化存储与数据库初始化封装

该包负责应用的数据存储初始化、迁移与访问封装,抽象底层数据库细节

Index

Constants

This section is empty.

Variables

View Source
var GlobalConfig = structs.Configs{}

GlobalConfig 全局配置缓存,启动时从数据库加载

Functions

func InitDB

func InitDB(dbPath string) (*gorm.DB, error)

InitDB 初始化 SQLite 数据库并自动迁移所有表结构。 支持内存数据库模式(dbPath 以 :memory: 结尾)。 当 ALKAID0_TEST_LESS_MEMORY_MODE 环境变量设置时, 内存模式降级为临时文件模式以节省 RAM(用于资源受限的测试环境)。

func InitStorage

func InitStorage(dataPath string, dbFile string) (*gorm.DB, error)

InitStorage 初始化 db

func New

func New() gormLogger.Interface

New 创建 GORM 自定义日志器,默认慢查询阈值为 300ms

func ReadGlobalConfigs

func ReadGlobalConfigs(db *gorm.DB) error

ReadGlobalConfigs 从数据库读取全局配置并存入 GlobalConfig

func SaveGlobalConfigs

func SaveGlobalConfigs(db *gorm.DB) error

SaveGlobalConfigs 保存全局配置

Types

type Level

type Level gormLogger.LogLevel

Level gorm 日志级别别名,用于内部日志级别比较与设置

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger 为 GORM 自定义 logger 实现 使用标准库 log 输出,并支持慢查询阈值与彩色输出

func (*Logger) Error

func (l *Logger) Error(ctx context.Context, msg string, data ...any)

Error 打印错误级别日志

func (*Logger) Info

func (l *Logger) Info(ctx context.Context, msg string, data ...any)

Info 打印信息级别日志

func (*Logger) LogMode

func (l *Logger) LogMode(level gormLogger.LogLevel) gormLogger.Interface

LogMode 设置日志级别

func (*Logger) Trace

func (l *Logger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

Trace 跟踪 SQL 执行耗时与错误

func (*Logger) Warn

func (l *Logger) Warn(ctx context.Context, msg string, data ...any)

Warn 打印警告级别日志

Directories

Path Synopsis
Package structs 定义存储层的数据结构与 GORM 模型
Package structs 定义存储层的数据结构与 GORM 模型

Jump to

Keyboard shortcuts

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