pgorm

package
v1.1.27 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DbMysql = iota
	DbSqlite
)

Variables

This section is empty.

Functions

func AutoMigrate

func AutoMigrate(conf Config, opts ...DialOptionFunc) error

func GetDbByConf

func GetDbByConf(conf Config, opts ...DialOptionFunc) *gorm.DB

func GetDbByModel

func GetDbByModel(m SqlModel, opts ...DialOptionFunc) *gorm.DB

func GormIsErrRecordNotFound

func GormIsErrRecordNotFound(err error) (bool, error)

func NewClient

func NewClient(conf Config, opts ...DialOptionFunc) *client

func NewGormLogger

func NewGormLogger(opts ...GormLoggerOption) *gormLogger

func PrePing added in v1.1.25

func PrePing(conf Config, opts ...DialOptionFunc) error

func RegisterSqlModel deprecated

func RegisterSqlModel(conf Config, ms ...SqlModel)

RegisterSqlModel will bind the corresponding SqlModel to the specified database connection create by Config

Deprecated: This method will directly panic the error and is not recommended

func RegisterSqlModelWithConf

func RegisterSqlModelWithConf(conf Config, ms ...SqlModel) error

Types

type Config

type Config interface {
	GetDBType() DbType
	GetUid() string
	GetService() string
	DialGorm(...DialOptionFunc) (*gorm.DB, error)
}

type DbType added in v1.1.1

type DbType int

type DialOption added in v1.1.25

type DialOption struct {
	LogPrefix            string
	IgnoreRecordNotFound bool
	SlowThreshold        time.Duration
}

type DialOptionFunc added in v1.1.25

type DialOptionFunc func(opt *DialOption)

func WithDialIgnoreNotFound added in v1.1.25

func WithDialIgnoreNotFound() DialOptionFunc

func WithDialThreshold added in v1.1.25

func WithDialThreshold(threshold time.Duration) DialOptionFunc

func WithLogPrefix added in v1.1.25

func WithLogPrefix(prefix string) DialOptionFunc

type GormLoggerOption

type GormLoggerOption func(g *gormLogger)

func WithIgnoreRecordNotFound

func WithIgnoreRecordNotFound() GormLoggerOption

func WithPrefix

func WithPrefix(prefix string) GormLoggerOption

func WithSlowThreshold

func WithSlowThreshold(dur time.Duration) GormLoggerOption

type MysqlConfig

type MysqlConfig struct {
	Instance string
	Database string
	Username string
	Password string
}

func (*MysqlConfig) DialGorm

func (m *MysqlConfig) DialGorm(opts ...DialOptionFunc) (*gorm.DB, error)

func (*MysqlConfig) GetDBType

func (m *MysqlConfig) GetDBType() DbType

func (*MysqlConfig) GetService

func (m *MysqlConfig) GetService() string

func (*MysqlConfig) GetUid

func (m *MysqlConfig) GetUid() string

func (*MysqlConfig) TrimSpace

func (m *MysqlConfig) TrimSpace()

func (*MysqlConfig) Validate

func (m *MysqlConfig) Validate() error

type MysqlDsn

type MysqlDsn struct {
	DSN string
}

func (*MysqlDsn) DialGorm

func (m *MysqlDsn) DialGorm(opts ...DialOptionFunc) (*gorm.DB, error)

func (*MysqlDsn) GetDBType

func (m *MysqlDsn) GetDBType() DbType

func (*MysqlDsn) GetService

func (m *MysqlDsn) GetService() string

func (*MysqlDsn) GetUid

func (m *MysqlDsn) GetUid() string

func (*MysqlDsn) Validate

func (m *MysqlDsn) Validate() error

type SqlModel

type SqlModel interface {
	TableName() string
}

type SqliteConfig

type SqliteConfig struct {
	DbFile string
}

func (*SqliteConfig) DialGorm

func (s *SqliteConfig) DialGorm(opts ...DialOptionFunc) (*gorm.DB, error)

func (*SqliteConfig) GetDBType

func (s *SqliteConfig) GetDBType() DbType

func (*SqliteConfig) GetService

func (s *SqliteConfig) GetService() string

func (*SqliteConfig) GetUid

func (s *SqliteConfig) GetUid() string

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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