Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 4 of 4 for MapColumns (0.16 sec)

  1. generics.go

    func (c chainG[T]) Omit(columns ...string) ChainInterface[T] {
    	return c.with(func(db *DB) *DB {
    		return db.Omit(columns...)
    	})
    }
    
    func (c chainG[T]) MapColumns(m map[string]string) ChainInterface[T] {
    	return c.with(func(db *DB) *DB {
    		return db.MapColumns(m)
    	})
    }
    
    func (c chainG[T]) Distinct(args ...interface{}) ChainInterface[T] {
    	return c.with(func(db *DB) *DB {
    		return db.Distinct(args...)
    	})
    }
    Registered: Sun Sep 07 09:35:13 UTC 2025
    - Last Modified: Thu Sep 04 13:13:16 UTC 2025
    - 15.5K bytes
    - Viewed (0)
  2. chainable_api.go

    		tx.Statement.Omits = strings.FieldsFunc(columns[0], utils.IsValidDBNameChar)
    	} else {
    		tx.Statement.Omits = columns
    	}
    	return
    }
    
    // MapColumns modify the column names in the query results to facilitate align to the corresponding structural fields
    func (db *DB) MapColumns(m map[string]string) (tx *DB) {
    	tx = db.getInstance()
    	tx.Statement.ColumnMapping = m
    	return
    }
    
    // Where add conditions
    //
    Registered: Sun Sep 07 09:35:13 UTC 2025
    - Last Modified: Sun May 25 07:40:40 UTC 2025
    - 14.8K bytes
    - Viewed (0)
  3. tests/generics_test.go

    		t.Errorf("found invalid user, got %v, expect %v", result, user)
    	}
    
    	mapResult, err := gorm.G[map[string]interface{}](DB).Table("users").Where("name = ?", user.Name).MapColumns(map[string]string{"name": "user_name"}).Take(ctx)
    	if v := mapResult["user_name"]; fmt.Sprint(v) != user.Name {
    		t.Errorf("failed to find map results, got %v, err %v", mapResult, err)
    	}
    }
    
    Registered: Sun Sep 07 09:35:13 UTC 2025
    - Last Modified: Thu Sep 04 13:13:16 UTC 2025
    - 28K bytes
    - Viewed (0)
  4. tests/query_test.go

    	DB.Save(&user)
    
    	type result struct {
    		Name     string
    		Nickname string
    		Age      uint
    	}
    	var res result
    	DB.Table("users").Where("name = ?", user.Name).MapColumns(map[string]string{"name": "nickname"}).Scan(&res)
    	if res.Nickname != user.Name {
    		t.Errorf("Expected res.Nickname to be %s, but got %s", user.Name, res.Nickname)
    	}
    	if res.Name != "" {
    Registered: Sun Sep 07 09:35:13 UTC 2025
    - Last Modified: Tue Jul 22 06:21:04 UTC 2025
    - 51K bytes
    - Viewed (0)
Back to top