gormx

package
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 19 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultMaxOpenCount = 40
	DefaultMaxIdleCount = 20
	DefaultMaxLifeTime  = time.Hour
)

Variables

This section is empty.

Functions

func CreateSSHConn added in v0.9.0

func CreateSSHConn(cnf *SSHConfig) (*ssh.Client, error)

func Dsn2DB

func Dsn2DB(dsnURL string, withLog bool) (*gorm.DB, error)

Dsn2DB from dsn json string to db

func ForUpdate added in v0.0.4

func ForUpdate(db *gorm.DB, lock bool) *gorm.DB

ForUpdate : add "for update" for "select" or not

func IsDupError

func IsDupError(err error) bool

IsDupError is duplicated key error

func IsNotFoundErr

func IsNotFoundErr(err error) bool

IsNotFoundErr is not found error

func New

func New(dsn string, opts ...Option) (*gorm.DB, error)

New : new *gorm.DB

func NewDBByDsn added in v0.9.1

func NewDBByDsn(dsn *Dsn, opts ...Option) (*gorm.DB, error)

NewDBByDsn : new *gorm.DB by Dsn

func NewDBBySSH added in v0.9.0

func NewDBBySSH(sshCnf *SSHConfig, dsn *Dsn, opts ...Option) (*gorm.DB, error)

NewDBBySSH new db by ssh

func NewGorm

func NewGorm(dsn string, maxOpenConn, maxIdle int, maxLifeTime time.Duration, log bool) (*gorm.DB, error)

NewGorm 获取一个db客户端 --maxOpenConn 最大打开连接数

func ToGRPCDupErr

func ToGRPCDupErr(err error) error

ToGRPCDupErr err to grpc duplicate

func ToGRPCNotFoundErr

func ToGRPCNotFoundErr(err error) error

ToGRPCNotFoundErr error to grpc

func Transact

func Transact(db *gorm.DB, fnList ...GormProcFn) (err error)

Transact : db transaction

Types

type Dsn

type Dsn struct {
	User     string            `json:"user" toml:"user"`
	Password string            `json:"password" toml:"password"`
	Proto    string            `json:"proto" toml:"proto"`
	Host     string            `json:"host" toml:"host"`
	Schema   string            `json:"schema" toml:"schema"`
	Options  map[string]string `json:"options" toml:"options"`
}

func (*Dsn) String

func (d *Dsn) String() string

func (*Dsn) UseDefault added in v0.1.8

func (d *Dsn) UseDefault() string

type GormProcFn

type GormProcFn func(txn *gorm.DB) error

GormProcFn gorm func

func Combine added in v0.8.5

func Combine(fns ...GormProcFn) GormProcFn

Combine : combine serial GormProcFn to one to avoid append

type Option

type Option func(*_Option)

func WithLog

func WithLog() Option

func WithLogSwitch added in v0.9.0

func WithLogSwitch(on bool) Option

func WithMaxIdle

func WithMaxIdle(maxIdle int) Option

func WithMaxLifeTime

func WithMaxLifeTime(maxLifeTime time.Duration) Option

func WithMaxOpenConn

func WithMaxOpenConn(maxOpenConn int) Option

type SSHConfig added in v0.9.0

type SSHConfig struct {
	Host string `json:"host" toml:"host"`
	User string `json:"user" toml:"user"`
	Pk   string `json:"pk" toml:"pk"`
	Port int    `json:"port" toml:"port"`
}

type SSHDialer added in v0.9.0

type SSHDialer struct {
	// contains filtered or unexported fields
}

func (*SSHDialer) Dial added in v0.9.0

func (d *SSHDialer) Dial(ctx context.Context, addr string) (net.Conn, error)

func (*SSHDialer) Register added in v0.9.0

func (d *SSHDialer) Register()

Jump to

Keyboard shortcuts

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