-
-
Notifications
You must be signed in to change notification settings - Fork 203
/
append.go
49 lines (46 loc) · 1.12 KB
/
append.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package schema
import (
"reflect"
"strconv"
"time"
"github.com/uptrace/bun/dialect"
)
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:
return strconv.AppendInt(b, int64(v), 10)
case uint32:
return fmter.Dialect().AppendUint32(b, v)
case uint64:
return fmter.Dialect().AppendUint64(b, v)
case float32:
return dialect.AppendFloat32(b, v)
case float64:
return dialect.AppendFloat64(b, v)
case string:
return fmter.Dialect().AppendString(b, v)
case time.Time:
return fmter.Dialect().AppendTime(b, v)
case []byte:
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)
}
appender := Appender(fmter.Dialect(), vv.Type())
return appender(fmter, b, vv)
}
}