Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 8 of 8 for insert (0.21 sec)

  1. tests/create_test.go

    		},
    		{
    			"name":    "dog",
    			"user_id": gorm.Expr("@uid"),
    		},
    	})
    
    	if !regexp.MustCompile(`INSERT INTO .pets. \(.name.,.user_id.\) .*VALUES \(.+,\(SELECT @uid:=id FROM \(SELECT id FROM .users. WHERE name=.+\) as tmp\)\),\(.+,@uid\)`).MatchString(result.Statement.SQL.String()) {
    		t.Errorf("invalid insert SQL, got %v", result.Statement.SQL.String())
    	}
    }
    
    func TestCreateNilPointer(t *testing.T) {
    	var user *User
    
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Tue Mar 19 03:50:28 GMT 2024
    - 26.4K bytes
    - Viewed (0)
  2. tests/table_test.go

    	}
    
    	r = dryDB.Create(&UserWithTable{}).Statement
    	if DB.Dialector.Name() != "sqlite" {
    		if !regexp.MustCompile(`INSERT INTO .gorm.\..user. (.*name.*) VALUES (.*)`).MatchString(r.Statement.SQL.String()) {
    			t.Errorf("Table with escape character, got %v", r.Statement.SQL.String())
    		}
    	} else {
    		if !regexp.MustCompile(`INSERT INTO .user. (.*name.*) VALUES (.*)`).MatchString(r.Statement.SQL.String()) {
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Sat Mar 09 09:31:28 GMT 2024
    - 10.6K bytes
    - Viewed (0)
  3. tests/scanner_valuer_test.go

    	if stmt.SQL.String() == "" || len(stmt.Vars) != 2 {
    		t.Errorf("Failed to generate sql, got %v", stmt.SQL.String())
    	}
    
    	if !regexp.MustCompile(`INSERT INTO .user_with_points. \(.name.,.point.\) VALUES \(.+,ST_PointFromText\(.+\)\)`).MatchString(stmt.SQL.String()) {
    		t.Errorf("insert with sql.Expr, but got %v", stmt.SQL.String())
    	}
    
    	if !reflect.DeepEqual([]interface{}{"jinzhu", "POINT(100 100)"}, stmt.Vars) {
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Wed Jun 07 07:02:07 GMT 2023
    - 10.6K bytes
    - Viewed (0)
  4. callbacks/create.go

    		if db.RowsAffected == 0 {
    			return
    		}
    
    		var (
    			pkField     *schema.Field
    			pkFieldName = "@id"
    		)
    
    		insertID, err := result.LastInsertId()
    		insertOk := err == nil && insertID > 0
    
    		if !insertOk {
    			if !supportReturning {
    				db.AddError(err)
    			}
    			return
    		}
    
    		if db.Statement.Schema != nil {
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Mon Apr 08 03:29:55 GMT 2024
    - 12.5K bytes
    - Viewed (0)
  5. tests/upsert_test.go

    	}
    }
    
    func TestUpsertSlice(t *testing.T) {
    	langs := []Language{
    		{Code: "upsert-slice1", Name: "Upsert-slice1"},
    		{Code: "upsert-slice2", Name: "Upsert-slice2"},
    		{Code: "upsert-slice3", Name: "Upsert-slice3"},
    	}
    	DB.Clauses(clause.OnConflict{DoNothing: true}).Create(&langs)
    
    	var langs2 []Language
    	if err := DB.Find(&langs2, "code LIKE ?", "upsert-slice%").Error; err != nil {
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Mon Sep 05 07:39:19 GMT 2022
    - 11.4K bytes
    - Viewed (0)
  6. finisher_api.go

    	"gorm.io/gorm/utils"
    )
    
    // Create inserts value, returning the inserted data's primary key in value's id
    func (db *DB) Create(value interface{}) (tx *DB) {
    	if db.CreateBatchSize > 0 {
    		return db.CreateInBatches(value, db.CreateBatchSize)
    	}
    
    	tx = db.getInstance()
    	tx.Statement.Dest = value
    	return tx.callbacks.Create().Execute(tx)
    }
    
    // CreateInBatches inserts value in batches of batchSize
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Fri Jan 12 08:42:21 GMT 2024
    - 22.7K bytes
    - Viewed (0)
  7. tests/sql_builder_test.go

    	// create
    	user := &User{Name: "foo", Age: 20}
    	user.CreatedAt = date
    	user.UpdatedAt = date
    	sql = DB.ToSQL(func(tx *gorm.DB) *gorm.DB {
    		return tx.Model(&User{}).Create(user)
    	})
    	assertEqualSQL(t, `INSERT INTO "users" ("created_at","updated_at","deleted_at","name","age","birthday","company_id","manager_id","active") VALUES ('2021-10-18 00:00:00','2021-10-18 00:00:00',NULL,'foo',20,NULL,NULL,NULL,false) RETURNING "id"`, sql)
    
    	// save
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Fri Jan 12 08:42:21 GMT 2024
    - 16.7K bytes
    - Viewed (0)
  8. tests/associations_many2many_test.go

    	}
    
    	newLang := Language{Code: "omitmany2many", Name: "omitmany2many"}
    	if err := DB.Model(&user).Omit("Languages.*").Association("Languages").Replace(&newLang); err == nil {
    		t.Errorf("should failed to insert languages due to constraint failed, error: %v", err)
    	}
    }
    
    func TestMany2ManyAssociationForSlice(t *testing.T) {
    	users := []User{
    		*GetUser("slice-many2many-1", Config{Languages: 2}),
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Sat Jun 10 13:05:19 GMT 2023
    - 13.2K bytes
    - Viewed (0)
Back to top