gorm

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 9 Imported by: 0

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 BuildDSN

func BuildDSN(cfg Config) (string, error)

BuildDSN returns a Postgres DSN. BuildDSN 返回 Postgres DSN。

func Connect

func Connect(ctx context.Context, cfg Config) (*gorm.DB, error)

Connect opens and verifies a GORM DB with Postgres driver. Connect 使用 Postgres 驱动打开并验证 GORM DB。

Example / 示例:

db, _ := gorm.Connect(ctx, gorm.Config{Host: "localhost", Port: 5432, User: "app", Name: "db"})

func NewLogger

func NewLogger(opts LogOptions) logger.Interface

NewLogger builds a GORM logger using the provided logging.Logger. NewLogger 使用指定的 logging.Logger 构建 GORM logger。

func Ping

func Ping(ctx context.Context, db *gorm.DB) error

Ping performs a lightweight health check using the underlying sql.DB. Ping 使用底层 sql.DB 执行轻量健康检查。

Types

type Config

type Config struct {
	Host                 string
	Port                 int
	User                 string
	Password             string
	Name                 string
	SSLMode              string
	MaxOpenConns         int
	MaxIdleConns         int
	ConnMaxLifetime      time.Duration
	PreferSimpleProtocol bool
	Logger               logger.Interface
}

Config holds Postgres connection settings. Config 包含 Postgres 连接配置。

type LogOptions

type LogOptions struct {
	Logger               logging.Logger
	Level                logging.Level
	Disabled             bool
	IgnoreRecordNotFound bool
}

LogOptions configures a GORM logger backed by EiluneKit logging. LogOptions 配置基于 EiluneKit logging 的 GORM logger。

Jump to

Keyboard shortcuts

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