mirror of
https://github.com/mainnika/mongox-go-driver.git
synced 2026-06-12 16:53:35 +00:00
LoadMany structure is now known as LoadStream
This commit is contained in:
@@ -9,15 +9,15 @@ import (
|
|||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ManyLoader is a controller for a database cursor
|
// StreamLoader is a controller for a database cursor
|
||||||
type ManyLoader struct {
|
type StreamLoader struct {
|
||||||
*mongo.Cursor
|
*mongo.Cursor
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
target interface{}
|
target interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNext loads next documents to a target or returns an error
|
// DecodeNext loads next documents to a target or returns an error
|
||||||
func (l *ManyLoader) GetNext() error {
|
func (l *StreamLoader) DecodeNext() error {
|
||||||
|
|
||||||
hasNext := l.Cursor.Next(l.ctx)
|
hasNext := l.Cursor.Next(l.ctx)
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ func (l *ManyLoader) GetNext() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Next loads next documents but doesn't perform decoding
|
// Next loads next documents but doesn't perform decoding
|
||||||
func (l *ManyLoader) Next() error {
|
func (l *StreamLoader) Next() error {
|
||||||
|
|
||||||
hasNext := l.Cursor.Next(l.ctx)
|
hasNext := l.Cursor.Next(l.ctx)
|
||||||
if !hasNext {
|
if !hasNext {
|
||||||
@@ -50,13 +50,13 @@ func (l *ManyLoader) Next() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Close cursor
|
// Close cursor
|
||||||
func (l *ManyLoader) Close() error {
|
func (l *StreamLoader) Close() error {
|
||||||
|
|
||||||
return l.Cursor.Close(l.ctx)
|
return l.Cursor.Close(l.ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadMany function loads documents one by one into a target channel
|
// LoadStream function loads documents one by one into a target channel
|
||||||
func LoadMany(db *mongox.Database, target interface{}, filters ...interface{}) (*ManyLoader, error) {
|
func LoadStream(db *mongox.Database, target interface{}, filters ...interface{}) (*StreamLoader, error) {
|
||||||
|
|
||||||
var cursor *mongo.Cursor
|
var cursor *mongo.Cursor
|
||||||
var err error
|
var err error
|
||||||
@@ -73,7 +73,7 @@ func LoadMany(db *mongox.Database, target interface{}, filters ...interface{}) (
|
|||||||
return nil, errors.InternalErrorf("can't create find result: %s", err)
|
return nil, errors.InternalErrorf("can't create find result: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
l := &ManyLoader{Cursor: cursor, ctx: db.Context(), target: target}
|
l := &StreamLoader{Cursor: cursor, ctx: db.Context(), target: target}
|
||||||
|
|
||||||
return l, nil
|
return l, nil
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user