models

package
v0.0.0-...-b9f5497 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2017 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DB *gorm.DB
)

Functions

func GetDbWithGorm

func GetDbWithGorm(dialect string, host string, port int64, dbname string, user string, password string) (*gorm.DB, error)

GetDbWithGorm return the github.com/jinzhu/gorm db

func MigrateAll

func MigrateAll()

Migrate runs migrations on the global

func RegisterModels

func RegisterModels(models ...interface{})

RegisterModels registers models

Types

type BaseModel

type BaseModel struct {
	CreatedTimeStr string     `json:"createdTime" gorm:"-"`
	CreatedTime    *time.Time `json:"-" gorm:"column:created_time; type:datetime; not null; default:current_timestamp"`
	UpdatedTime    *time.Time `json:"-" gorm:"column:updated_time; type:datetime"`
	DeletedTime    *time.Time `json:"-" gorm:"column:deleted_time; type:datetime"`
	IsDeleted      int64      `json:"-" gorm:"column:is_deleted; type:tinyint(1); not null; default:0"`
}

func (*BaseModel) AfterFind

func (this *BaseModel) AfterFind()

type BmbUser

type BmbUser struct {
	ID        int64  `json:"-" gorm:"column:id; type:int(11); primary_key; auto_increment"`
	UserID    string `` /* 126-byte string literal not displayed */
	Username  string `json:"username" gorm:"column:username; type:varchar(20); not null"`
	HeadPhoto string `json:"headPhoto" gorm:"column:head_photo; type:varchar(200); not null"`
	Sex       int64  `json:"sex" gorm:"column:sex; type:tinyint(1); not null; default:1"`
	Pid       int64  `json:"pid" gorm:"column:pid; type:tinyint(4); not null; default:1"`
	Cid       int64  `json:"cid" gorm:"column:cid; type:tinyint(4); not null; default:1"`
	BaseModel
}

func (*BmbUser) FindUserByUserID

func (this *BmbUser) FindUserByUserID(userID string) (one BmbUser)

func (BmbUser) TableName

func (BmbUser) TableName() string

type Model

type Model struct {
	*gorm.DB
	// contains filtered or unexported fields
}

Model facilitate database interactions, support mysql

func NewModel

func NewModel() *Model

NewModel returns a new Model without opening database connection

func NewModelWithConfig

func NewModelWithConfig(dialect string, host string, port int64, dbname string, user string, password string) (*Model, error)

NewModelWithConfig creates a new model, and opens database connection based on cfg settings

func (*Model) AddModels

func (m *Model) AddModels(values ...interface{}) error

AddModels add the values to the models registry

func (*Model) AutoMigrateAll

func (m *Model) AutoMigrateAll()

AutoMigrateAll runs migrations for all the registered models

func (*Model) IsOpenDB

func (m *Model) IsOpenDB() bool

IsOpenDB returns true if the Model has already established connection to the database

func (*Model) OpenWithConfig

func (m *Model) OpenWithConfig(dialect string, host string, port int64, dbname string, user string, password string) error

OpenWithConfig opens database connection with the settings found in cfg

Jump to

Keyboard shortcuts

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