예제 #1
0
파일: append.go 프로젝트: uruddarraju/pg
// Returns nil when src is NULL.
func appendIfaceRaw(dst []byte, srci interface{}) []byte {
	if srci == nil {
		return nil
	}

	switch src := srci.(type) {
	case bool:
		return appendBool(dst, src)
	case int8:
		return strconv.AppendInt(dst, int64(src), 10)
	case int16:
		return strconv.AppendInt(dst, int64(src), 10)
	case int32:
		return strconv.AppendInt(dst, int64(src), 10)
	case int64:
		return strconv.AppendInt(dst, int64(src), 10)
	case int:
		return strconv.AppendInt(dst, int64(src), 10)
	case uint8:
		return strconv.AppendInt(dst, int64(src), 10)
	case uint16:
		return strconv.AppendInt(dst, int64(src), 10)
	case uint32:
		return strconv.AppendInt(dst, int64(src), 10)
	case uint64:
		return strconv.AppendInt(dst, int64(src), 10)
	case uint:
		return strconv.AppendInt(dst, int64(src), 10)
	case float32:
		return appendFloat(dst, float64(src))
	case float64:
		return appendFloat(dst, src)
	case string:
		return appendStringRaw(dst, src)
	case time.Time:
		return pgutil.AppendTime(dst, src)
	case []byte:
		return appendBytes(dst, src)
	case []string:
		return appendStringSlice(dst, src, true)
	case []int:
		return appendIntSlice(dst, src)
	case []int64:
		return appendInt64Slice(dst, src)
	case []float64:
		return appendFloat64Slice(dst, src)
	case map[string]string:
		return appendStringStringMap(dst, src, true)
	case RawQueryAppender:
		return src.AppendRawQuery(dst)
	case driver.Valuer:
		return appendDriverValueRaw(dst, src)
	default:
		return appendValueRaw(dst, reflect.ValueOf(srci))
	}
}
예제 #2
0
파일: append.go 프로젝트: anmic/pg
func appendTime(b []byte, tm time.Time, quote bool) []byte {
	if quote {
		b = append(b, '\'')
	}
	b = pgutil.AppendTime(b, tm)
	if quote {
		b = append(b, '\'')
	}
	return b
}
예제 #3
0
파일: append.go 프로젝트: uruddarraju/pg
func appendValueRaw(dst []byte, v reflect.Value) []byte {
	switch v.Kind() {
	case reflect.Ptr:
		if v.IsNil() {
			return nil
		}
		return appendValueRaw(dst, v.Elem())
	case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int:
		return strconv.AppendInt(dst, v.Int(), 10)
	case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint:
		return strconv.AppendUint(dst, v.Uint(), 10)
	case reflect.Float32, reflect.Float64:
		return appendFloat(dst, v.Float())
	case reflect.String:
		return appendStringRaw(dst, v.String())
	case reflect.Struct:
		if v.Type() == timeType {
			return pgutil.AppendTime(dst, v.Interface().(time.Time))
		}
	}
	panic(fmt.Sprintf("pg: Format(unsupported %s)", v.Type()))
}
예제 #4
0
파일: append.go 프로젝트: uruddarraju/pg
func appendIface(dst []byte, srci interface{}) []byte {
	if srci == nil {
		return appendNull(dst)
	}

	switch src := srci.(type) {
	case bool:
		return appendBool(dst, src)
	case int8:
		return strconv.AppendInt(dst, int64(src), 10)
	case int16:
		return strconv.AppendInt(dst, int64(src), 10)
	case int32:
		return strconv.AppendInt(dst, int64(src), 10)
	case int64:
		return strconv.AppendInt(dst, int64(src), 10)
	case int:
		return strconv.AppendInt(dst, int64(src), 10)
	case uint8:
		return strconv.AppendUint(dst, uint64(src), 10)
	case uint16:
		return strconv.AppendUint(dst, uint64(src), 10)
	case uint32:
		return strconv.AppendUint(dst, uint64(src), 10)
	case uint64:
		return strconv.AppendUint(dst, src, 10)
	case uint:
		return strconv.AppendUint(dst, uint64(src), 10)
	case float32:
		return appendFloat(dst, float64(src))
	case float64:
		return appendFloat(dst, src)
	case string:
		return appendString(dst, src)
	case time.Time:
		dst = append(dst, '\'')
		dst = pgutil.AppendTime(dst, src)
		dst = append(dst, '\'')
		return dst
	case []byte:
		dst = append(dst, '\'')
		dst = appendBytes(dst, src)
		dst = append(dst, '\'')
		return dst
	case []string:
		dst = append(dst, '\'')
		dst = appendStringSlice(dst, src, false)
		dst = append(dst, '\'')
		return dst
	case []int:
		dst = append(dst, '\'')
		dst = appendIntSlice(dst, src)
		dst = append(dst, '\'')
		return dst
	case []int64:
		dst = append(dst, '\'')
		dst = appendInt64Slice(dst, src)
		dst = append(dst, '\'')
		return dst
	case []float64:
		dst = append(dst, '\'')
		dst = appendFloat64Slice(dst, src)
		dst = append(dst, '\'')
		return dst
	case map[string]string:
		dst = append(dst, '\'')
		dst = appendStringStringMap(dst, src, false)
		dst = append(dst, '\'')
		return dst
	case QueryAppender:
		return src.AppendQuery(dst)
	case driver.Valuer:
		return appendDriverValuer(dst, src)
	default:
		return appendValue(dst, reflect.ValueOf(srci))
	}
}
예제 #5
0
파일: append_value.go 프로젝트: koheeba/pg
func appendTimeValue(dst []byte, v reflect.Value) []byte {
	dst = append(dst, '\'')
	dst = pgutil.AppendTime(dst, v.Interface().(time.Time))
	dst = append(dst, '\'')
	return dst
}