driver

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package driver defines a set of interfaces that the docstore package uses to interact with the underlying services.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UniqueString

func UniqueString() string

UniqueString generates a string that is unique with high probability. Driver implementations can use it to generate keys for Create actions.

Types

type Action

type Action struct {
	Kind       ActionKind // the kind of action
	Doc        Document   // the document on which to perform the action
	FieldPaths [][]string // field paths to retrieve, for Get only
	Mods       []Mod      // modifications to make, for Update only
}

An Action describes a single operation on a single document.

type ActionKind

type ActionKind int

ActionKind describes the type of an action.

const (
	Create ActionKind = iota
	Replace
	Put
	Get
	Delete
	Update
)

type Collection

type Collection interface {
	// RunActions executes a sequence of actions.
	// Implementations are free to execute the actions however they wish, but it must
	// appear as if they were executed in order. The actions need not happen
	// atomically.
	//
	// RunActions should return immediately after the first action that fails.
	// The first return value is the number of actions successfully
	// executed, and the second is the error that caused the action to fail.
	//
	// If all actions succeed, RunActions returns (number of actions, nil).
	RunActions(context.Context, []*Action) (int, error)

	// ErrorCode should return a code that describes the error, which was returned by
	// one of the other methods in this interface.
	ErrorCode(error) gcerr.ErrorCode
}

A Collection is a set of documents.

type Document

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

A Document is a lightweight wrapper around either a map[string]interface{} or a struct pointer. It provides operations to get and set fields and field paths.

func NewDocument

func NewDocument(doc interface{}) (Document, error)

Create a new document from doc, which must be a map[string]interface{} or a struct pointer.

func (Document) Get

func (d Document) Get(fp []string) (interface{}, error)

Get returns the value of the given field path in the document.

func (Document) GetField

func (d Document) GetField(field string) (interface{}, error)

GetField returns the value of the named document field.

func (Document) Map

func (d Document) Map() map[string]interface{}

TODO(jba): remove this method after memdocstore uses the codec framework.

func (Document) Set

func (d Document) Set(fp []string, val interface{}) error

Set sets the value of the field path in the document. This creates sub-maps as necessary, if possible.

func (Document) SetField

func (d Document) SetField(field string, value interface{}) error

SetField sets the field to value in the document.

type Mod

type Mod struct {
	FieldPath []string
	Value     interface{}
}

A Mod is a modification to a field path in a document. At present, the only modifications supported are: - set the value at the field path, or create the field path if it doesn't exist - delete the field path (when Value is nil)

Jump to

Keyboard shortcuts

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