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