definition

package
v0.0.0-...-8b2948b Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2017 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HasMany    = "has_many"
	BelongsTo  = "belongs_to"
	HasOne     = "has_one"
	ManyToMany = "many_to_many"
)

Gorm field relations Kind

Variables

View Source
var (
	PreloadShop            = CreatePreload(&Shop{})
	PreloadOrder           = CreatePreload(&Order{})
	PreloadCacheManageHash = CreatePreload(&CacheManageHash{})
)

Functions

func BetweenCreateTime

func BetweenCreateTime(start, end time.Time) func(db *gorm.DB) *gorm.DB

func Connect

func Connect(dbtype, dbaddress string, args map[string]interface{}) (*gorm.DB, error)

func Migrate

func Migrate(db *gorm.DB) error

func NestedSelect

func NestedSelect(table interface{}, selects []string) func(db *gorm.DB) *gorm.DB

Types

type CacheManageHash

type CacheManageHash struct {
	gorm.Model
	Key    string                 `gorm:"type:varchar(256);unique_index"`
	Fields []CacheManageHashField `gorm:"ForeignKey:HashId"`
}

db struct

type CacheManageHashField

type CacheManageHashField struct {
	ID     uint   `gorm:"primary_key"`
	HashId uint   `gorm:"index:idx_hash_field"`
	Field  string `gorm:"type:varchar(100);index:idx_hash_field"`
	Value  string
}

db struct

type Discount

type Discount struct {
	Full   int
	Reduce int
	ShopId uint `gorm:"index"`
}

db struct

type Order

type Order struct {
	gorm.Model
	ShopAddr string `gorm:"type:varchar(1024);index"`
	Shop     Shop   `gorm:"ForeignKey:ShopAddr"`

	Tag   string     `gorm:"type:varchar(64);unique_index:idx_tag_endat"`
	Items []UserItem `gorm:"ForeignKey:OrderId"`

	User     *User   `gorm:"ForeignKey:UserName"`
	UserName *string `gorm:"type:varchar(256);`

	EndAt *time.Time `gorm:"unique_index:idx_tag_endat"`
}

db struct

type Preload

type Preload struct {
	All        func(db *gorm.DB) *gorm.DB
	HasMany    func(db *gorm.DB) *gorm.DB
	HasOne     func(db *gorm.DB) *gorm.DB
	BelongsTo  func(db *gorm.DB) *gorm.DB
	ManyToMany func(db *gorm.DB) *gorm.DB
}

func CreatePreload

func CreatePreload(table interface{}) *Preload

type Shop

type Shop struct {
	gorm.Model

	Address    string `gorm:"type:varchar(1024);unique_index"`
	BeginPrice int
	BeginCost  int
	Discounts  []Discount `gorm:"ForeignKey:ShopId`
}

db struct

type User

type User struct {
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time `sql:"index"`
	Name      string     `gorm:"type:varchar(256);primary_key"`
	Pass      string
}

db struct

type UserItem

type UserItem struct {
	ID      uint           `gorm:"primary_key"`
	OrderId uint           `gorm:"unique_index:idx_order_user;index"`
	Cell    []UserItemCell `gorm:"ForeignKey:UserItemId"`

	User     User   `gorm:"ForeignKey:UserName"`
	UserName string `gorm:"type:varchar(256);unique_index:idx_order_user"`
}

db struct

type UserItemCell

type UserItemCell struct {
	ID         uint   `gorm:"primary_key"`
	UserItemId uint   `gorm:"unique_index:idx_item_name_price"`
	Name       string `gorm:"type:varchar(256);unique_index:idx_item_name_price"`
	Price      uint   `gorm:"unique_index:idx_item_name_price"`
	Num        uint
}

db struct

func (*UserItemCell) Incr

func (cell *UserItemCell) Incr(value int) func(*gorm.DB) *gorm.DB

Jump to

Keyboard shortcuts

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