// ColMap returns the ColumnMap pointer matching the given struct field
// name.  It panics if the struct does not contain a field matching this
// name.
352187
func (t *TableMap) ColMap(field string) *ColumnMap {
	col := colMapOrNil(t, field)
	if col == nil {
		e := fmt.Sprintf("No ColumnMap in table %s type %s with field %s",
			t.TableName, t.gotype.Name(), field)

		panic(e)
	}
	return col
}
1073906
func valuesMap(stmt InsertStmt, values Values) (fields, error) {
	fields := make(fields, len(values))
	var i int
	for column, _ := range values {
		if !stmt.HasColumn(column) {
			return nil, fmt.Errorf(
				"aspect: cannot INSERT a value with column '%s' as it has no corresponding column in the INSERT statement",
				column,
			)
		}
		fields[i] = field{column: column} // TODO set index?
	}
	return fields, nil
}
1018645
func (i *Index) AddColumn(field string, col, row uint64OrString) {
	i.addColumn(field, col, row, 0)
}
618025
func NamedStructMap(e *Echo, m interface{}, data map[string][]string, topName string, filters ...FormDataFilter) error {
	vc := reflect.ValueOf(m)
	tc := reflect.TypeOf(m)

	switch tc.Kind() {
	case reflect.Struct:
	case reflect.Ptr:
		vc = vc.Elem()
		tc = tc.Elem()
	default:
		return errors.New(`binder: unsupported type ` + tc.Kind().String())
	}
	var (
		validator *validation.Validation
		filter    FormDataFilter
	)
	if len(filters) > 0 {
		filter = filters[0]
	}
	if filter == nil {
		filter = DefaultNopFilter
	}
	for k, t := range data {
		k, t = filter(k, t)
		if len(k) == 0 || k[0] == '_' {
			continue
		}

		if len(topName) > 0 {
			if !strings.HasPrefix(k, topName) {
				continue
			}
			k = k[len(topName)+1:]
		}

		v := t[0]
		names := strings.Split(k, `.`)
		var (
			err      error
			propPath string
		)
		length := len(names)
		if length == 1 && strings.HasSuffix(k, `]`) {
			k = strings.TrimRight(k, `[]`)
			names = FormNames(k)
			length = len(names)
		}
		value := vc
		typev := tc
		for i, name := range names {
			name = strings.Title(name)
			if i > 0 {
				propPath += `.`
			}
			propPath += name

			//不是最后一个元素
			if i != length-1 {
				if value.Kind() != reflect.Struct {
					e.Logger().Warnf(`binder: arg error, value kind is %v`, value.Kind())
					break
				}
				f, _ := typev.FieldByName(name)
				if tagfast.Value(tc, f, `form_options`) == `-` {
					break
				}
				value = value.FieldByName(name)
				if !value.IsValid() {
					e.Logger().Debugf(`binder: %T#%v value is not valid %v`, m, propPath, value)
					break
				}
				if !value.CanSet() {
					e.Logger().Warnf(`binder: can not set %T#%v -> %v`, m, propPath, value.Interface())
					break
				}
				if value.Kind() == reflect.Ptr {
					if value.IsNil() {
						value.Set(reflect.New(value.Type().Elem()))
					}
					value = value.Elem()
				}
				if value.Kind() != reflect.Struct {
					e.Logger().Warnf(`binder: arg error, value %T#%v kind is %v`, m, propPath, value.Kind())
					break
				}
				typev = value.Type()
				f, _ = typev.FieldByName(name)
				if tagfast.Value(tc, f, `form_options`) == `-` {
					break
				}
				continue
			}

			//最后一个元素
			tv := value.FieldByName(name)
			if !tv.IsValid() {
				break
			}
			if !tv.CanSet() {
				e.Logger().Warnf(`binder: can not set %v to %v`, k, tv)
				break
			}
			f, _ := typev.FieldByName(name)
			if tagfast.Value(tc, f, `form_options`) == `-` {
				break
			}
			if tv.Kind() == reflect.Ptr {
				tv.Set(reflect.New(tv.Type().Elem()))
				tv = tv.Elem()
			}

			var l interface{}
			switch k := tv.Kind(); k {
			case reflect.String:
				switch tagfast.Value(tc, f, `form_filter`) {
				case `html`:
					v = DefaultHTMLFilter(v)
				default:
					delimter := tagfast.Value(tc, f, `form_delimiter`)
					if len(delimter) > 0 {
						v = strings.Join(t, delimter)
					}
				}
				l = v
				tv.Set(reflect.ValueOf(l))
			case reflect.Bool:
				l = (v != `false` && v != `0` && v != ``)
				tv.Set(reflect.ValueOf(l))
			case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32:
				dateformat := tagfast.Value(tc, f, `form_format`)
				if len(dateformat) > 0 {
					t, err := time.Parse(dateformat, v)
					if err != nil {
						e.Logger().Warnf(`binder: arg %v as int: %v`, v, err)
						l = int(0)
					} else {
						l = int(t.Unix())
					}
				} else {
					x, err := strconv.Atoi(v)
					if err != nil {
						e.Logger().Warnf(`binder: arg %v as int: %v`, v, err)
					}
					l = x
				}
				tv.Set(reflect.ValueOf(l))
			case reflect.Int64:
				dateformat := tagfast.Value(tc, f, `form_format`)
				if len(dateformat) > 0 {
					t, err := time.Parse(dateformat, v)
					if err != nil {
						e.Logger().Warnf(`binder: arg %v as int64: %v`, v, err)
						l = int64(0)
					} else {
						l = t.Unix()
					}
				} else {
					x, err := strconv.ParseInt(v, 10, 64)
					if err != nil {
						e.Logger().Warnf(`binder: arg %v as int64: %v`, v, err)
					}
					l = x
				}
				tv.Set(reflect.ValueOf(l))
			case reflect.Float32, reflect.Float64:
				x, err := strconv.ParseFloat(v, 64)
				if err != nil {
					e.Logger().Warnf(`binder: arg %v as float64: %v`, v, err)
				}
				l = x
				tv.Set(reflect.ValueOf(l))
			case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
				dateformat := tagfast.Value(tc, f, `form_format`)
				var x uint64
				var bitSize int
				switch k {
				case reflect.Uint8:
					bitSize = 8
				case reflect.Uint16:
					bitSize = 16
				case reflect.Uint32:
					bitSize = 32
				default:
					bitSize = 64
				}
				if len(dateformat) > 0 {
					t, err := time.Parse(dateformat, v)
					if err != nil {
						e.Logger().Warnf(`binder: arg %v as uint: %v`, v, err)
						x = uint64(0)
					} else {
						x = uint64(t.Unix())
					}
				} else {
					x, err = strconv.ParseUint(v, 10, bitSize)
					if err != nil {
						e.Logger().Warnf(`binder: arg %v as uint: %v`, v, err)
					}
				}
				switch k {
				case reflect.Uint:
					l = uint(x)
				case reflect.Uint8:
					l = uint8(x)
				case reflect.Uint16:
					l = uint16(x)
				case reflect.Uint32:
					l = uint32(x)
				default:
					l = x
				}
				tv.Set(reflect.ValueOf(l))
			case reflect.Struct:
				if tvf, ok := tv.Interface().(FromConversion); ok {
					err := tvf.FromString(v)
					if err != nil {
						e.Logger().Warnf(`binder: struct %v invoke FromString faild`, tvf)
					}
				} else if tv.Type().String() == `time.Time` {
					x, err := time.Parse(`2006-01-02 15:04:05.000 -0700`, v)
					if err != nil {
						x, err = time.Parse(`2006-01-02 15:04:05`, v)
						if err != nil {
							x, err = time.Parse(`2006-01-02`, v)
							if err != nil {
								e.Logger().Warnf(`binder: unsupported time format %v, %v`, v, err)
							}
						}
					}
					l = x
					tv.Set(reflect.ValueOf(l))
				} else {
					e.Logger().Warn(`binder: can not set an struct which is not implement Fromconversion interface`)
				}
			case reflect.Ptr:
				e.Logger().Warn(`binder: can not set an ptr of ptr`)
			case reflect.Slice, reflect.Array:
				setSlice(e, name, tv, t)
			default:
				break
			}

			//validation
			valid := tagfast.Value(tc, f, `valid`)
			if len(valid) == 0 {
				continue
			}
			if validator == nil {
				validator = validation.New()
			}
			ok, err := validator.ValidSimple(name, fmt.Sprintf(`%v`, l), valid)
			if !ok {
				return validator.Errors[0].WithField()
			}
			if err != nil {
				e.Logger().Warn(err)
			}
		}
	}
	return nil
}
1131963
func fieldNameMapping(obj interface{}) map[string]string {
	st := reflect.TypeOf(obj)
	fl := st.NumField()

	jsonToForce := make(map[string]string, fl)

	for i := 0; i < fl; i++ {
		sf := st.Field(i)
		jName := strings.SplitN(sf.Tag.Get("json"), ",", 2)[0]
		fName := strings.SplitN(sf.Tag.Get("force"), ",", 2)[0]

		if jName == "-" {
			continue
		}

		if fName == "-" {
			continue
		}

		if jName == "" {
			jName = sf.Name
		}

		if fName == "" {
			fName = sf.Name
		}

		jsonToForce[jName] = fName
	}

	for k, v := range baseFieldNameMap {
		jsonToForce[k] = v
	}

	return jsonToForce
}
498485
func TranslatedMap(ctx context.Context, sourceInterface interface{}) map[string]interface{} {
	iType := reflect.TypeOf(sourceInterface).Elem()
	result := make(map[string]interface{})

	for i := 0; i < iType.NumField(); i++ {
		fieldName := reflect.TypeOf(sourceInterface).Elem().Field(i).Name
		fieldValue := reflect.ValueOf(sourceInterface).Elem().Field(i).String()

		result[fieldName] = Translate(ctx, fieldValue)
	}

	return result
}
1152499
func (s *Struct) FillMap(out map[string]interface{}) {
	if out == nil {
		return
	}

	fields := s.structFields()

	for _, field := range fields {
		name := field.Name
		val := s.value.FieldByName(name)
		isSubStruct := false
		var finalVal interface{}

		tagName, tagOpts := parseTag(field.Tag.Get(s.TagName))
		if tagName != "" {
			name = tagName
		}

		// if the value is a zero value and the field is marked as omitempty do
		// not include
		if tagOpts.Has("omitempty") {
			zero := reflect.Zero(val.Type()).Interface()
			current := val.Interface()

			if reflect.DeepEqual(current, zero) {
				continue
			}
		}

		if !tagOpts.Has("omitnested") {
			finalVal = s.nested(val)

			v := reflect.ValueOf(val.Interface())
			if v.Kind() == reflect.Ptr {
				v = v.Elem()
			}

			switch v.Kind() {
			case reflect.Map, reflect.Struct:
				isSubStruct = true
			}
		} else {
			finalVal = val.Interface()
		}

		if tagOpts.Has("string") {
			s, ok := val.Interface().(fmt.Stringer)
			if ok {
				out[name] = s.String()
			}
			continue
		}

		if isSubStruct && (tagOpts.Has("flatten")) {
			for k := range finalVal.(map[string]interface{}) {
				out[k] = finalVal.(map[string]interface{})[k]
			}
		} else {
			out[name] = finalVal
		}
	}
}
1183523
func indexCol2Col(cols []*Column, col *model.IndexColumn) *Column {
	for _, c := range cols {
		if c.ColName.L == col.Name.L {
			return c
		}
	}
	return nil
}
232609
func (session *Session) Cols(columns ...string) *Session {
	session.Statement.Cols(columns...)
	return session
}
1311329
func structToMap(v reflect.Value) map[string]interface{} {
	out := make(map[string]interface{})
	t := v.Type()
	for i := 0; i < t.NumField(); i++ {
		field := t.Field(i)
		if field.PkgPath != "" {
			// unexported field. skip.
			continue
		}
		out[field.Name] = v.FieldByName(field.Name).Interface()
	}
	return out
}
82070
func (m *Table) Column(col string) (value.ValueType, bool) {
	f, ok := m.FieldMap[col]
	if ok {
		return f.ValueType(), true
	}
	f, ok = m.FieldMap[strings.ToLower(col)]
	if ok {
		return f.ValueType(), true
	}
	return value.UnknownType, false
}
917914
func (e *EntityDefinition) ColumnTypes() map[string]Type {
	m := make(map[string]Type)
	for _, c := range e.Columns {
		m[c.Name] = c.Type
	}
	return m
}
477959
func colMatch(a *ast.ColumnName, b *ast.ColumnName) bool {
	if a.Schema.L == "" || a.Schema.L == b.Schema.L {
		if a.Table.L == "" || a.Table.L == b.Table.L {
			return a.Name.L == b.Name.L
		}
	}
	return false
}
337670
func (m Mat3x2) Col(col int) Vec3 {
	return Vec3{m[col*3+0], m[col*3+1], m[col*3+2]}
}
347401
func (rs *Rows) ScanMap(dest interface{}) error {
	vv := reflect.ValueOf(dest)
	if vv.Kind() != reflect.Ptr || vv.Elem().Kind() != reflect.Map {
		return errors.New("dest should be a map's pointer")
	}

	cols, err := rs.Columns()
	if err != nil {
		return err
	}

	newDest := make([]interface{}, len(cols))
	vvv := vv.Elem()

	for i, _ := range cols {
		newDest[i] = ReflectNew(vvv.Type().Elem()).Interface()
		//v := reflect.New(vvv.Type().Elem())
		//newDest[i] = v.Interface()
	}

	err = rs.Rows.Scan(newDest...)
	if err != nil {
		return err
	}

	for i, name := range cols {
		vname := reflect.ValueOf(name)
		vvv.SetMapIndex(vname, reflect.ValueOf(newDest[i]).Elem())
	}

	return nil
}
1090841
func (session *Session) Cols(columns ...string) *Session {
	session.statement.Cols(columns...)
	return session
}
755656
func fieldTypeFromPBColumn(col *tipb.ColumnInfo) *types.FieldType {
	return &types.FieldType{
		Tp:      byte(col.GetTp()),
		Flag:    uint(col.Flag),
		Flen:    int(col.GetColumnLen()),
		Decimal: int(col.GetDecimal()),
		Elems:   col.Elems,
		Collate: mysql.Collations[uint8(col.GetCollation())],
	}
}