2021-08-25 13:34:33 +00:00
|
|
|
package schema
|
|
|
|
|
2021-09-08 19:05:26 +00:00
|
|
|
import (
|
|
|
|
"database/sql/driver"
|
|
|
|
"encoding/json"
|
|
|
|
"net"
|
2024-11-08 13:51:23 +00:00
|
|
|
"net/netip"
|
2021-09-08 19:05:26 +00:00
|
|
|
"reflect"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
bytesType = reflect.TypeOf((*[]byte)(nil)).Elem()
|
2022-04-24 10:26:22 +00:00
|
|
|
timePtrType = reflect.TypeOf((*time.Time)(nil))
|
|
|
|
timeType = timePtrType.Elem()
|
2021-09-08 19:05:26 +00:00
|
|
|
ipType = reflect.TypeOf((*net.IP)(nil)).Elem()
|
|
|
|
ipNetType = reflect.TypeOf((*net.IPNet)(nil)).Elem()
|
2024-11-08 13:51:23 +00:00
|
|
|
netipPrefixType = reflect.TypeOf((*netip.Prefix)(nil)).Elem()
|
|
|
|
netipAddrType = reflect.TypeOf((*netip.Addr)(nil)).Elem()
|
2021-09-08 19:05:26 +00:00
|
|
|
jsonRawMessageType = reflect.TypeOf((*json.RawMessage)(nil)).Elem()
|
|
|
|
|
|
|
|
driverValuerType = reflect.TypeOf((*driver.Valuer)(nil)).Elem()
|
|
|
|
queryAppenderType = reflect.TypeOf((*QueryAppender)(nil)).Elem()
|
2022-04-24 10:26:22 +00:00
|
|
|
jsonMarshalerType = reflect.TypeOf((*json.Marshaler)(nil)).Elem()
|
2021-09-08 19:05:26 +00:00
|
|
|
)
|
2021-08-25 13:34:33 +00:00
|
|
|
|
|
|
|
func indirectType(t reflect.Type) reflect.Type {
|
|
|
|
if t.Kind() == reflect.Ptr {
|
|
|
|
t = t.Elem()
|
|
|
|
}
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func fieldByIndex(v reflect.Value, index []int) (_ reflect.Value, ok bool) {
|
|
|
|
if len(index) == 1 {
|
|
|
|
return v.Field(index[0]), true
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, idx := range index {
|
|
|
|
if i > 0 {
|
|
|
|
if v.Kind() == reflect.Ptr {
|
|
|
|
if v.IsNil() {
|
|
|
|
return v, false
|
|
|
|
}
|
|
|
|
v = v.Elem()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
v = v.Field(idx)
|
|
|
|
}
|
|
|
|
return v, true
|
|
|
|
}
|