2021-08-25 15:34:33 +02:00
|
|
|
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 {
|
2021-08-25 15:34:33 +02:00
|
|
|
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)
|
2021-08-25 15:34:33 +02:00
|
|
|
case uint32:
|
2021-10-24 13:14:37 +02:00
|
|
|
return fmter.Dialect().AppendUint32(b, v)
|
2021-08-25 15:34:33 +02:00
|
|
|
case uint64:
|
2021-10-24 13:14:37 +02:00
|
|
|
return fmter.Dialect().AppendUint64(b, v)
|
2021-08-25 15:34:33 +02:00
|
|
|
case float32:
|
|
|
|
return dialect.AppendFloat32(b, v)
|
|
|
|
case float64:
|
|
|
|
return dialect.AppendFloat64(b, v)
|
|
|
|
case string:
|
|
|
|
return dialect.AppendString(b, v)
|
|
|
|
case time.Time:
|
2021-10-24 13:14:37 +02:00
|
|
|
return fmter.Dialect().AppendTime(b, v)
|
2021-08-25 15:34:33 +02:00
|
|
|
case []byte:
|
2021-10-24 13:14:37 +02:00
|
|
|
return fmter.Dialect().AppendBytes(b, v)
|
2021-08-25 15:34:33 +02:00
|
|
|
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())
|
2021-08-25 15:34:33 +02:00
|
|
|
return appender(fmter, b, vv)
|
|
|
|
}
|
|
|
|
}
|