unexport fields in Query struct

This commit is contained in:
parent aa16700270
commit 5a8f2301fc
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C
2 changed files with 16 additions and 19 deletions

@ -140,10 +140,10 @@ func (m *Model) Find(query interface{}, opts ...*options.FindOptions) (*Query, e
qqv := reflect.New(qqt)
qqv.Elem().Set(reflect.MakeSlice(qqt, 0, 0))
qq := &Query{
Model: m,
Collection: m.getColl(),
model: m,
collection: m.getColl(),
doc: qqv.Interface(),
Op: OP_FIND_ALL,
op: OP_FIND_ALL,
}
q, err := m.FindRaw(query, opts...)
@ -177,7 +177,7 @@ func (m *Model) FindPaged(query interface{}, page int64, perPage int64, opts ...
opts = append(opts, options.Find().SetSkip(skipAmt).SetLimit(perPage))
}
q, err := m.Find(query, opts...)
q.Op = OP_FIND_PAGED
q.op = OP_FIND_PAGED
return q, err
}
@ -200,11 +200,11 @@ func (m *Model) FindOne(query interface{}, options ...*options.FindOneOptions) (
v := reflect.New(reflect.TypeOf(qqn))
v.Elem().Set(reflect.ValueOf(qqn))
qq := &Query{
Collection: m.getColl(),
collection: m.getColl(),
rawDoc: raw,
doc: v.Elem().Interface(),
Op: OP_FIND_ONE,
Model: m,
op: OP_FIND_ONE,
model: m,
}
qq.rawDoc = raw
err = rip.Decode(qq.doc)

@ -15,15 +15,12 @@ import (
)
type Query struct {
// the handle of the collection associated with this query
Collection *mongo.Collection
// the operation from which this query stems
Op string
// the model instance associated with this query
Model *Model
done bool
rawDoc any
doc any
collection *mongo.Collection
op string
model *Model
done bool
rawDoc any
doc any
}
const (
@ -189,7 +186,7 @@ func populate(r Reference, rcoll string, rawDoc interface{}, d string, src inter
// Populate populates document references via reflection
func (q *Query) Populate(fields ...string) *Query {
_, cm, _ := ModelRegistry.HasByName(q.Model.typeName)
_, cm, _ := ModelRegistry.HasByName(q.model.typeName)
if cm != nil {
rawDoc := q.rawDoc
@ -254,7 +251,7 @@ func (q *Query) Populate(fields ...string) *Query {
func (q *Query) reOrganize() {
var trvo reflect.Value
if arr, ok := q.rawDoc.(bson.A); ok {
typ := ModelRegistry[q.Model.typeName].Type
typ := ModelRegistry[q.model.typeName].Type
if typ.Kind() != reflect.Pointer {
typ = reflect.PointerTo(typ)
}
@ -495,6 +492,6 @@ func (q *Query) Exec(result interface{}) {
}
}
reflect.ValueOf(result).Elem().Set(reflect.ValueOf(q.doc).Elem())
q.Model.self = q.doc
q.model.self = q.doc
q.done = true
}