Documentation
¶
Overview ¶
Package ds provides a Document store.
Index ¶
- func DocumentPaths(docs []*Document) []string
- func FirstPathComponent(path string) string
- func LastPathComponent(path string) string
- func Path(paths ...interface{}) string
- func PathComponents(path string) []string
- func SetLogger(l Logger)
- func Spew(iter DocumentIterator, opts *SpewOpts) (*bytes.Buffer, error)
- func SpewOut(iter DocumentIterator, opts *SpewOpts, out io.Writer) error
- type Change
- type Changes
- type Collection
- type CollectionIterator
- type ContextLogger
- type Direction
- type Document
- type DocumentIterator
- type DocumentStore
- type DocumentsOpts
- type ErrPathExists
- type LogLevel
- type Logger
- type Mem
- func (m *Mem) ChangeAdd(ctx context.Context, name string, id string, ref string) error
- func (m *Mem) Changes(ctx context.Context, name string, ts time.Time, limit int, direction Direction) ([]*Change, time.Time, error)
- func (m *Mem) Collections(ctx context.Context, parent string) (CollectionIterator, error)
- func (m *Mem) Create(ctx context.Context, path string, b []byte) error
- func (m *Mem) Delete(ctx context.Context, path string) (bool, error)
- func (m *Mem) DeleteAll(ctx context.Context, paths []string) error
- func (m *Mem) Documents(ctx context.Context, parent string, opts *DocumentsOpts) (DocumentIterator, error)
- func (m *Mem) Exists(ctx context.Context, path string) (bool, error)
- func (m *Mem) Get(ctx context.Context, path string) (*Document, error)
- func (m *Mem) GetAll(ctx context.Context, paths []string) ([]*Document, error)
- func (m *Mem) Now() time.Time
- func (m *Mem) Set(ctx context.Context, path string, b []byte) error
- func (m *Mem) SetTimeNow(nowFn func() time.Time)
- func (m *Mem) StopWatching(path string)
- func (m *Mem) StopWatchingAll()
- func (m *Mem) URI() string
- func (m *Mem) Watch(path string, ln WatchLn) error
- type PathType
- type SpewFormat
- type SpewOpts
- type StringSet
- type Watch
- type WatchEvent
- type WatchLn
- type WatchStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FirstPathComponent ¶
FirstPathComponent returns first path component.
func LastPathComponent ¶
LastPathComponent returns last path component.
func Path ¶
func Path(paths ...interface{}) string
Path returns a path string from the specified paths or path components. The components can be strings, values with a String() function.
For example,
Path("a", "b") => "/a/b"
Path("") => "/"
Path("/a/") => "/a"
Path("/a//b") => "/a/b"
func PathComponents ¶
PathComponents returns the components of a path.
Types ¶
type Change ¶
type Change struct {
Path string `json:"path" firestore:"path"`
Timestamp time.Time `json:"ts" firestore:"ts"`
}
Change is used to track changes at a path. If this format changes, you should also change in firestore and other backends that don't directly use this struct on set.
type Changes ¶
type Changes interface {
ChangeAdd(ctx context.Context, name string, id string, ref string) error
Changes(ctx context.Context, name string, from time.Time, limit int, direction Direction) ([]*Change, time.Time, error)
}
Changes describes changes to a path.
type Collection ¶
type Collection struct {
// Path to Document's.
Path string
}
Collection is a location for Document's.
func CollectionsFromIterator ¶
func CollectionsFromIterator(iter CollectionIterator) ([]*Collection, error)
CollectionsFromIterator returns Collection's from CollectionIterator.
type CollectionIterator ¶
type CollectionIterator interface {
// Next collection, or nil.
Next() (*Collection, error)
// Release resources associated with the iterator.
Release()
}
CollectionIterator is an iterator for Collection's.
func NewCollectionIterator ¶
func NewCollectionIterator(cols []*Collection) CollectionIterator
NewCollectionIterator returns an iterator for a Collection slice.
type ContextLogger ¶
type ContextLogger interface {
Debugf(ctx context.Context, format string, args ...interface{})
Infof(ctx context.Context, format string, args ...interface{})
Warningf(ctx context.Context, format string, args ...interface{})
Errorf(ctx context.Context, format string, args ...interface{})
}
ContextLogger interface used in this package with request context.
type Document ¶
type Document struct {
// Path of document.
Path string
// Data ...
Data []byte
// CreatedAt (read only). The time at which the document was created.
CreatedAt time.Time
// UpdatedAt (read only). The time at which the document was last changed.
UpdatedAt time.Time
}
Document is a data at a path with metadata.
func DocumentsFromIterator ¶
func DocumentsFromIterator(iter DocumentIterator) ([]*Document, error)
DocumentsFromIterator returns Document's from DocumentIterator.
func NewDocument ¶
NewDocument creates a datastore document.
type DocumentIterator ¶
type DocumentIterator interface {
// Next document, or nil.
Next() (*Document, error)
// Release resources associated with the iterator.
Release()
}
DocumentIterator is an iterator for Document's.
func NewDocumentIterator ¶
func NewDocumentIterator(docs []*Document) DocumentIterator
NewDocumentIterator returns an iterator for a Document slice.
type DocumentStore ¶
type DocumentStore interface {
// Create data at path.
// ErrPathExists if path already exists.
Create(ctx context.Context, path string, b []byte) error
// Create or set data at path.
Set(ctx context.Context, path string, b []byte) error
// Get path.
// If not found, returns nil.
Get(ctx context.Context, path string) (*Document, error)
// GetAll at paths.
// If a path is not found, it is ignored.
GetAll(ctx context.Context, paths []string) ([]*Document, error)
// Exists, if exists at path.
Exists(ctx context.Context, path string) (bool, error)
// Delete at path.
Delete(ctx context.Context, path string) (bool, error)
// If a path is not found, it is ignored.
DeleteAll(ctx context.Context, paths []string) error
// Documents for Document's.
Documents(ctx context.Context, parent string, opts *DocumentsOpts) (DocumentIterator, error)
// Collections are parents of Document's.
Collections(ctx context.Context, parent string) (CollectionIterator, error)
}
DocumentStore is a place for Document's.
type DocumentsOpts ¶
type DocumentsOpts struct {
// Prefix to filter on.
Prefix string
// Index is offset into number of documents.
Index int
// Limit is number of documents (max) to return.
Limit int
// PathOnly to only include only path in Document (no data).
PathOnly bool
}
DocumentsOpts are options for iterating documents.
type ErrPathExists ¶
type ErrPathExists struct {
Path string
}
ErrPathExists is trying to set value that already exists.
func (ErrPathExists) Error ¶
func (e ErrPathExists) Error() string
type Logger ¶
type Logger interface {
Debugf(format string, args ...interface{})
Infof(format string, args ...interface{})
Warningf(format string, args ...interface{})
Errorf(format string, args ...interface{})
Fatalf(format string, args ...interface{})
}
Logger interface used in this package.
type Mem ¶
Mem is an in memory DocumentStore implementation.
func (*Mem) Changes ¶
func (m *Mem) Changes(ctx context.Context, name string, ts time.Time, limit int, direction Direction) ([]*Change, time.Time, error)
Changes ...
func (*Mem) Collections ¶
Collections ...
func (*Mem) Documents ¶
func (m *Mem) Documents(ctx context.Context, parent string, opts *DocumentsOpts) (DocumentIterator, error)
Documents ...
func (*Mem) SetTimeNow ¶
SetTimeNow to use a custom time.Now.
type PathType ¶
type PathType string
PathType denotes the type of path.
const KeyPathType PathType = "key"
KeyPathType is a path with 2 components, meant for a syncable key/value store, like Firebase or leveldb.
const URLPathType PathType = "url"
URLPathType is a path with more than 2 components for web APIs.
type SpewFormat ¶
type SpewFormat string
SpewFormat is format for Spew.
const ( // SpewFormatDefault ... SpewFormatDefault SpewFormat = "" // SpewFormatTable is in a grid, each entry separated by newlines. SpewFormatTable SpewFormat = "table" // SpewFormatFlat are fields separated by newlines and entries separated by empty lines. SpewFormatFlat SpewFormat = "flat" )
type StringSet ¶
type StringSet struct {
// contains filtered or unexported fields
}
StringSet is a set of strings.
func NewStringSetSplit ¶
NewStringSetSplit creates StringSet for split string.
func NewStringSetWithCapacity ¶
NewStringSetWithCapacity ..
type Watch ¶
type Watch interface {
Watch(path string, ln WatchLn) error
StopWatching(path string)
StopWatchingAll()
}
Watch for changes at path.
type WatchEvent ¶
type WatchEvent struct {
Status WatchStatus
Path string
}
WatchEvent gives updates to watch status and version.
type WatchStatus ¶
type WatchStatus string
WatchStatus is status for watch.
const ( // WatchStatusNone is an known status WatchStatusNone WatchStatus = "" // WatchStatusStarting is a status for when watch is starting WatchStatusStarting WatchStatus = "starting" // WatchStatusStopping is a status for when watch is stopping WatchStatusStopping WatchStatus = "stopping" // WatchStatusData is a status for when data has changed WatchStatusData WatchStatus = "data" )