mirror of
1
Fork 0
gotosocial/vendor/github.com/uptrace/bun/schema/append.go

50 lines
1.1 KiB
Go
Raw Normal View History

package schema
import (
"reflect"
"strconv"
"time"
"github.com/uptrace/bun/dialect"
)
2021-10-24 13:14:37 +02:00
func Append(fmter Formatter, b []byte, v interface{}) []byte {
switch v := v.(type) {
case nil:
return dialect.AppendNull(b)
case bool:
return dialect.AppendBool(b, v)
case int:
return strconv.AppendInt(b, int64(v), 10)
case int32:
return strconv.AppendInt(b, int64(v), 10)
case int64:
return strconv.AppendInt(b, v, 10)
case uint:
2021-10-24 13:14:37 +02:00
return strconv.AppendInt(b, int64(v), 10)
case uint32:
2021-10-24 13:14:37 +02:00
return fmter.Dialect().AppendUint32(b, v)
case uint64:
2021-10-24 13:14:37 +02:00
return fmter.Dialect().AppendUint64(b, v)
case float32:
return dialect.AppendFloat32(b, v)
case float64:
return dialect.AppendFloat64(b, v)
case string:
2021-11-13 12:29:08 +01:00
return fmter.Dialect().AppendString(b, v)
case time.Time:
2021-10-24 13:14:37 +02:00
return fmter.Dialect().AppendTime(b, v)
case []byte:
2021-10-24 13:14:37 +02:00
return fmter.Dialect().AppendBytes(b, v)
case QueryAppender:
return AppendQueryAppender(fmter, b, v)
default:
vv := reflect.ValueOf(v)
if vv.Kind() == reflect.Ptr && vv.IsNil() {
return dialect.AppendNull(b)
}
2021-10-24 13:14:37 +02:00
appender := Appender(fmter.Dialect(), vv.Type())
return appender(fmter, b, vv)
}
}