forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
document_session_revisions.go
80 lines (65 loc) · 2.8 KB
/
document_session_revisions.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package ravendb
import "reflect"
type IRevisionsSessionOperations = DocumentSessionRevisions
type DocumentSessionRevisions struct {
*AdvancedSessionExtentionBase
}
func NewDocumentSessionRevisions(session *InMemoryDocumentSessionOperations) *DocumentSessionRevisions {
return &DocumentSessionRevisions{
AdvancedSessionExtentionBase: NewAdvancedSessionExtentionBase(session),
}
}
func (r *DocumentSessionRevisions) GetFor(clazz reflect.Type, id string) ([]interface{}, error) {
return r.GetForPaged(clazz, id, 0, 25)
}
func (r *DocumentSessionRevisions) GetForStartAt(clazz reflect.Type, id string, start int) ([]interface{}, error) {
return r.GetForPaged(clazz, id, start, 25)
}
// use -1 for start and pageSize to mean: "not given"
func (r *DocumentSessionRevisions) GetForPaged(clazz reflect.Type, id string, start int, pageSize int) ([]interface{}, error) {
operation := NewGetRevisionOperationRange(r.session, id, start, pageSize, false)
command := operation.CreateRequest()
err := r.requestExecutor.ExecuteCommandWithSessionInfo(command, r.sessionInfo)
if err != nil {
return nil, err
}
operation.setResult(command.Result)
return operation.GetRevisionsFor(clazz), nil
}
func (r *DocumentSessionRevisions) GetMetadataFor(id string) ([]*MetadataAsDictionary, error) {
return r.GetMetadataForPaged(id, 0, 25)
}
func (r *DocumentSessionRevisions) GetMetadataForStartAt(id string, start int) ([]*MetadataAsDictionary, error) {
return r.GetMetadataForPaged(id, start, 25)
}
func (r *DocumentSessionRevisions) GetMetadataForPaged(id string, start int, pageSize int) ([]*MetadataAsDictionary, error) {
operation := NewGetRevisionOperationRange(r.session, id, start, pageSize, true)
command := operation.CreateRequest()
err := r.requestExecutor.ExecuteCommandWithSessionInfo(command, r.sessionInfo)
if err != nil {
return nil, err
}
operation.setResult(command.Result)
return operation.GetRevisionsMetadataFor(), nil
}
// TODO: change to take interace{} to return as an argument?
// TODO: change changeVector to *string?
func (r *DocumentSessionRevisions) Get(clazz reflect.Type, changeVector string) (interface{}, error) {
operation := NewGetRevisionOperationWithChangeVector(r.session, changeVector)
command := operation.CreateRequest()
err := r.requestExecutor.ExecuteCommandWithSessionInfo(command, r.sessionInfo)
if err != nil {
return nil, err
}
operation.setResult(command.Result)
return operation.GetRevision(clazz), nil
}
/*
public <T> Map<String, T> get(Class<T> clazz, String[] changeVectors) {
GetRevisionOperation operation = new GetRevisionOperation(session, changeVectors);
GetRevisionsCommand command = operation.CreateRequest();
requestExecutor.execute(command, sessionInfo);
operation.setResult(command.getResult());
return operation.GetRevisions(clazz);
}
*/