Version: v0.0.3 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2019 License: Apache-2.0 Imports: 21 Imported by: 0



Package cdb provides the core CouchDB types.



This section is empty.


This section is empty.


func EscapeID added in v0.0.3

func EscapeID(s string) string

EscapeID escapes a document or database ID to be a safe filename.

func UnescapeID added in v0.0.3

func UnescapeID(s string) string

UnescapeID unescapes a filename into a document or database ID.


type 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

Attachment represents a file attachment.

func (*Attachment) MarshalJSON

func (a *Attachment) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*Attachment) Open

func (a *Attachment) Open() (filesystem.File, error)

Open opens the attachment for reading.

type Document

type Document struct {
	ID        string    `json:"_id" yaml:"_id"`
	Revisions Revisions `json:"-" yaml:"-"`
	// RevsInfo is only used during JSON marshaling, and should never be
	// consulted as authoritative.
	RevsInfo []RevInfo `json:"_revs_info,omitempty" yaml:"-"`

	Options kivik.Options `json:"-" yaml:"-"`
	// contains filtered or unexported fields

Document is a CouchDB document.

func (*Document) AddRevision

func (d *Document) AddRevision(ctx context.Context, rev *Revision, options kivik.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 (*Document) Compact

func (d *Document) Compact(ctx context.Context) error

Compact cleans up any non-leaf revs, and attempts to consolidate attachments.

func (*Document) MarshalJSON

func (d *Document) MarshalJSON() ([]byte, error)

MarshalJSON satisfies the json.Marshaler interface.

type FS

type FS struct {
	// contains filtered or unexported fields

FS provides filesystem access to a

func New

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) NewDocument

func (fs *FS) NewDocument(docID string) *Document

NewDocument creates a new document.

func (*FS) NewRevision

func (fs *FS) NewRevision(i interface{}) (*Revision, error)

NewRevision creates a new revision from i, according to opts.

func (*FS) OpenDocID

func (fs *FS) OpenDocID(docID string, opts kivik.Options) (*Document, error)

OpenDocID opens the requested document by ID (without file extension).

func (*FS) ReadSecurity

func (fs *FS) ReadSecurity(ctx context.Context, path string) (*driver.Security, error)

ReadSecurity reads the _security.{ext} document from path.

type RevHistory

type RevHistory struct {
	Start int64    `json:"start" yaml:"start"`
	IDs   []string `json:"ids" yaml:"ids"`

RevHistory represents the recent ancestors of a revision.

func (*RevHistory) AddRevision

func (h *RevHistory) AddRevision(rev RevID) *RevHistory

AddRevision returns a new history, with rev added.

func (*RevHistory) Ancestors

func (h *RevHistory) Ancestors() []string

Ancestors returns the full, known revision history, newest first, starting with the current rev.

type RevID

type RevID struct {
	Seq int64
	Sum string
	// contains filtered or unexported fields

RevID is a CouchDB document revision identifier.

func (*RevID) Changed

func (r *RevID) Changed() bool

Changed returns true if the rev has changed since being read.

func (RevID) Equal

func (r RevID) Equal(revid RevID) bool

Equal returns true if rev and revid are equal.

func (*RevID) IsZero

func (r *RevID) IsZero() bool

IsZero returns true if r is uninitialized.

func (RevID) MarshalText

func (r RevID) MarshalText() ([]byte, error)

MarshalText satisfies the encoding.TextMarshaler interface.

func (RevID) String

func (r RevID) String() string

func (*RevID) UnmarshalJSON

func (r *RevID) UnmarshalJSON(p []byte) error

UnmarshalJSON satisfies the json.Unmarshaler interface.

func (*RevID) UnmarshalText

func (r *RevID) UnmarshalText(p []byte) error

UnmarshalText xatisfies the json.Unmarshaler interface.

type RevInfo

type RevInfo struct {
	Rev    string `json:"rev"`
	Status string `json:"status"`

RevInfo is revisions information as presented in the _revs_info key.

type RevMeta

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

RevMeta is the metadata stored in reach revision.

type Revision

type Revision struct {

	// Data is the normal payload
	Data map[string]interface{} `json:"-" yaml:"-"`
	// contains filtered or unexported fields

Revision is a specific instance of a document.

func (*Revision) AttachmentsIterator

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 (*Revision) Delete

func (r *Revision) Delete(ctx context.Context) error

Delete deletes the revision.

func (*Revision) MarshalJSON

func (r *Revision) MarshalJSON() ([]byte, error)

MarshalJSON satisfies the json.Marshaler interface

func (*Revision) UnmarshalJSON

func (r *Revision) UnmarshalJSON(p []byte) error

UnmarshalJSON satisfies the json.Unmarshaler interface.

func (*Revision) UnmarshalYAML

func (r *Revision) UnmarshalYAML(u func(interface{}) error) error

UnmarshalYAML satisfies the yaml.Unmarshaler interface.

type Revisions

type Revisions []*Revision

Revisions is a sortable list of document revisions.

func (Revisions) Len

func (r Revisions) Len() int

Len returns the number of elements in r.

func (Revisions) Less

func (r Revisions) Less(i, j int) bool

func (Revisions) Swap

func (r Revisions) Swap(i, j int)


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL