orm

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2020 License: MIT Imports: 11 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 struct {
	ID        uint64 `gorm:"primaryKey;column:id;" json:"id"`
	CreatedAt int64  `gorm:"column:created_at;index:created_at" json:"created_at"`
	UpdatedAt int64  `gorm:"column:updated_at;index:updated_at" json:"updated_at"`
}

Database gorm supported data nesting, custom data table structure imported into the structure, will have these three fields by default

func (*Database) BeforeCreate

func (db *Database) BeforeCreate(_ *gorm.DB) error

BeforeCreate create hook, will force to set created_at and updated_at field, custom structure can re implement the method

func (*Database) BeforeUpdate

func (db *Database) BeforeUpdate(_ *gorm.DB) (err error)

BeforeUpdate update hook

type Loader

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

Loader orm init tool

func NewORM

func NewORM(logger *logrus.Entry) *Loader

NewORM new orm

func (*Loader) DB

func (loader *Loader) DB(db ...string) *gorm.DB

DB get *gorm.DB If the DB parameter is passed in, the connection of the specified configuration node in the configuration file will be obtained. Otherwise, the connection of the default master node will be taken

func (*Loader) OnChange

func (loader *Loader) OnChange(viper *viper.Viper)

OnChange when the configuration file changes, the connection to the database will be re established

type Node

type Node struct {
	LogLevel string `mapstructure:"log_level"`
	DSN      string `mapstructure:"dsn"`
	MaxIdle  int    `mapstructure:"max_idle"`
	MaxOpen  int    `mapstructure:"max_open"`
	Replicas struct {
		Connections []string `mapstructure:"connections"` // all replica set connections
		MaxIdle     int      `mapstructure:"max_idle"`
		MaxOpen     int      `mapstructure:"max_open"`
	} `mapstructure:"replicas"`
}

Node config info

Jump to

Keyboard shortcuts

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