forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
document_session_revisions.go
97 lines (83 loc) · 2.93 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package ravendb
// Note: Java's IRevisionsSessionOperations is DocumentSessionRevisions
// TODO: write a unique wrapper type
type RevisionsSessionOperations = DocumentSessionRevisions
// DocumentSessionRevisions represents revisions operations
type DocumentSessionRevisions struct {
*AdvancedSessionExtensionBase
}
func newDocumentSessionRevisions(session *InMemoryDocumentSessionOperations) *DocumentSessionRevisions {
return &DocumentSessionRevisions{
AdvancedSessionExtensionBase: newAdvancedSessionExtensionBase(session),
}
}
func (r *DocumentSessionRevisions) GetFor(results interface{}, id string) error {
return r.GetForPaged(results, id, 0, 25)
}
func (r *DocumentSessionRevisions) GetForStartAt(results interface{}, id string, start int) error {
return r.GetForPaged(results, id, start, 25)
}
func (r *DocumentSessionRevisions) GetForPaged(results interface{}, id string, start int, pageSize int) error {
operation, err := NewGetRevisionOperationRange(r.session, id, start, pageSize, false)
if err != nil {
return err
}
command, err := operation.createRequest()
if err != nil {
return err
}
err = r.requestExecutor.ExecuteCommand(command, r.sessionInfo)
if err != nil {
return err
}
operation.setResult(command.Result)
return operation.GetRevisionsFor(results)
}
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, err := NewGetRevisionOperationRange(r.session, id, start, pageSize, true)
if err != nil {
return nil, err
}
command, err := operation.createRequest()
if err != nil {
return nil, err
}
err = r.requestExecutor.ExecuteCommand(command, r.sessionInfo)
if err != nil {
return nil, err
}
operation.setResult(command.Result)
return operation.GetRevisionsMetadataFor(), nil
}
func (r *DocumentSessionRevisions) Get(result interface{}, changeVector string) error {
operation := NewGetRevisionOperationWithChangeVectors(r.session, []string{changeVector})
command, err := operation.createRequest()
if err != nil {
return err
}
err = r.requestExecutor.ExecuteCommand(command, r.sessionInfo)
if err != nil {
return err
}
operation.setResult(command.Result)
return operation.GetRevision(result)
}
func (r *DocumentSessionRevisions) GetRevisions(results interface{}, changeVectors []string) error {
operation := NewGetRevisionOperationWithChangeVectors(r.session, changeVectors);
command, err := operation.createRequest();
if err != nil {
return err
}
err = r.requestExecutor.ExecuteCommand(command, r.sessionInfo);
if err != nil {
return err
}
operation.setResult(command.Result);
return operation.GetRevisions(results);
}