func EscapeID(s string) string
EscapeID escapes a document or database ID to be a safe filename.
func UnescapeID(s string) string
UnescapeID unescapes a filename into a document or database ID.
Attachment represents a file attachment.
type Attachment struct { ContentType string `json:"content_type" yaml:"content_type"` RevPos *int64 `json:"revpos,omitempty" yaml:"revpos,omitempty"` Stub bool `json:"stub,omitempty" yaml:"stub,omitempty"` Follows bool `json:"follows,omitempty" yaml:"follows,omitempty"` Content []byte `json:"data,omitempty" yaml:"content,omitempty"` Size int64 `json:"length" yaml:"size"` Digest string `json:"digest" yaml:"digest"` // contains filtered or unexported fields }
func (a *Attachment) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (a *Attachment) Open() (filesystem.File, error)
Open opens the attachment for reading.
Document is a CouchDB document.
type Document struct { ID string `json:"_id" yaml:"_id"` Revisions Revisions `json:"-" yaml:"-"` // RevsInfo is only used during JSON marshaling when revs_info=true, and // should never be consulted as authoritative. RevsInfo []RevInfo `json:"_revs_info,omitempty" yaml:"-"` // RevHistory is only used during JSON marshaling, when revs=true, and // should never be consulted as authoritative. RevHistory *RevHistory `json:"_revisions,omitempty" yaml:"-"` Options map[string]interface{} `json:"-" yaml:"-"` // contains filtered or unexported fields }
func (d *Document) AddRevision(ctx context.Context, rev *Revision, options driver.Options) (string, error)
AddRevision adds rev to the existing document, according to options, and persists it to disk. The return value is the new revision ID.
func (d *Document) Compact(ctx context.Context) error
Compact cleans up any non-leaf revs, and attempts to consolidate attachments.
func (d *Document) MarshalJSON() ([]byte, error)
MarshalJSON satisfies the json.Marshaler interface.
FS provides filesystem access to a
type FS struct {
// contains filtered or unexported fields
}
func New(dbroot string, fs ...filesystem.Filesystem) *FS
New initializes a new FS instance, anchored at dbroot. If fs is omitted or nil, the default is used.
func (fs *FS) NewDocument(docID string) *Document
NewDocument creates a new document.
func (fs *FS) NewRevision(i interface{}) (*Revision, error)
NewRevision creates a new revision from i, according to opts.
func (fs *FS) OpenDocID(docID string, options driver.Options) (*Document, error)
OpenDocID opens the requested document by ID (without file extension).
func (fs *FS) OpenDocIDOpenRevs(docID string, options driver.Options) ([]*Document, error)
OpenDocIDOpenRevs opens the requested document by ID (without file extension), same as OpenDocID, however, it honors the open_revs option, to potentially return multiple revisions of the same document.
func (fs *FS) ReadSecurity(ctx context.Context, path string) (*driver.Security, error)
ReadSecurity reads the _security.{ext} document from path. If not found, an empty security document is returned.
func (fs *FS) WriteSecurity(ctx context.Context, path string, sec *driver.Security) error
WriteSecurity overwrites the existing _security document, if it exists. If it does not exist, it is created with the .json extension.
RevHistory represents the recent ancestors of a revision.
type RevHistory struct { Start int64 `json:"start" yaml:"start"` IDs []string `json:"ids" yaml:"ids"` }
func (h *RevHistory) AddRevision(rev RevID) *RevHistory
AddRevision returns a new history, with rev added.
func (h *RevHistory) Ancestors() []string
Ancestors returns the full, known revision history, newest first, starting with the current rev.
RevID is a CouchDB document revision identifier.
type RevID struct { Seq int64 Sum string // contains filtered or unexported fields }
func (r *RevID) Changed() bool
Changed returns true if the rev has changed since being read.
func (r RevID) Equal(revid RevID) bool
Equal returns true if rev and revid are equal.
func (r *RevID) IsZero() bool
IsZero returns true if r is uninitialized.
func (r RevID) MarshalText() ([]byte, error)
MarshalText satisfies the encoding.TextMarshaler interface.
func (r RevID) String() string
func (r *RevID) UnmarshalJSON(p []byte) error
UnmarshalJSON satisfies the json.Unmarshaler interface.
func (r *RevID) UnmarshalText(p []byte) error
UnmarshalText satisfies the json.Unmarshaler interface.
RevInfo is revisions information as presented in the _revs_info key.
type RevInfo struct { Rev string `json:"rev"` Status string `json:"status"` }
RevMeta is the metadata stored in reach revision.
type RevMeta struct { Rev RevID `json:"_rev" yaml:"_rev"` Deleted *bool `json:"_deleted,omitempty" yaml:"_deleted,omitempty"` Attachments map[string]*Attachment `json:"_attachments,omitempty" yaml:"_attachments,omitempty"` RevHistory *RevHistory `json:"_revisions,omitempty" yaml:"_revisions,omitempty"` // contains filtered or unexported fields }
Revision is a specific instance of a document.
type Revision struct { RevMeta // Data is the normal payload Data map[string]interface{} `json:"-" yaml:"-"` // contains filtered or unexported fields }
func (r *Revision) AttachmentsIterator() (driver.Attachments, error)
AttachmentsIterator will return a driver.Attachments iterator, if the options permit. If options don't permit, both return values will be nil.
func (r *Revision) Delete(context.Context) error
Delete deletes the revision.
func (r *Revision) MarshalJSON() ([]byte, error)
MarshalJSON satisfies the json.Marshaler interface
func (r *Revision) UnmarshalJSON(p []byte) error
UnmarshalJSON satisfies the json.Unmarshaler interface.
func (r *Revision) UnmarshalYAML(u func(interface{}) error) error
UnmarshalYAML satisfies the yaml.Unmarshaler interface.
Revisions is a sortable list of document revisions.
type Revisions []*Revision
func (r Revisions) Deleted() bool
Deleted returns true if the winning revision is deleted.
func (r Revisions) Len() int
Len returns the number of elements in r.
func (r Revisions) Less(i, j int) bool
func (r Revisions) Swap(i, j int)