docstore

package
v0.0.0-...-b178995 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2020 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrIDNotFound = errors.New("ID doest not exist")

Functions

This section is empty.

Types

type Collection

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

Collection represents a collection of documents

func (*Collection) GetID

func (col *Collection) GetID(ctx context.Context, id string, doc interface{}) error

Get retrieve the document, `doc` must a map[string]interface{} or a struct pointer.

func (*Collection) Insert

func (col *Collection) Insert(ctx context.Context, idoc interface{}, opts *InsertOpts) (*ID, error)

func (*Collection) Iter

func (col *Collection) Iter(query *Query, opts *IterOpts) (*Iter, error)

func (*Collection) UpdateID

func (col *Collection) UpdateID(ctx context.Context, id string, doc interface{}) error

Update the whole document

type DocStore

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

func New

func New(client *clientutil.ClientUtil) *DocStore

serverAddr should't have a trailing space

func (*DocStore) Col

func (docstore *DocStore) Col(collection string) *Collection

func (*DocStore) Collections

func (docstore *DocStore) Collections() ([]string, error)

func (*DocStore) DownloadAttachment

func (docstore *DocStore) DownloadAttachment(ref string) (io.Reader, error)

DownloadAttachment returns an `io.ReadCloser` with the file content for the given ref.

func (*DocStore) UploadAttachment

func (docstore *DocStore) UploadAttachment(name string, r io.Reader, data map[string]interface{}) (string, error)

type ID

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

func IDFromHex

func IDFromHex(data string) (*ID, error)

FromHex build an `ID` from an hex encoded string

func (*ID) ETag

func (id *ID) ETag() string

ETag returns the ETag of the current document for future conditional requests

func (*ID) Hash

func (id *ID) Hash() string

Hash returns the hash of the JSON blob

func (*ID) String

func (id *ID) String() string

String implements Stringer interface

func (*ID) Time

func (id *ID) Time() time.Time

Ts returns the timestamp component

type InsertOpts

type InsertOpts struct {
	Indexed bool
}

InsertOpts defines the options for the `Insert` operation TODO(tsileo): use the same opts style as clientutil (...options)

func DefaultInsertOpts

func DefaultInsertOpts() *InsertOpts

DefaultInsertOpts initializes a new `InsertOpts` with sane default

type Iter

type Iter struct {

	// FIXME(tsileo): attch the cursor?
	Opts     *IterOpts // Contains the current `IterOpts`
	LatestID string    // Needed for the subsequent API calls
	// contains filtered or unexported fields
}

func (*Iter) Close

func (iter *Iter) Close() error

func (*Iter) Cursor

func (iter *Iter) Cursor() string

func (*Iter) Err

func (iter *Iter) Err() error

func (*Iter) Next

func (iter *Iter) Next(res interface{}) bool

Next unmarshall the request into the given slice, returns false when there's no more data

type IterOpts

type IterOpts struct {
	Limit int
}

func DefaultIterOtps

func DefaultIterOtps() *IterOpts

type M

type M map[string]interface{}

type Q

type Q map[string]interface{}

Q is a wrapper of `map[string]interface{} for syntactic sugar

type Query

type Query struct {
	Query string

	Script string
}

func (*Query) ToQueryString

func (q *Query) ToQueryString() string

Jump to

Keyboard shortcuts

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