Documentation
¶
Overview ¶
Package gorm provides GORM helpers for Postgres. Package gorm 提供 Postgres 的 GORM 辅助函数。
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Connect ¶
Connect opens and verifies a Postgres-backed GORM DB. Call Connect(ctx, Config{...}). Connect 打开并验证基于 Postgres 的 GORM DB。 调用 Connect(ctx, Config{...})。
Example / 示例:
db, _ := gorm.Connect(ctx, gorm.Config{Host: "localhost", Port: 5432, User: "app", Database: "db"})
func NewLogger ¶
func NewLogger(opts LogOptions) logger.Interface
NewLogger returns a GORM logger backed by slog. Call NewLogger(LogOptions{Logger: base, Level: slog.LevelInfo}). NewLogger 返回基于 slog 的 GORM logger。 调用 NewLogger(LogOptions{Logger: base, Level: slog.LevelInfo})。
Types ¶
type Config ¶
type Config struct {
Host string
Port int
User string
Password string
Database string
SSLMode string
MaxOpenConns int
MaxIdleConns int
ConnMaxLifetime time.Duration
PreferSimpleProtocol bool
Logger logger.Interface
}
Config configures Connect. Config 配置 Connect。
type LogOptions ¶
type LogOptions struct {
Logger *slog.Logger
Level slog.Level
Disabled bool
IgnoreRecordNotFound bool
// IncludeQueryParams logs SQL query parameter values.
// Keep it false for production logs.
// IncludeQueryParams 记录 SQL 查询参数值。
// 生产日志保持 false。
IncludeQueryParams bool
}
LogOptions configures NewLogger. LogOptions 配置 NewLogger。
Click to show internal directories.
Click to hide internal directories.