db_gorm

package
v1.7.10 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DB *gorm.DB
)

Functions

func Connect

func Connect(options ...Options) (trx.Manager, error)

func LoadTx

func LoadTx(ctx trx.Context) (*gorm.DB, error)

func NewClient

func NewClient(opts ...Options) (*gorm.DB, error)

func NewTxManager

func NewTxManager(conn *gorm.DB) trx.Manager

func WithTx

func WithTx(ctx context.Context, fn func(tx *gorm.DB) error) error

Types

type BaseCrud

type BaseCrud interface {
	Create(context.Context) error
	Update(context.Context) error
	Delete(context.Context) error
	Find(context.Context) error
}

type Config

type Config struct {
	ShowSql       bool
	SlowThreshold time.Duration
	Dsn           string
	DBType        DBType
}

func NewConfig

func NewConfig(opts ...Options) *Config

type DBType

type DBType int
const (
	Mysql DBType = iota + 1
	Postgres
	SQLite
)

type GormTransaction

type GormTransaction struct {
	context.Context
	// contains filtered or unexported fields
}

func (*GormTransaction) Commit

func (t *GormTransaction) Commit() error

func (*GormTransaction) Rollback

func (t *GormTransaction) Rollback()

func (*GormTransaction) RollbackTo

func (t *GormTransaction) RollbackTo(name string)

func (*GormTransaction) SavePoint

func (t *GormTransaction) SavePoint(name string)

type GormTxManager

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

func (*GormTxManager) Start

func (t *GormTxManager) Start(ctx context.Context) (trx.Context, error)

type ID

type ID int64

type Logger

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

func NewLogger

func NewLogger(options *LoggerOptions) *Logger

func (*Logger) Error

func (l *Logger) Error(_ context.Context, s string, i ...interface{})

func (*Logger) Info

func (l *Logger) Info(_ context.Context, s string, i ...interface{})

func (*Logger) LogMode

func (l *Logger) LogMode(level logger.LogLevel) logger.Interface

func (*Logger) Trace

func (l *Logger) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)

func (*Logger) Warn

func (l *Logger) Warn(_ context.Context, s string, i ...interface{})

type LoggerOptions

type LoggerOptions struct {
	SlowThreshold             time.Duration
	IgnoreRecordNotFoundError bool
	LogLevel                  plumeLogger.Level
}

type Model

type Model struct {
	ID        ID
	CreatedAt time.Time
	UpdatedAt time.Time
}

type Options

type Options interface {
	Apply(c *Config)
}

func ParseMysqlConfig

func ParseMysqlConfig(v *viper.Viper) []Options

func ParseOptions

func ParseOptions(v *viper.Viper) []Options

func ParsePostgresSqlConfig

func ParsePostgresSqlConfig(v *viper.Viper) []Options

func ParseSqliteOptions

func ParseSqliteOptions(v *viper.Viper) []Options

func WithDBType

func WithDBType(dBType DBType) Options

func WithDsn

func WithDsn(dsn string) Options

WithDsn, dsn example: - for postgres: host=localhost user=postgres password=123456 dbname=gorm port=5432 sslmode=disable TimeZone=Asia/Shanghai - for mysql: root:123456@tcp(127.0.0.1:3306)/gorm?charset=utf8mb4&parseTime=True&loc=Local

func WithShowSql

func WithShowSql(showSql bool) Options

func WithSlowThreshold

func WithSlowThreshold(slowThreshold time.Duration) Options

type SoftDeletion

type SoftDeletion struct {
	DeletedAt gorm.DeletedAt
}

Directories

Path Synopsis
dal
gen
example/persistence
Package persistence.
Package persistence.

Jump to

Keyboard shortcuts

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