...

Package cdb

import "github.com/go-kivik/kivik/v4/x/fsdb/cdb"
Overview
Index
Subdirectories

Overview ▾

Package cdb provides the core CouchDB types.

Index ▾

func EscapeID(s string) string
func UnescapeID(s string) string
type Attachment
    func (a *Attachment) MarshalJSON() ([]byte, error)
    func (a *Attachment) Open() (filesystem.File, error)
type Document
    func (d *Document) AddRevision(ctx context.Context, rev *Revision, options driver.Options) (string, error)
    func (d *Document) Compact(ctx context.Context) error
    func (d *Document) MarshalJSON() ([]byte, error)
type FS
    func New(dbroot string, fs ...filesystem.Filesystem) *FS
    func (fs *FS) NewDocument(docID string) *Document
    func (fs *FS) NewRevision(i interface{}) (*Revision, error)
    func (fs *FS) OpenDocID(docID string, options driver.Options) (*Document, error)
    func (fs *FS) OpenDocIDOpenRevs(docID string, options driver.Options) ([]*Document, error)
    func (fs *FS) ReadSecurity(ctx context.Context, path string) (*driver.Security, error)
    func (fs *FS) WriteSecurity(ctx context.Context, path string, sec *driver.Security) error
type RevHistory
    func (h *RevHistory) AddRevision(rev RevID) *RevHistory
    func (h *RevHistory) Ancestors() []string
type RevID
    func (r *RevID) Changed() bool
    func (r RevID) Equal(revid RevID) bool
    func (r *RevID) IsZero() bool
    func (r RevID) MarshalText() ([]byte, error)
    func (r RevID) String() string
    func (r *RevID) UnmarshalJSON(p []byte) error
    func (r *RevID) UnmarshalText(p []byte) error
type RevInfo
type RevMeta
type Revision
    func (r *Revision) AttachmentsIterator() (driver.Attachments, error)
    func (r *Revision) Delete(context.Context) error
    func (r *Revision) MarshalJSON() ([]byte, error)
    func (r *Revision) UnmarshalJSON(p []byte) error
    func (r *Revision) UnmarshalYAML(u func(interface{}) error) error
type Revisions
    func (r Revisions) Deleted() bool
    func (r Revisions) Len() int
    func (r Revisions) Less(i, j int) bool
    func (r Revisions) Swap(i, j int)

Package files

attachments.go cdb.go constants.go document.go errors.go fs.go revid.go revision.go security.go util.go

func EscapeID

func EscapeID(s string) string

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

func UnescapeID

func UnescapeID(s string) string

UnescapeID unescapes a filename into a document or database ID.

type Attachment

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 (*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

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 (*Document) AddRevision

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 (*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

FS provides filesystem access to a

type FS struct {
    // contains filtered or unexported fields
}

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, options driver.Options) (*Document, error)

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

func (*FS) OpenDocIDOpenRevs

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

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

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.

type RevHistory

RevHistory represents the recent ancestors of a revision.

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

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

RevID is a CouchDB document revision identifier.

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

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 satisfies the json.Unmarshaler interface.

type RevInfo

RevInfo is revisions information as presented in the _revs_info key.

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

type RevMeta

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
}

type Revision

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 (*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(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

Revisions is a sortable list of document revisions.

type Revisions []*Revision

func (Revisions) Deleted

func (r Revisions) Deleted() bool

Deleted returns true if the winning revision is deleted.

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)

Subdirectories

Name Synopsis
..
decode Package decode assists in document decoding.