github.com/ravendb/ravendb-go-client@v0.0.0-20240229102137-4474ee7aa0fa/lazy_session_operations.go (about) 1 package ravendb 2 3 // Note: ILazySessionOperations is LazySessionOperations 4 5 // LazySessionOperations describes API for lazy operations 6 type LazySessionOperations struct { 7 delegate *DocumentSession 8 } 9 10 func newLazySessionOperations(delegate *DocumentSession) *LazySessionOperations { 11 return &LazySessionOperations{ 12 delegate: delegate, 13 } 14 } 15 16 // Include adds a given object path to be included in results 17 func (o *LazySessionOperations) Include(path string) *LazyMultiLoaderWithInclude { 18 return NewLazyMultiLoaderWithInclude(o.delegate).Include(path) 19 } 20 21 func (o *LazySessionOperations) LoadWithEval(id string, onEval func(), onEvalResult interface{}) (*Lazy, error) { 22 if id == "" { 23 return nil, newIllegalArgumentError("id cannot be empty string") 24 } 25 if o.delegate.IsLoaded(id) { 26 fn := func(result interface{}) error { 27 return o.delegate.Load(result, id) 28 } 29 return newLazy(fn), nil 30 } 31 32 session := o.delegate.InMemoryDocumentSessionOperations 33 op := NewLoadOperation(session).byID(id) 34 lazyLoadOperation := newLazyLoadOperation(session, op).byID(id) 35 return o.delegate.addLazyOperation(lazyLoadOperation, onEval, onEvalResult), nil 36 } 37 38 func (o *LazySessionOperations) Load(id string) (*Lazy, error) { 39 return o.LoadWithEval(id, nil, nil) 40 } 41 42 // LoadStartingWith returns Lazy object for lazily loading multiple value 43 // of a given type and matching args 44 // results should be map[string]*Struct 45 func (o *LazySessionOperations) LoadStartingWith(args *StartsWithArgs) *Lazy { 46 session := o.delegate.InMemoryDocumentSessionOperations 47 operation := NewLazyStartsWithOperation(args.StartsWith, args.Matches, args.Exclude, args.Start, args.PageSize, session, args.StartAfter) 48 49 return o.delegate.addLazyOperation(operation, nil, nil) 50 } 51 52 // LoadMulti returns Lazy object for lazily loading multiple values 53 // of a given type and with given ids 54 func (o *LazySessionOperations) LoadMulti(ids []string) (*Lazy, error) { 55 if len(ids) == 0 { 56 return nil, newIllegalArgumentError("ids cannot be empty array") 57 } 58 return o.delegate.lazyLoadInternal(ids, nil, nil, nil), nil 59 } 60 61 func (o *LazySessionOperations) LoadMultiWithEval(ids []string, onEval func(), onEvalResult interface{}) (*Lazy, error) { 62 if len(ids) == 0 { 63 return nil, newIllegalArgumentError("ids cannot be empty array") 64 } 65 return o.delegate.lazyLoadInternal(ids, nil, onEval, onEvalResult), nil 66 }