tests

package
v0.0.0-...-343d07f Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2018 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TestDB    *DBCon
	TestDBErr error
)

Functions

func NameIn

func NameIn(names []string) func(d *DBCon) *DBCon

func NameIn1And2

func NameIn1And2(d *DBCon) *DBCon

func NameIn2And3

func NameIn2And3(d *DBCon) *DBCon

Types

type Address

type Address struct {
	ID        int
	Address1  string
	Address2  string
	Post      string
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time
}

type Animal

type Animal struct {
	Counter uint64    `gorm:"primary_key:yes"`
	Name    string    `sql:"DEFAULT:'galeone'"`
	From    string    //test reserved sql keyword as field name
	Age     time.Time `sql:"DEFAULT:current_timestamp"`

	CreatedAt time.Time
	UpdatedAt time.Time
	// contains filtered or unexported fields
}

type Author

type Author struct {
	Name  string
	Email string
}

type BasePost

type BasePost struct {
	Id    int64
	Title string
	URL   string
}

type BigEmail

type BigEmail struct {
	Id           int64
	UserId       int64
	Email        string     `sql:"index:idx_email_agent"`
	UserAgent    string     `sql:"index:idx_email_agent"`
	RegisteredAt *time.Time `sql:"unique_index"`
	CreatedAt    time.Time
	UpdatedAt    time.Time
}

func (BigEmail) TableName

func (b BigEmail) TableName() string

type Blog

type Blog struct {
	ID         uint   `gorm:"primary_key"`
	Locale     string `gorm:"primary_key"`
	Subject    string
	Body       string
	Tags       []Tag `gorm:"many2many:blog_tags;"`
	SharedTags []Tag `gorm:"many2many:shared_blog_tags;ForeignKey:id;AssociationForeignKey:id"`
	LocaleTags []Tag `gorm:"many2many:locale_blog_tags;ForeignKey:id,locale;AssociationForeignKey:id"`
}

type CalculateField

type CalculateField struct {
	Model
	Name     string
	Children []CalculateFieldChild
	Category CalculateFieldCategory
	EmbeddedField
}

type CalculateFieldCategory

type CalculateFieldCategory struct {
	Model
	CalculateFieldID uint
	Name             string
}

type CalculateFieldChild

type CalculateFieldChild struct {
	Model
	CalculateFieldID uint
	Name             string
}

type Cart

type Cart struct {
}

func (Cart) TableName

func (c Cart) TableName() string

type Cat

type Cat struct {
	Id   int
	Name string
	Toy  Toy `gorm:"polymorphic:Owner;"`
}

type Category

type Category struct {
	Model
	Name string

	Categories []Category
	CategoryID *uint
}

type Comment

type Comment struct {
	Model
	PostId  int64
	Content string
	Post    Post
}

type Company

type Company struct {
	Id    int64
	Name  string
	Owner *User `sql:"-"`
}

type CreditCard

type CreditCard struct {
	ID        int8
	Number    string
	UserId    sql.NullInt64
	CreatedAt time.Time `sql:"not null"`
	UpdatedAt time.Time
	DeletedAt *time.Time
}

type CustomColumnAndIgnoredFieldClash

type CustomColumnAndIgnoredFieldClash struct {
	Body    string `sql:"-"`
	RawBody string `gorm:"column:body"`
}

Make sure an ignored field does not interfere with another field's custom column name that matches the ignored field.

type CustomizeAccount

type CustomizeAccount struct {
	IdAccount string `gorm:"column:idAccount;primary_key:true"`
	Name      string
}

type CustomizeColumn

type CustomizeColumn struct {
	ID   int64      `gorm:"column:mapped_id; primary_key:yes"`
	Name string     `gorm:"column:mapped_name"`
	Date *time.Time `gorm:"column:mapped_time"`
}

type CustomizeInvitation

type CustomizeInvitation struct {
	Model
	Address string         `sql:"column:invitation"`
	Person  *CustomizeUser `gorm:"foreignkey:Email;associationforeignkey:invitation"`
}

type CustomizePerson

type CustomizePerson struct {
	IdPerson string             `gorm:"column:idPerson;primary_key:true"`
	Accounts []CustomizeAccount `gorm:"many2many:PersonAccount;associationforeignkey:idAccount;foreignkey:idPerson"`
}

type CustomizeUser

type CustomizeUser struct {
	Model
	Email string `sql:"column:email_address"`
}

type Dog

type Dog struct {
	Id   int
	Name string
	Toys []Toy `gorm:"polymorphic:Owner;"`
}

type ElementWithIgnoredField

type ElementWithIgnoredField struct {
	Id           int64
	Value        string
	IgnoredField int64 `sql:"-"`
}

func (ElementWithIgnoredField) TableName

func (e ElementWithIgnoredField) TableName() string

type Email

type Email struct {
	Id        int16
	UserId    int
	Email     string `sql:"type:varchar(100);"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

type EmbeddedField

type EmbeddedField struct {
	EmbeddedName string `sql:"NOT NULL;DEFAULT:'hello'"`
}

type EngadgetPost

type EngadgetPost struct {
	BasePost BasePost `gorm:"embedded"`
	Author   Author   `gorm:"embedded;embedded_prefix:author_"` // Embedded struct
	ImageUrl string
}

type ExampleStringSlice

type ExampleStringSlice []string

func (*ExampleStringSlice) Scan

func (l *ExampleStringSlice) Scan(input interface{}) error

func (ExampleStringSlice) Value

func (l ExampleStringSlice) Value() (driver.Value, error)

type ExampleStruct

type ExampleStruct struct {
	Name  string
	Value string
}

type ExampleStructSlice

type ExampleStructSlice []ExampleStruct

func (*ExampleStructSlice) Scan

func (l *ExampleStructSlice) Scan(input interface{}) error

func (ExampleStructSlice) Value

func (l ExampleStructSlice) Value() (driver.Value, error)

type HNPost

type HNPost struct {
	BasePost
	Author  `gorm:"embedded_prefix:user_"` // Embedded struct
	Upvotes int32
}

type Hamster

type Hamster struct {
	Id           int
	Name         string
	PreferredToy Toy `gorm:"polymorphic:Owner;polymorphic_value:hamster_preferred"`
	OtherToy     Toy `gorm:"polymorphic:Owner;polymorphic_value:hamster_other"`
}

type JoinTable

type JoinTable struct {
	From uint64
	To   uint64
	Time time.Time `sql:"default: null"`
}

type Language

type Language struct {
	Model
	Name  string
	Users []User `gorm:"many2many:user_languages;"`
}

type LevelA1

type LevelA1 struct {
	ID    uint
	Value string
}

type LevelA2

type LevelA2 struct {
	ID       uint
	Value    string
	LevelA3s []*LevelA3
}

type LevelA3

type LevelA3 struct {
	ID        uint
	Value     string
	LevelA1ID sql.NullInt64
	LevelA1   *LevelA1
	LevelA2ID sql.NullInt64
	LevelA2   *LevelA2
}

type LevelB1

type LevelB1 struct {
	ID       uint
	Value    string
	LevelB3s []*LevelB3
}

type LevelB2

type LevelB2 struct {
	ID    uint
	Value string
}

type LevelB3

type LevelB3 struct {
	ID        uint
	Value     string
	LevelB1ID sql.NullInt64
	LevelB1   *LevelB1
	LevelB2s  []*LevelB2 `gorm:"many2many:levelb1_levelb3_levelb2s"`
}

type LevelC1

type LevelC1 struct {
	ID        uint
	Value     string
	LevelC2ID uint
}

type LevelC2

type LevelC2 struct {
	ID      uint
	Value   string
	LevelC1 LevelC1
}

type LevelC3

type LevelC3 struct {
	ID        uint
	Value     string
	LevelC2ID uint
	LevelC2   LevelC2
}

type MultipleIndexes

type MultipleIndexes struct {
	ID     int64
	UserID int64  `sql:"unique_index:uix_multipleindexes_user_name,uix_multipleindexes_user_email;index:idx_multipleindexes_user_other"`
	Name   string `sql:"unique_index:uix_multipleindexes_user_name"`
	Email  string `sql:"unique_index:,uix_multipleindexes_user_email"`
	Other  string `sql:"index:,idx_multipleindexes_user_other"`
}

type NormalStruct

type NormalStruct struct {
	ID   int64
	Name string
	Num  int
}

type NotSoLongTableName

type NotSoLongTableName struct {
	Id                int64
	ReallyLongThingID int64
	ReallyLongThing   ReallyLongTableNameToTestMySQLNameLengthLimit
}

type NullTime

type NullTime struct {
	Time  time.Time
	Valid bool
}

func (*NullTime) Scan

func (nt *NullTime) Scan(value interface{}) error

func (NullTime) Value

func (nt NullTime) Value() (driver.Value, error)

type NullValue

type NullValue struct {
	Id      int64
	Name    sql.NullString  `sql:"not null"`
	Gender  *sql.NullString `sql:"not null"`
	Age     sql.NullInt64
	Male    sql.NullBool
	Height  sql.NullFloat64
	AddedAt NullTime
}

Scanner

type Num

type Num int64

func (*Num) Scan

func (i *Num) Scan(src interface{}) error

type Order

type Order struct {
}

type Person

type Person struct {
	Id        int
	Name      string
	Addresses []*Address `gorm:"many2many:person_addresses;"`
}

func (Person) String

func (p Person) String() string

type PersonAddress

type PersonAddress struct {
	JoinTableHandler
	PersonID  int
	AddressID int
	DeletedAt *time.Time
	CreatedAt time.Time
}

func (*PersonAddress) Add

func (*PersonAddress) Add(handler JoinTableHandlerInterface, db *DBCon, foreignValue interface{}, associationValue interface{}) error

func (*PersonAddress) Delete

func (*PersonAddress) Delete(handler JoinTableHandlerInterface, db *DBCon) error

func (*PersonAddress) JoinWith

func (pa *PersonAddress) JoinWith(handler JoinTableHandlerInterface, db *DBCon, source interface{}) *DBCon

type PointerStruct

type PointerStruct struct {
	ID   int64
	Name *string
	Num  *int
}

type Post

type Post struct {
	Id             int64
	CategoryId     sql.NullInt64
	MainCategoryId int64
	Title          string
	Body           string
	Comments       []*Comment
	Category       Category
	MainCategory   Category
}

type Product

type Product struct {
	Id                    int64
	Code                  string
	Price                 int64
	CreatedAt             time.Time
	UpdatedAt             time.Time
	AfterFindCallTimes    int64
	BeforeCreateCallTimes int64
	AfterCreateCallTimes  int64
	BeforeUpdateCallTimes int64
	AfterUpdateCallTimes  int64
	BeforeSaveCallTimes   int64
	AfterSaveCallTimes    int64
	BeforeDeleteCallTimes int64
	AfterDeleteCallTimes  int64
}

func (*Product) AfterCreate

func (s *Product) AfterCreate(tx *DBCon)

func (*Product) AfterDelete

func (s *Product) AfterDelete() (err error)

func (*Product) AfterFind

func (s *Product) AfterFind()

func (*Product) AfterSave

func (s *Product) AfterSave() (err error)

func (*Product) AfterUpdate

func (s *Product) AfterUpdate()

func (*Product) BeforeCreate

func (s *Product) BeforeCreate() (err error)

func (*Product) BeforeDelete

func (s *Product) BeforeDelete() (err error)

func (*Product) BeforeSave

func (s *Product) BeforeSave() (err error)

func (*Product) BeforeUpdate

func (s *Product) BeforeUpdate() (err error)

func (*Product) GetCallTimes

func (s *Product) GetCallTimes() []int64

type PromotionBenefit

type PromotionBenefit struct {
	Model
	Name        string
	PromotionID uint
	Discount    PromotionDiscount `gorm:"ForeignKey:promotion_id"`
}

type PromotionCoupon

type PromotionCoupon struct {
	Model
	Code       string
	DiscountID uint
	Discount   PromotionDiscount
}

type PromotionDiscount

type PromotionDiscount struct {
	Model
	Name     string
	Coupons  []*PromotionCoupon `gorm:"ForeignKey:discount_id"`
	Rule     *PromotionRule     `gorm:"ForeignKey:discount_id"`
	Benefits []PromotionBenefit `gorm:"ForeignKey:promotion_id"`
}

type PromotionRule

type PromotionRule struct {
	Model
	Name       string
	Begin      *time.Time
	End        *time.Time
	DiscountID uint
	Discount   *PromotionDiscount
}

type ReallyLongTableNameToTestMySQLNameLengthLimit

type ReallyLongTableNameToTestMySQLNameLengthLimit struct {
	Id int64
}

type ReallyLongThingThatReferencesShort

type ReallyLongThingThatReferencesShort struct {
	Id      int64
	ShortID int64
	Short   Short
}

type RecordWithSlice

type RecordWithSlice struct {
	ID      uint64
	Strings ExampleStringSlice `sql:"type:text"`
	Structs ExampleStructSlice `sql:"type:text"`
}

type Role

type Role struct {
	Name string `gorm:"size:256"`
}

func (Role) IsAdmin

func (role Role) IsAdmin() bool

func (*Role) Scan

func (role *Role) Scan(value interface{}) error

func (Role) Value

func (role Role) Value() (driver.Value, error)

type Short

type Short struct {
	Id int64
}

type Tag

type Tag struct {
	ID     uint   `gorm:"primary_key"`
	Locale string `gorm:"primary_key"`
	Value  string
	Blogs  []*Blog `gorm:"many2many:blogs_tags"`
}

type Toy

type Toy struct {
	Id        int
	Name      string
	OwnerId   int
	OwnerType string
}

type User

type User struct {
	Id                int64
	Age               int64
	UserNum           Num
	Name              string `sql:"size:255"`
	Email             string
	Birthday          *time.Time    // Time
	CreatedAt         time.Time     // CreatedAt: Time of record is created, will be insert automatically
	UpdatedAt         time.Time     // UpdatedAt: Time of record is updated, will be updated automatically
	Emails            []Email       // Embedded structs
	BillingAddress    Address       // Embedded struct
	BillingAddressID  sql.NullInt64 // Embedded struct's foreign key
	ShippingAddress   Address       // Embedded struct
	ShippingAddressId int64         // Embedded struct's foreign key
	CreditCard        CreditCard
	Latitude          float64
	Languages         []Language `gorm:"many2many:user_languages;"`
	CompanyID         *int
	Company           Company
	Role
	PasswordHash      []byte
	Sequence          uint                  `gorm:"AUTO_INCREMENT"`
	IgnoreMe          int64                 `sql:"-"`
	IgnoreStringSlice []string              `sql:"-"`
	Ignored           struct{ Name string } `sql:"-"`
	IgnoredPointer    *User                 `sql:"-"`
}

Jump to

Keyboard shortcuts

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