gorm

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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