package v2 import ( "fmt" "testing" "gorm.io/driver/postgres" "gorm.io/gorm" "gorm.io/gorm/clause" ) func TestModel(t *testing.T) { dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=disable TimeZone=Asia/Shanghai", "192.168.31.55", "timerzz", "zhhg1997", "kedaya_dev", "5432") db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{}) if err != nil { t.Fatal(err) } err = db.AutoMigrate(&Article{}, &ProviderArticle{}, &ProviderPrice{}, &SellerArticle{}, &SellerPrice{}) if err != nil { t.Fatal(err) } var article = Article{ Name: "test", EnglishName: "test", Pid: "1299999922", Brand: "col", Desc: "desc", Image: "http://123", Available: false, CostPrice: 123, Providers: []ProviderArticle{ { Pid: "999", Brand: "col", Link: "http://123", ProviderId: "coach", SkuID: "sku999999", Cost: ProviderPrice{ OriginalPrice: 000, FinalPrice: 0000, CalMark: "uuuuu", }, HistoryPrice: []ProviderPrice{ { OriginalPrice: 0000, FinalPrice: 000, CalMark: "uuuuu", }, }, }, }, SellPrice: 321, Sellers: []SellerArticle{}, Rate: 123, Remark: "jjjjj", } db.Clauses(clause.OnConflict{ Columns: []clause.Column{{Name: "pid"}, {Name: "brand"}}, DoUpdates: clause.AssignmentColumns([]string{"name", "english_name", "available", "updated_at"}), }).Create(&article) }