forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
document.go
50 lines (41 loc) · 1.86 KB
/
document.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
package influxdb
import (
"context"
"github.com/influxdata/influxdb/v2/kit/platform"
)
// ErrDocumentNotFound is the error msg for a missing document.
const ErrDocumentNotFound = "document not found"
// DocumentService is used to create/find instances of document stores.
type DocumentService interface {
CreateDocumentStore(ctx context.Context, name string) (DocumentStore, error)
FindDocumentStore(ctx context.Context, name string) (DocumentStore, error)
}
// Document is a generic structure for stating data.
type Document struct {
ID platform.ID `json:"id"`
Meta DocumentMeta `json:"meta"`
Content interface{} `json:"content,omitempty"` // TODO(desa): maybe this needs to be json.Marshaller & json.Unmarshaler
Labels []*Label `json:"labels,omitempty"` // read only
// This is needed for authorization.
// The service that passes documents around will take care of filling it
// via request parameters or others, as the kv store will take care of
// filling it once it returns a document.
// This is not stored in the kv store neither required in the API.
Organizations map[platform.ID]UserType `json:"-"`
}
// DocumentMeta is information that is universal across documents. Ideally
// data in the meta should be indexed and queryable.
type DocumentMeta struct {
Name string `json:"name"`
Type string `json:"type,omitempty"`
Description string `json:"description,omitempty"`
Version string `json:"version,omitempty"`
CRUDLog
}
// DocumentStore is used to perform CRUD operations on documents. It follows an options
// pattern that allows users to perform actions related to documents in a transactional way.
type DocumentStore interface {
CreateDocument(ctx context.Context, d *Document) error
FindDocument(ctx context.Context, id platform.ID) (*Document, error)
FindDocuments(ctx context.Context, orgID platform.ID) ([]*Document, error)
}