Files
monitor/backend/internal/db/db.go
2025-12-02 23:20:10 +08:00

40 lines
847 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package db
import (
"context"
"database/sql"
)
// DB 定义数据库连接接口
type DB interface {
// 获取原始数据库连接
GetDB() *sql.DB
// 执行查询,返回多行结果
Query(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
// 执行查询,返回单行结果
QueryRow(ctx context.Context, query string, args ...interface{}) *sql.Row
// 执行更新操作INSERT、UPDATE、DELETE
Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
// 开始事务
BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
// 关闭数据库连接
Close() error
}
// Config 数据库配置结构体
type Config struct {
Type string
Host string
Port int
Username string
Password string
Database string
SSLMode string
Charset string
}