diff --git a/document_internals.go b/document_internals.go index 70568ec..cb3838b 100644 --- a/document_internals.go +++ b/document_internals.go @@ -39,21 +39,6 @@ func serializeIDs(input interface{}) interface{} { return nil } } - /*var itagged interface{} - if reflect.ValueOf(itagged).Kind() != reflect.Pointer { - itagged = incrementTagged(&input) - } else { - itagged = incrementTagged(input) - } - taggedVal := reflect.ValueOf(reflect.ValueOf(itagged).Interface()).Elem() - if vp.Kind() == reflect.Ptr { - tmp := reflect.ValueOf(taggedVal.Interface()) - if tmp.Kind() == reflect.Pointer { - vp.Elem().Set(tmp.Elem()) - } else { - vp.Elem().Set(tmp) - } - }*/ switch vp.Elem().Kind() { case reflect.Struct: ret0 := bson.M{} @@ -72,10 +57,6 @@ func serializeIDs(input interface{}) interface{} { bson.Unmarshal(marsh, &unmarsh) for k, v := range unmarsh { ret0[k] = v - /*if t, ok := v.(primitive.DateTime); ok { - ret0 - } else { - }*/ } } else { _, terr := tag.Get("ref") @@ -92,8 +73,6 @@ func serializeIDs(input interface{}) interface{} { rarr = append(rarr, getID(fv.Index(j).Interface())) } ret0[bbson.Name] = rarr - /*ret0[bbson.Name] = serializeIDs(fv.Interface()) - break*/ } else if !ok { panic(fmt.Sprintf("referenced model slice at '%s.%s' does not implement HasID", nameOf(input), ft.Name)) } else { diff --git a/query.go b/query.go index e1b09f2..9e1ba31 100644 --- a/query.go +++ b/query.go @@ -290,21 +290,11 @@ func (q *Query) reOrganize() { slic := reflect.New(reflect.SliceOf(typ)) for _, v2 := range arr { inter := reflect.ValueOf(rerere(v2, typ)) - /*if inter.Kind() == reflect.Pointer { - inter = inter.Elem() - }*/ slic.Elem().Set(reflect.Append(slic.Elem(), inter)) } trvo = slic.Elem() } else { trvo = reflect.ValueOf(rerere(q.rawDoc, reflect.TypeOf(q.doc))) - /*for { - if trvo.Kind() == reflect.Pointer { - trvo = trvo.Elem() - } else { - break - } - }*/ } resV := reflect.ValueOf(q.doc) diff --git a/registry.go b/registry.go index 060c8d4..6c81e2c 100644 --- a/registry.go +++ b/registry.go @@ -5,7 +5,6 @@ import ( "fmt" "log" "reflect" - "strings" "sync" "github.com/fatih/structtag" @@ -45,7 +44,7 @@ type TModelRegistry map[string]*Model // ModelRegistry - the ModelRegistry stores a map containing // pointers to Model instances, keyed by an associated // model name -var ModelRegistry = make(TModelRegistry, 0) +var ModelRegistry = make(TModelRegistry) // DB - The mongodb database handle var DB *mongo.Database @@ -59,26 +58,6 @@ var NextStringID func() string var mutex sync.Mutex -func getRawTypeFromTag(tagOpt string, slice bool) reflect.Type { - var t reflect.Type - switch strings.ToLower(tagOpt) { - case "int": - var v int64 = 0 - t = reflect.TypeOf(v) - case "uint": - var v uint = 0 - t = reflect.TypeOf(v) - case "string": - var v = "0" - t = reflect.TypeOf(v) - - } - if slice { - return reflect.SliceOf(t) - } - return t -} - func makeGfsRef(tag *structtag.Tag, idx int) gridFSReference { opts := tag.Options var ffmt string @@ -183,10 +162,6 @@ func parseTags(t reflect.Type, v reflect.Value) (map[string][]InternalIndex, map break } if refTag, ok := tags.Get("ref"); ok == nil { - // ref:"ModelName,refType" - /* if len(refTag.Options) < 1 { - panic("no raw type provided for ref") - } */ sname := sft.Name + "@" + refTag.Name refs[sname] = makeRef(i, refTag.Name, sft.Name, sft.Type) } diff --git a/testing.go b/testing.go index e294110..dc7dcad 100644 --- a/testing.go +++ b/testing.go @@ -136,7 +136,7 @@ func genChaps(single bool) []chapter { ret = append(ret, chapter{ ID: primitive.NewObjectID(), Title: fmt.Sprintf("-%d-", i+1), - Index: int(i + 1), + Index: i + 1, Words: 50, Notes: "notenotenote !!!", Genre: []string{"Slash"}, @@ -202,10 +202,6 @@ func initTest() { author.ID = 696969 ModelRegistry.Model(band{}, user{}, story{}) } -func after() { - err := DBClient.Disconnect(context.TODO()) - panik(err) -} var metallica = band{ ID: 1, diff --git a/util.go b/util.go index c7ea36c..a4fb780 100644 --- a/util.go +++ b/util.go @@ -64,7 +64,7 @@ func getNested(field string, aValue reflect.Value) (*reflect.Type, *reflect.Valu } aft := value.Type() dots := strings.Split(field, ".") - if value.Kind() != reflect.Struct /*&& arrRegex.FindString(dots[0]) == ""*/ { + if value.Kind() != reflect.Struct { if value.Kind() == reflect.Slice { st := reflect.MakeSlice(value.Type().Elem(), 0, 0) for i := 0; i < value.Len(); i++ { @@ -85,8 +85,6 @@ func getNested(field string, aValue reflect.Value) (*reflect.Type, *reflect.Valu } else { return &aft, &value, nil } - /*ft := value.Type() - */ } ref := value if ref.Kind() == reflect.Pointer { @@ -96,7 +94,7 @@ func getNested(field string, aValue reflect.Value) (*reflect.Type, *reflect.Valu if arrRegex.FindString(dots[0]) != "" && fv.Kind() == reflect.Slice { matches := arrRegex.FindStringSubmatch(dots[0]) ridx, _ := strconv.Atoi(matches[0]) - idx := int(ridx) + idx := ridx fv = fv.Index(idx) } @@ -194,20 +192,3 @@ func normalizeSliceToDocumentSlice(in any) *DocumentSlice { } return &ret } - -/*func normalizeDocSlice(iput reflect.Value) reflect.Value { - idslice, idsliceOk := iput.Interface().(IDocumentSlice) - dslice, dsliceOk := resV.Interface().(DocumentSlice) - switch { - case idsliceOk: - - case dsliceOk: - default: - return iput - } - //if { - // resV.Set(trvo.Elem()) - //} else { - // - //} -}*/