github.com/altipla-consulting/ravendb-go-client@v0.1.3/document_session_revisions.go (about) 1 package ravendb 2 3 // Note: Java's IRevisionsSessionOperations is DocumentSessionRevisions 4 5 // TODO: write a unique wrapper type 6 type RevisionsSessionOperations = DocumentSessionRevisions 7 8 // DocumentSessionRevisions represents revisions operations 9 type DocumentSessionRevisions struct { 10 *AdvancedSessionExtensionBase 11 } 12 13 func newDocumentSessionRevisions(session *InMemoryDocumentSessionOperations) *DocumentSessionRevisions { 14 return &DocumentSessionRevisions{ 15 AdvancedSessionExtensionBase: newAdvancedSessionExtensionBase(session), 16 } 17 } 18 19 func (r *DocumentSessionRevisions) GetFor(results interface{}, id string) error { 20 return r.GetForPaged(results, id, 0, 25) 21 } 22 23 func (r *DocumentSessionRevisions) GetForStartAt(results interface{}, id string, start int) error { 24 return r.GetForPaged(results, id, start, 25) 25 } 26 27 func (r *DocumentSessionRevisions) GetForPaged(results interface{}, id string, start int, pageSize int) error { 28 operation, err := NewGetRevisionOperationRange(r.session, id, start, pageSize, false) 29 if err != nil { 30 return err 31 } 32 33 command, err := operation.createRequest() 34 if err != nil { 35 return err 36 } 37 err = r.requestExecutor.ExecuteCommand(command, r.sessionInfo) 38 if err != nil { 39 return err 40 } 41 operation.setResult(command.Result) 42 return operation.GetRevisionsFor(results) 43 } 44 45 func (r *DocumentSessionRevisions) GetMetadataFor(id string) ([]*MetadataAsDictionary, error) { 46 return r.GetMetadataForPaged(id, 0, 25) 47 } 48 49 func (r *DocumentSessionRevisions) GetMetadataForStartAt(id string, start int) ([]*MetadataAsDictionary, error) { 50 return r.GetMetadataForPaged(id, start, 25) 51 } 52 53 func (r *DocumentSessionRevisions) GetMetadataForPaged(id string, start int, pageSize int) ([]*MetadataAsDictionary, error) { 54 operation, err := NewGetRevisionOperationRange(r.session, id, start, pageSize, true) 55 if err != nil { 56 return nil, err 57 } 58 command, err := operation.createRequest() 59 if err != nil { 60 return nil, err 61 } 62 err = r.requestExecutor.ExecuteCommand(command, r.sessionInfo) 63 if err != nil { 64 return nil, err 65 } 66 operation.setResult(command.Result) 67 return operation.GetRevisionsMetadataFor(), nil 68 } 69 70 func (r *DocumentSessionRevisions) Get(result interface{}, changeVector string) error { 71 operation := NewGetRevisionOperationWithChangeVectors(r.session, []string{changeVector}) 72 command, err := operation.createRequest() 73 if err != nil { 74 return err 75 } 76 err = r.requestExecutor.ExecuteCommand(command, r.sessionInfo) 77 if err != nil { 78 return err 79 } 80 operation.setResult(command.Result) 81 return operation.GetRevision(result) 82 } 83 84 func (r *DocumentSessionRevisions) GetRevisions(results interface{}, changeVectors []string) error { 85 operation := NewGetRevisionOperationWithChangeVectors(r.session, changeVectors); 86 87 command, err := operation.createRequest(); 88 if err != nil { 89 return err 90 } 91 err = r.requestExecutor.ExecuteCommand(command, r.sessionInfo); 92 if err != nil { 93 return err 94 } 95 operation.setResult(command.Result); 96 return operation.GetRevisions(results); 97 }