- Sort Score
- Result 10 results
- Languages All
Results 1 - 6 of 6 for FirstOrCreate (0.12 sec)
-
chainable_api.go
// // user -> User{Name: "jinzhu", Age: 20} // // [FirstOrCreate]: https://gorm.io/docs/advanced_query.html#FirstOrCreate // [FirstOrInit]: https://gorm.io/docs/advanced_query.html#FirstOrInit func (db *DB) Attrs(attrs ...interface{}) (tx *DB) { tx = db.getInstance() tx.Statement.attrs = attrs return } // Assign provide attributes used in [FirstOrCreate] or [FirstOrInit] //
Registered: Sun Nov 03 09:35:10 UTC 2024 - Last Modified: Mon Jun 24 09:42:59 UTC 2024 - 14.8K bytes - Viewed (0) -
tests/upsert_test.go
if err := DB.Where(&User{Name: "find or create", Age: 33}).FirstOrCreate(&user1).Error; err != nil { t.Errorf("no error should happen when FirstOrInit, but got %v", err) } if user1.Name != "find or create" || user1.ID == 0 || user1.Age != 33 { t.Errorf("user should be created with search value") } DB.Where(&User{Name: "find or create", Age: 33}).FirstOrCreate(&user2)
Registered: Sun Nov 03 09:35:10 UTC 2024 - Last Modified: Mon Sep 05 07:39:19 UTC 2022 - 11.4K bytes - Viewed (0) -
finisher_api.go
if len(tx.Statement.assigns) > 0 { tx.assignInterfacesToValue(tx.Statement.assigns...) } return } // FirstOrCreate finds the first matching record, otherwise if not found creates a new instance with given conds. // Each conds must be a struct or map. // // Using FirstOrCreate in conjunction with Assign will result in an update to the database even if the record exists. //
Registered: Sun Nov 03 09:35:10 UTC 2024 - Last Modified: Sat Sep 14 12:58:29 UTC 2024 - 22.8K bytes - Viewed (0) -
tests/scanner_valuer_test.go
ExampleStruct: ExampleStruct{"name", "value1"}, ExampleStructPtr: &ExampleStruct{"name", "value2"}, } var result ScannerValuerStruct tx := DB.Where(data).FirstOrCreate(&result) if tx.RowsAffected != 1 { t.Errorf("RowsAffected should be 1 after create some record") } if tx.Error != nil { t.Errorf("Should not raise any error, but got %v", tx.Error) }
Registered: Sun Nov 03 09:35:10 UTC 2024 - Last Modified: Wed Jun 07 07:02:07 UTC 2023 - 10.6K bytes - Viewed (0) -
tests/create_test.go
company := Company{Name: "first_or_create_if_not_exists_table"} if err := DB.Table("not_exists").FirstOrCreate(&company).Error; err == nil { t.Errorf("not exists table, but err is nil") } } func TestFirstOrCreateWithPrimaryKey(t *testing.T) { company := Company{ID: 100, Name: "company100_with_primarykey"} DB.FirstOrCreate(&company) if company.ID != 100 {
Registered: Sun Nov 03 09:35:10 UTC 2024 - Last Modified: Tue Mar 19 03:50:28 UTC 2024 - 26.4K bytes - Viewed (0) -
tests/associations_many2many_test.go
language := Language{Code: fmt.Sprintf("consurrent %d", i)} db.Create(&language) languages = append(languages, language) } user := User{} db.Create(&user) db.Preload("Languages").FirstOrCreate(&user) var wg sync.WaitGroup for i := 0; i < count; i++ { wg.Add(1) go func(user User, language Language) { err := db.Model(&user).Association("Languages").Append(&language)
Registered: Sun Nov 03 09:35:10 UTC 2024 - Last Modified: Sat Jun 10 13:05:19 UTC 2023 - 13.2K bytes - Viewed (0)