testutil

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Skipped bool

Functions

func CreateTestDB

func CreateTestDB(ctx context.Context, statements ...string) (dsn string, cleanup func(), err error)

func InitIntegrationTests

func InitIntegrationTests() (cleanup func(), err error)

func RunsOnEmulator

func RunsOnEmulator() bool

Types

type Account

type Account struct {
	gorm.Model
	UserID sql.NullInt64
	Number string
}

type Child

type Child struct {
	gorm.Model
	Name     string
	ParentID *int64
	Parent   *Parent
}

type Company

type Company struct {
	ID   int
	Name string
}

type Config

type Config struct {
	Account   bool
	Pets      int
	Toys      int
	Company   bool
	Manager   bool
	Team      int
	Languages int
	Friends   int
	NamedPet  bool
}

type Coupon

type Coupon struct {
	ID               int              `gorm:"primarykey"`
	AppliesToProduct []*CouponProduct `gorm:"foreignKey:CouponId;constraint:OnDelete:CASCADE"`
	AmountOff        int64            `gorm:"column:amount_off"`
	PercentOff       float64          `gorm:"column:percent_off"`
}

type CouponProduct

type CouponProduct struct {
	CouponId  int    `gorm:"primarykey"`
	ProductId string `gorm:"primarykey;size:255"`
	Desc      string
}

type Language

type Language struct {
	Code string `gorm:"primarykey"`
	Name string
}

type Order

type Order struct {
	gorm.Model
	Num      string
	Coupon   *Coupon
	CouponID string
}

type Parent

type Parent struct {
	gorm.Model
	FavChildID int64
	FavChild   *Child
	Children   []*Child
}

type Pet

type Pet struct {
	gorm.Model
	UserID sql.NullInt64
	Name   string
	Toy    Toy `gorm:"polymorphic:Owner;"`
}

type Toy

type Toy struct {
	gorm.Model
	Name      string
	OwnerID   string
	OwnerType string
}

type User

type User struct {
	gorm.Model
	Name      string
	Age       int64
	Birthday  *time.Time
	Account   Account
	Pets      []*Pet
	NamedPet  *Pet
	Toys      []Toy `gorm:"polymorphic:Owner"`
	CompanyID sql.NullInt64
	Company   Company
	ManagerID sql.NullInt64
	Manager   *User
	Team      []User     `gorm:"foreignkey:ManagerID"`
	Languages []Language `gorm:"many2many:UserSpeak;"`
	Friends   []*User    `gorm:"many2many:user_friends;"`
	Active    bool
}

User has one `Account` (has one), many `Pets` (has many) and `Toys` (has many - polymorphic) He works in a Company (belongs to), he has a Manager (belongs to - single-table), and also managed a Team (has many - single-table) He speaks many languages (many to many) and has many friends (many to many - single-table) His pet also has one Toy (has one - polymorphic) NamedPet is a reference to a named `Pet` (has one)

func GetUser

func GetUser(name string, config Config) *User

Jump to

Keyboard shortcuts

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