pgorm

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DbMysql = iota
	DbSqlite
)

Variables

This section is empty.

Functions

func AutoMigrate

func AutoMigrate(conf Config) error

func GetDbByConf

func GetDbByConf(conf Config) *gorm.DB

func GetDbByModel

func GetDbByModel(m SqlModel) *gorm.DB

func GormIsErrRecordNotFound

func GormIsErrRecordNotFound(err error) (bool, error)

func NewClient

func NewClient(conf Config) *client

func NewGormLogger

func NewGormLogger(opts ...GormLoggerOption) *gormLogger

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() (*gorm.DB, error)
}

type DbType added in v1.1.1

type DbType int

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() (*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() (*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() (*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