pgsqlcli

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultSlowThreshold = time.Second
	DefaultSingularTable = true
)

Variables

This section is empty.

Functions

func Close added in v1.4.0

func Close()

Close 关闭数据库连接

func Connect

func Connect(addr, user, pwd, dbName string, options ...Option)

Connect 连接数据库

func DB

func DB(ctx context.Context) *gorm.DB

DB 获取数据库连接

func IsRecordNotFoundErr

func IsRecordNotFoundErr(err error) bool

IsRecordNotFoundErr 判断是否记录不存在错误

func StartTransaction

func StartTransaction(ctx context.Context, trans TransactionFunc) error

StartTransaction 开启事务

Types

type Option

type Option func(*Options)

func WithConnTimeout added in v1.4.0

func WithConnTimeout(timeout int) Option

WithConnTimeout 设置连接超时时间(秒)

func WithIgnoreRecordNotFoundError

func WithIgnoreRecordNotFoundError(ignoreRecordNotFoundError bool) Option

WithIgnoreRecordNotFoundError 忽略记录不存在错误

func WithParameterizedQueries

func WithParameterizedQueries(parameterizedQueries bool) Option

WithParameterizedQueries 使用参数化查询

func WithSSLMode added in v1.4.0

func WithSSLMode(sslMode string) Option

WithSSLMode 设置 SSL 模式("disable", "require", "verify-ca", "verify-full")

func WithSilent

func WithSilent(silent bool) Option

WithSilent 设置是否打印sql语句

func WithSlowThreshold

func WithSlowThreshold(slowThreshold time.Duration) Option

WithSlowThreshold 设置慢查询阈值

func WithTimeZone added in v1.4.0

func WithTimeZone(timeZone string) Option

WithTimeZone 设置时区(例如:"UTC", "Asia/Shanghai", "America/New_York")

type Options

type Options struct {
	TablePrefix   string // 表前缀
	SingularTable bool   // 使用单数表名

	// Logger
	Silent                    bool          // 是否打印 sql 语句
	ParameterizedQueries      bool          // 使用参数化查询
	IgnoreRecordNotFoundError bool          // 忽略记录不存在错误
	SlowThreshold             time.Duration // 慢查询阈值

	// Connection
	TimeZone    string // 时区配置,默认 "UTC"
	SSLMode     string // SSL 模式,默认 "disable"
	ConnTimeout int    // 连接超时时间(秒),默认 10
}

type TransactionFunc

type TransactionFunc func(tx *gorm.DB) error

Jump to

Keyboard shortcuts

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