database

package
v0.23.6 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database interface {
	Open() error
	DB() *gorm.DB
	AutoMigrate(values ...interface{}) (Database, error)
	Close()
	// contains filtered or unexported methods
}

Database 数据库

func NewDatabase

func NewDatabase(opts ...Option) Database

NewDatabase ..

type Model added in v0.4.1

type Model struct {
	CreatedAt int64          `gorm:"comment:'记录创建时间'" json:"createdAt"`
	UpdatedAt int64          `gorm:"comment:'最后一次更新时间'" json:"updatedAt"`
	DeletedAt gorm.DeletedAt `gorm:"index;comment:'软删除时间'" json:"deletedAt"`
}

Model 替代 gorm.Model,无 id,需要自定义主键 时间为 秒,

type ModelID added in v0.4.1

type ModelID struct {
	ID uint `gorm:"primaryKey;AUTO_INCREMENT" json:"id"`
	Model
}

ModelID 替代 gorm.Model,带自增 id

type ModelNoJSON added in v0.20.6

type ModelNoJSON struct {
	CreatedAt int64          `gorm:"comment:'记录创建时间'" json:"-"`
	UpdatedAt int64          `gorm:"comment:'最后一次更新时间'" json:"-"`
	DeletedAt gorm.DeletedAt `gorm:"index;comment:'软删除时间'" json:"-"`
}

ModelNoJSON 同 Model

type Option

type Option func(Database)

Option ..

func WithDBName

func WithDBName(dbname string) Option

WithDBName 数据库名称

func WithDialect

func WithDialect(dialect string) Option

WithDialect 数据库 dialect

func WithHost

func WithHost(host string) Option

WithHost 数据库地址

func WithLogDebug

func WithLogDebug(logDebug bool) Option

WithLogDebug 是否打印debug日志

func WithMaxConnLifeTime

func WithMaxConnLifeTime(maxConnLifeTime int) Option

WithMaxConnLifeTime 数据库 maxConnLifeTime

func WithMaxIdleConns

func WithMaxIdleConns(maxIdleConns int) Option

WithMaxIdleConns 数据库 maxIdleConns

func WithMaxOpenConns

func WithMaxOpenConns(maxOpenConns int) Option

WithMaxOpenConns 数据库 maxOpenConns

func WithPassword

func WithPassword(password string) Option

WithPassword 数据库密码

func WithPort

func WithPort(port int) Option

WithPort 数据库端口号

func WithUsername

func WithUsername(username string) Option

WithUsername 数据库用户名

Jump to

Keyboard shortcuts

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