예제 #1
0
func newIterator(query Query) model.Iterator {
	mgoQuery, err := query.mongoQuery()
	if err != nil {
		return model.NewErrorOnlyIterator(err)
	}
	mgoIter := mgoQuery.Iter()
	collection, selectors := collectionAndSubDocumentSelectors(query)
	return &MongoIterator{collection: collection, selectors: selectors, iter: mgoIter}
}
예제 #2
0
func NewMongoIterator(query Query) model.Iterator {
	mgoQuery, err := query.mongoQuery()
	if err != nil {
		return model.NewErrorOnlyIterator(err)
	}
	return &MongoIterator{collection: query.Collection(), iter: mgoQuery.Iter()}
	// mgoIter := mgoQuery.Iter()
	// collection, selectors := collectionAndSubDocumentSelectors(query)
	// return &MongoIterator{collection: collection, selectors: selectors, iter: mgoIter}
}
예제 #3
0
// Returns an iterator of dereferenced refs, or an error iterator if there was an error
func DereferenceIterator(refs ...Ref) model.Iterator {
	docs := make([]interface{}, len(refs))
	for i := range refs {
		var err error
		docs[i], err = refs[i].Get()
		if err != nil {
			err = errs.Format("%s: %s", refs[i].ID.Hex(), err.Error())
			return model.NewErrorOnlyIterator(err)
		}
	}
	return model.NewObjectIterator(docs...)
}
예제 #4
0
func (self *Collection) TryDocumentWithIDIterator(id bson.ObjectId, subDocSelectors ...string) model.Iterator {
	if len(subDocSelectors) > 0 {
		panic("Sub document selectors are not implemented")
	}
	document, ok, err := self.TryDocumentWithID(id, subDocSelectors...)
	if err != nil {
		return model.NewErrorOnlyIterator(err)
	}
	if !ok {
		return model.NewObjectIterator()
	}
	return model.NewObjectIterator(document)
}
예제 #5
0
// Returns an iterator of dereferenced refs, or an error iterator if there was an error
func DereferenceIterator(refs ...Ref) model.Iterator {
	var docs []interface{}
	for i := range refs {
		doc, err := refs[i].Get()
		if err != nil {
			err = errs.Format("%s: %s", refs[i].ID.Hex(), err.Error())
			return model.NewErrorOnlyIterator(err)
		} else if doc != nil {
			docs = append(docs, doc)
		}
	}
	return model.NewObjectIterator(docs...)
}
예제 #6
0
func (self *QueryError) Iterator() model.Iterator {
	return model.NewErrorOnlyIterator(self.Err)
}