summaryrefslogtreecommitdiff
path: root/vendor/github.com/uptrace/bun/schema/reflect.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2021-09-08 20:22:24 +0100
committerLibravatar GitHub <noreply@github.com>2021-09-08 20:22:24 +0100
commit299801f299737364cdd3e5a526bd40df5c48ca93 (patch)
tree2d0926cdcf3088781842a83fd8ed50593006ccc2 /vendor/github.com/uptrace/bun/schema/reflect.go
parentrework media processing a little bit (#191) (diff)
parentupdate bun library -> v1.0.4 (diff)
downloadgotosocial-299801f299737364cdd3e5a526bd40df5c48ca93.tar.xz
Merge pull request #195 from NyaaaWhatsUpDoc/update/bun-library
update bun library -> v1.0.4
Diffstat (limited to 'vendor/github.com/uptrace/bun/schema/reflect.go')
-rw-r--r--vendor/github.com/uptrace/bun/schema/reflect.go70
1 files changed, 70 insertions, 0 deletions
diff --git a/vendor/github.com/uptrace/bun/schema/reflect.go b/vendor/github.com/uptrace/bun/schema/reflect.go
new file mode 100644
index 000000000..5b20b1964
--- /dev/null
+++ b/vendor/github.com/uptrace/bun/schema/reflect.go
@@ -0,0 +1,70 @@
+package schema
+
+import (
+ "database/sql/driver"
+ "encoding/json"
+ "net"
+ "reflect"
+ "time"
+)
+
+var (
+ bytesType = reflect.TypeOf((*[]byte)(nil)).Elem()
+ timeType = reflect.TypeOf((*time.Time)(nil)).Elem()
+ ipType = reflect.TypeOf((*net.IP)(nil)).Elem()
+ ipNetType = reflect.TypeOf((*net.IPNet)(nil)).Elem()
+ jsonRawMessageType = reflect.TypeOf((*json.RawMessage)(nil)).Elem()
+
+ driverValuerType = reflect.TypeOf((*driver.Valuer)(nil)).Elem()
+ queryAppenderType = reflect.TypeOf((*QueryAppender)(nil)).Elem()
+)
+
+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
+}
+
+func fieldByIndexAlloc(v reflect.Value, index []int) reflect.Value {
+ if len(index) == 1 {
+ return v.Field(index[0])
+ }
+
+ for i, idx := range index {
+ if i > 0 {
+ v = indirectNil(v)
+ }
+ v = v.Field(idx)
+ }
+ return v
+}
+
+func indirectNil(v reflect.Value) reflect.Value {
+ if v.Kind() == reflect.Ptr {
+ if v.IsNil() {
+ v.Set(reflect.New(v.Type().Elem()))
+ }
+ v = v.Elem()
+ }
+ return v
+}