github.com/altipla-consulting/ravendb-go-client@v0.1.3/document_session_attachments.go (about) 1 package ravendb 2 3 // Note: Java's IAttachmentsSessionOperations is DocumentSessionAttachments 4 5 // TODO: make a unique wrapper type 6 type AttachmentsSessionOperations = DocumentSessionAttachments 7 8 type DocumentSessionAttachments struct { 9 *DocumentSessionAttachmentsBase 10 } 11 12 func NewDocumentSessionAttachments(session *InMemoryDocumentSessionOperations) *DocumentSessionAttachments { 13 res := &DocumentSessionAttachments{} 14 res.DocumentSessionAttachmentsBase = NewDocumentSessionAttachmentsBase(session) 15 return res 16 } 17 18 func (s *DocumentSessionAttachments) Exists(documentID string, name string) (bool, error) { 19 command, err := NewHeadAttachmentCommand(documentID, name, nil) 20 if err != nil { 21 return false, err 22 } 23 err = s.requestExecutor.ExecuteCommand(command, s.sessionInfo) 24 if err != nil { 25 return false, err 26 } 27 res := command.Result != "" 28 return res, nil 29 } 30 31 func (s *DocumentSessionAttachments) GetByID(documentID string, name string) (*AttachmentResult, error) { 32 operation := NewGetAttachmentOperation(documentID, name, AttachmentDocument, "", nil) 33 err := s.session.GetOperations().Send(operation, s.sessionInfo) 34 if err != nil { 35 return nil, err 36 } 37 res := operation.Command.Result 38 return res, nil 39 } 40 41 func (s *DocumentSessionAttachments) Get(entity interface{}, name string) (*AttachmentResult, error) { 42 document := getDocumentInfoByEntity(s.documents, entity) 43 if document == nil { 44 return nil, throwEntityNotInSession(entity) 45 } 46 return s.GetByID(document.id, name) 47 } 48 49 func (s *DocumentSessionAttachments) GetRevision(documentID string, name string, changeVector *string) (*AttachmentResult, error) { 50 operation := NewGetAttachmentOperation(documentID, name, AttachmentRevision, "", changeVector) 51 err := s.session.GetOperations().Send(operation, s.sessionInfo) 52 if err != nil { 53 return nil, err 54 } 55 res := operation.Command.Result 56 return res, nil 57 }