model

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package model is the initial database driver and define the data structures corresponding to the tables.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCacheNotFound No hit cache
	ErrCacheNotFound = redis.Nil

	// ErrRecordNotFound no records found
	ErrRecordNotFound = gorm.ErrRecordNotFound
)

Functions

func CloseMysql

func CloseMysql() error

CloseMysql close mysql

func CloseRedis

func CloseRedis() error

CloseRedis close redis

func GetDB

func GetDB() *gorm.DB

GetDB get db

func GetRedisCli

func GetRedisCli() *redis.Client

GetRedisCli get redis client

func InitCache

func InitCache(cType string)

InitCache initial cache

func InitMysql

func InitMysql()

InitMysql connect mysql

func InitRedis

func InitRedis()

InitRedis connect redis

Types

type CacheType

type CacheType struct {
	CType string        // cache type  memory or redis
	Rdb   *redis.Client // if CType=redis, Rdb cannot be empty
}

CacheType cache type

func GetCacheType

func GetCacheType() *CacheType

GetCacheType get cacheType

type UserExample

type UserExample struct {
	mysql.Model `gorm:"embedded"`

	Name     string `gorm:"column:name;NOT NULL" json:"name"`         // username
	Password string `gorm:"column:password;NOT NULL" json:"password"` // password
	Email    string `gorm:"column:email;NOT NULL" json:"email"`       // email
	Phone    string `gorm:"column:phone;NOT NULL" json:"phone"`       // phone number
	Avatar   string `gorm:"column:avatar;NOT NULL" json:"avatar"`     // avatar
	Age      int    `gorm:"column:age;NOT NULL" json:"age"`           // age
	Gender   int    `gorm:"column:gender;NOT NULL" json:"gender"`     // gender, 1:Male, 2:Female, other values:unknown
	Status   int    `gorm:"column:status;NOT NULL" json:"status"`     // account status, 1:inactive, 2:activated, 3:blocked
	LoginAt  int64  `gorm:"column:login_at;NOT NULL" json:"loginAt"`  // login timestamp
}

UserExample object fields mapping table

func (*UserExample) TableName

func (table *UserExample) TableName() string

TableName get table name

Jump to

Keyboard shortcuts

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