Exemplo n.º 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}
}
Exemplo n.º 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}
}
Exemplo n.º 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...)
}
Exemplo n.º 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)
}
Exemplo n.º 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...)
}
Exemplo n.º 6
0
func (self *QueryError) Iterator() model.Iterator {
	return model.NewErrorOnlyIterator(self.Err)
}