mysql

package
v0.0.0-...-584e80b Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package mysql

Define mysql configuration

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(instance *DbConfig) (*gorm.DB, error)

Connect to the database and return database handle

Types

type Commodity

type Commodity struct {
	gorm.Model
	Name        string
	Description string
	Price       float64
	Owner       string
	Img         string
}

Commodity 映射商品表

type CommodityKind

type CommodityKind struct {
	ID          uint   `gorm:"primaryKey;autoIncrement"`
	CommodityID uint   `gorm:"not null"`
	Kind        string `gorm:"not null"`
}

CommodityKind 商品种类表

type DbConfig

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

func DbBuilder

func DbBuilder() *DbConfig

func (*DbConfig) Build

func (db *DbConfig) Build() DbConfig

func (*DbConfig) LoadDbConfigFromViper

func (db *DbConfig) LoadDbConfigFromViper(v *viper.Viper) (string, error)

LoadDbConfigFromViper return a connect string

func (*DbConfig) String

func (db *DbConfig) String() string

convert mysql config struct to string

func (*DbConfig) WithDBName

func (db *DbConfig) WithDBName(dbname string) *DbConfig

func (*DbConfig) WithHost

func (db *DbConfig) WithHost(host string) *DbConfig

func (*DbConfig) WithName

func (db *DbConfig) WithName(name string) *DbConfig

func (*DbConfig) WithPassword

func (db *DbConfig) WithPassword(password string) *DbConfig

func (*DbConfig) WithPort

func (db *DbConfig) WithPort(port int) *DbConfig

type Order

type Order struct {
	OrderID       uint           `gorm:"primaryKey;autoIncrement"`
	CustomerID    uint           `gorm:"not null"`
	OrderDate     time.Time      `gorm:"not null"`
	TotalAmount   float64        `gorm:"not null"`
	Status        string         `gorm:"type:enum('pending','processing','shipped','completed','cancelled');default:'pending';not null"`
	PaymentMethod string         `gorm:"size:50"`
	CreatedAt     time.Time      `gorm:"not null"`
	UpdatedAt     time.Time      `gorm:"not null"`
	DeletedAt     gorm.DeletedAt `gorm:"index"`
}

Order 映射订单表

type OrderItem

type OrderItem struct {
	ItemID    uint           `gorm:"primaryKey;autoIncrement"`
	OrderId   uint           `gorm:"not null"`
	ProductId uint           `gorm:"not null"`
	Quantity  uint           `gorm:"not null"`
	Price     float64        `gorm:"not null"`
	Order     Order          `gorm:"foreignKey:OrderID"`
	Product   Commodity      `gorm:"foreignKey:ProductId"`
	CreatedAt time.Time      `gorm:"not null"`
	UpdatedAt time.Time      `gorm:"not null"`
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

OrderItem 订单商品关联表

type RolePermission

type RolePermission struct {
	ID         uint   `gorm:"primaryKey;autoIncrement"`
	Role       string `gorm:"not null"`
	Permission string `gorm:"not null"`
}

RolePermission 角色权限关联表

type User

type User struct {
	gorm.Model
	Username    string `gorm:"not null"`
	RealName    string
	Password    []byte `gorm:"not null"`
	PhoneNumber string
	Role        string `gorm:"not null"`
	Status      string `gorm:"default:'offline'"`
}

User 用户表模型

type UserFavorite

type UserFavorite struct {
	ID          uint `gorm:"primaryKey;autoIncrement"`
	UserID      uint `gorm:"not null"`
	CommodityID uint `gorm:"not null"`
}

UserFavorite 用户收藏商品表

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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