Documentation ¶
Index ¶
- Variables
- type Counter
- func (c *Counter) Copy() orm.CloneableData
- func (*Counter) Descriptor() ([]byte, []int)
- func (m *Counter) GetCount() int64
- func (m *Counter) GetID() []byte
- func (m *Counter) Marshal() (dAtA []byte, err error)
- func (m *Counter) MarshalTo(dAtA []byte) (int, error)
- func (*Counter) ProtoMessage()
- func (m *Counter) Reset()
- func (c *Counter) SetID(id []byte) error
- func (m *Counter) Size() (n int)
- func (m *Counter) String() string
- func (m *Counter) Unmarshal(dAtA []byte) error
- func (c *Counter) Validate() error
- func (m *Counter) XXX_DiscardUnknown()
- func (m *Counter) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Counter) XXX_Merge(src proto.Message)
- func (m *Counter) XXX_Size() int
- func (m *Counter) XXX_Unmarshal(b []byte) error
- type Model
- type ModelBucket
- type ModelBucketOption
- type ModelIterator
- type ModelSlicePtr
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidLengthCodec = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowCodec = fmt.Errorf("proto: integer overflow") )
Functions ¶
This section is empty.
Types ¶
type Counter ¶
type Counter struct { ID []byte `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` Count int64 `protobuf:"varint,2,opt,name=count,proto3" json:"count,omitempty"` }
Counter could be used for sequence, but mainly just for test
func (*Counter) Copy ¶
func (c *Counter) Copy() orm.CloneableData
Copy produces a new copy to fulfill the Model interface
func (*Counter) Descriptor ¶
func (*Counter) ProtoMessage ¶
func (*Counter) ProtoMessage()
func (*Counter) SetID ¶
SetID is a minimal implementation, useful when the ID is a separate protobuf field
func (*Counter) XXX_DiscardUnknown ¶
func (m *Counter) XXX_DiscardUnknown()
func (*Counter) XXX_Marshal ¶
func (*Counter) XXX_Unmarshal ¶
type Model ¶
type Model interface { weave.Persistent Validate() error Copy() orm.CloneableData GetID() []byte SetID([]byte) error }
Model is implemented by any entity that can be stored using ModelBucket.
This is the same interface as CloneableData. Using the right type names provides an easier to read API.
Model stores both the Key and the Value. GetID/SetID are used to store and access the Key. The ID is always set to nil before serializing and storing the Value.
type ModelBucket ¶
type ModelBucket interface { // One query the database for a single model instance. Lookup is done // by the primary index key. Result is loaded into given destination // model. // This method returns ErrNotFound if the entity does not exist in the // database. // If given model type cannot be used to contain stored entity, ErrType // is returned. One(db weave.ReadOnlyKVStore, key []byte, dest Model) error // PrefixScan will scan for all models with a primary key (ID) // that begins with the given prefix. // The function returns a (possibly empty) iterator, which can // load each model as it arrives. // If reverse is true, iterates in descending order (highest value first), // otherwise, it iterates in PrefixScan(db weave.ReadOnlyKVStore, prefix []byte, reverse bool) (ModelIterator, error) // ByIndex returns all objects that secondary index with given name and // given key. Main index is always unique but secondary indexes can // return more than one value for the same key. // All matching entities are appended to given destination slice. If no // result was found, no error is returned and destination slice is not // modified. ByIndex(db weave.ReadOnlyKVStore, indexName string, key []byte, dest ModelSlicePtr) error // IndexScan does a PrefixScan, but on the named index. This would let us eg. load all counters // in order of their count. Or easily find the lowest or highest count. IndexScan(db weave.ReadOnlyKVStore, indexName string, prefix []byte, reverse bool) (ModelIterator, error) // Put saves given model in the database. Before inserting into // database, model is validated using its Validate method. // If the key is nil or zero length then a sequence generator is used // to create a unique key value. // Using a key that already exists in the database cause the value to // be overwritten. Put(db weave.KVStore, m Model) error // Delete removes an entity with given primary key from the database. // It returns ErrNotFound if an entity with given key does not exist. Delete(db weave.KVStore, key []byte) error // Has returns nil if an entity with given primary key value exists. It // returns ErrNotFound if no entity can be found. // Has is a cheap operation that that does not read the data and only // checks the existence of it. Has(db weave.KVStore, key []byte) error // Register registers this buckets content to be accessible via query // requests under the given name. Register(name string, r weave.QueryRouter) }
ModelBucket is implemented by buckets that operates on Models rather than Objects.
func NewModelBucket ¶
func NewModelBucket(name string, m Model, opts ...ModelBucketOption) ModelBucket
NewModelBucket returns a ModelBucket instance. This implementation relies on a bucket instance. Final implementation should operate directly on the KVStore instead.
type ModelBucketOption ¶
type ModelBucketOption func(mb *modelBucket)
ModelBucketOption is implemented by any function that can configure ModelBucket during creation.
func WithIndex ¶
func WithIndex(name string, indexer orm.Indexer, unique bool) ModelBucketOption
WithIndex configures the bucket to build an index with given name. All entities stored in the bucket are indexed using value returned by the indexer function. If an index is unique, there can be only one entity referenced per index value.
type ModelIterator ¶
type ModelSlicePtr ¶
type ModelSlicePtr interface{}
ModelSlicePtr represents a pointer to a slice of models. Think of it as *[]Model Because of Go type system, using []Model would not work for us. Instead we use a placeholder type and the validation is done during the runtime.