forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
document_session_attachments.go
51 lines (44 loc) · 1.73 KB
/
document_session_attachments.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
package ravendb
type IAttachmentsSessionOperations = DocumentSessionAttachments
type DocumentSessionAttachments struct {
*DocumentSessionAttachmentsBase
}
func NewDocumentSessionAttachments(session *InMemoryDocumentSessionOperations) *DocumentSessionAttachments {
res := &DocumentSessionAttachments{}
res.DocumentSessionAttachmentsBase = NewDocumentSessionAttachmentsBase(session)
return res
}
func (s *DocumentSessionAttachments) Exists(documentId string, name string) (bool, error) {
command := NewHeadAttachmentCommand(documentId, name, nil)
err := s.requestExecutor.ExecuteCommandWithSessionInfo(command, s.sessionInfo)
if err != nil {
return false, err
}
res := command.Result != ""
return res, nil
}
func (s *DocumentSessionAttachments) Get(documentId string, name string) (*CloseableAttachmentResult, error) {
operation := NewGetAttachmentOperation(documentId, name, AttachmentType_DOCUMENT, "", nil)
err := s.session.GetOperations().SendWithSessionInfo(operation, s.sessionInfo)
if err != nil {
return nil, err
}
res := operation.Command.Result
return res, nil
}
func (s *DocumentSessionAttachments) GetEntity(entity Object, name string) (*CloseableAttachmentResult, error) {
document := s.documentsByEntity[entity]
if document == nil {
return nil, throwEntityNotInSession(entity)
}
return s.Get(document.id, name)
}
func (s *DocumentSessionAttachments) GetRevision(documentId string, name string, changeVector *string) (*CloseableAttachmentResult, error) {
operation := NewGetAttachmentOperation(documentId, name, AttachmentType_REVISION, "", changeVector)
err := s.session.GetOperations().SendWithSessionInfo(operation, s.sessionInfo)
if err != nil {
return nil, err
}
res := operation.Command.Result
return res, nil
}