unexport fields in Query struct
This commit is contained in:
parent
aa16700270
commit
5a8f2301fc
14
model.go
14
model.go
@ -140,10 +140,10 @@ func (m *Model) Find(query interface{}, opts ...*options.FindOptions) (*Query, e
|
|||||||
qqv := reflect.New(qqt)
|
qqv := reflect.New(qqt)
|
||||||
qqv.Elem().Set(reflect.MakeSlice(qqt, 0, 0))
|
qqv.Elem().Set(reflect.MakeSlice(qqt, 0, 0))
|
||||||
qq := &Query{
|
qq := &Query{
|
||||||
Model: m,
|
model: m,
|
||||||
Collection: m.getColl(),
|
collection: m.getColl(),
|
||||||
doc: qqv.Interface(),
|
doc: qqv.Interface(),
|
||||||
Op: OP_FIND_ALL,
|
op: OP_FIND_ALL,
|
||||||
}
|
}
|
||||||
q, err := m.FindRaw(query, opts...)
|
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))
|
opts = append(opts, options.Find().SetSkip(skipAmt).SetLimit(perPage))
|
||||||
}
|
}
|
||||||
q, err := m.Find(query, opts...)
|
q, err := m.Find(query, opts...)
|
||||||
q.Op = OP_FIND_PAGED
|
q.op = OP_FIND_PAGED
|
||||||
return q, err
|
return q, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,11 +200,11 @@ func (m *Model) FindOne(query interface{}, options ...*options.FindOneOptions) (
|
|||||||
v := reflect.New(reflect.TypeOf(qqn))
|
v := reflect.New(reflect.TypeOf(qqn))
|
||||||
v.Elem().Set(reflect.ValueOf(qqn))
|
v.Elem().Set(reflect.ValueOf(qqn))
|
||||||
qq := &Query{
|
qq := &Query{
|
||||||
Collection: m.getColl(),
|
collection: m.getColl(),
|
||||||
rawDoc: raw,
|
rawDoc: raw,
|
||||||
doc: v.Elem().Interface(),
|
doc: v.Elem().Interface(),
|
||||||
Op: OP_FIND_ONE,
|
op: OP_FIND_ONE,
|
||||||
Model: m,
|
model: m,
|
||||||
}
|
}
|
||||||
qq.rawDoc = raw
|
qq.rawDoc = raw
|
||||||
err = rip.Decode(qq.doc)
|
err = rip.Decode(qq.doc)
|
||||||
|
21
query.go
21
query.go
@ -15,15 +15,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Query struct {
|
type Query struct {
|
||||||
// the handle of the collection associated with this query
|
collection *mongo.Collection
|
||||||
Collection *mongo.Collection
|
op string
|
||||||
// the operation from which this query stems
|
model *Model
|
||||||
Op string
|
done bool
|
||||||
// the model instance associated with this query
|
rawDoc any
|
||||||
Model *Model
|
doc any
|
||||||
done bool
|
|
||||||
rawDoc any
|
|
||||||
doc any
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -189,7 +186,7 @@ func populate(r Reference, rcoll string, rawDoc interface{}, d string, src inter
|
|||||||
|
|
||||||
// Populate populates document references via reflection
|
// Populate populates document references via reflection
|
||||||
func (q *Query) Populate(fields ...string) *Query {
|
func (q *Query) Populate(fields ...string) *Query {
|
||||||
_, cm, _ := ModelRegistry.HasByName(q.Model.typeName)
|
_, cm, _ := ModelRegistry.HasByName(q.model.typeName)
|
||||||
|
|
||||||
if cm != nil {
|
if cm != nil {
|
||||||
rawDoc := q.rawDoc
|
rawDoc := q.rawDoc
|
||||||
@ -254,7 +251,7 @@ func (q *Query) Populate(fields ...string) *Query {
|
|||||||
func (q *Query) reOrganize() {
|
func (q *Query) reOrganize() {
|
||||||
var trvo reflect.Value
|
var trvo reflect.Value
|
||||||
if arr, ok := q.rawDoc.(bson.A); ok {
|
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 {
|
if typ.Kind() != reflect.Pointer {
|
||||||
typ = reflect.PointerTo(typ)
|
typ = reflect.PointerTo(typ)
|
||||||
}
|
}
|
||||||
@ -495,6 +492,6 @@ func (q *Query) Exec(result interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
reflect.ValueOf(result).Elem().Set(reflect.ValueOf(q.doc).Elem())
|
reflect.ValueOf(result).Elem().Set(reflect.ValueOf(q.doc).Elem())
|
||||||
q.Model.self = q.doc
|
q.model.self = q.doc
|
||||||
q.done = true
|
q.done = true
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user