model

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2024 License: MIT Imports: 12 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 CloseDB

func CloseDB() error

CloseDB close db

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 GetSnowId added in v1.0.2

func GetSnowId() snowflake.ID

func GetSnowNode added in v1.0.2

func GetSnowNode() *snowflake.Node

GetSnowNode get db

func InitCache

func InitCache(cType string)

InitCache initial cache

func InitDB

func InitDB()

InitDB connect database

func InitMysql

func InitMysql()

InitMysql connect mysql

func InitPostgresql

func InitPostgresql()

InitPostgresql connect postgresql

func InitRedis

func InitRedis()

InitRedis connect redis

func InitSnowNode added in v1.0.2

func InitSnowNode()

InitSnowNode connect redis

func InitSqlite

func InitSqlite()

InitSqlite connect sqlite

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 {
	ggorm.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