Documentation
¶
Index ¶
- Variables
- func MarshalPropertyList(pl datastore.PropertyList) ([]byte, error)
- func NewCloudStore(client *datastore.Client) *cloudStore
- func UnmarshalPropertyList(data []byte, pl *datastore.PropertyList) error
- type Cache
- type Client
- func (c *Client) Cacher() Cache
- func (c *Client) Close() error
- func (c *Client) Delete(ctx context.Context, key *datastore.Key) error
- func (c *Client) DeleteMulti(ctx context.Context, keys []*datastore.Key) error
- func (c *Client) Get(ctx context.Context, key *datastore.Key, val interface{}) error
- func (c *Client) GetMulti(ctx context.Context, keys []*datastore.Key, vals interface{}) error
- func (c *Client) Mutate(ctx context.Context, muts ...*Mutation) ([]*datastore.Key, error)
- func (c *Client) NewTransaction(ctx context.Context, opts ...datastore.TransactionOption) (*Transaction, error)
- func (c *Client) Put(ctx context.Context, key *datastore.Key, val interface{}) (*datastore.Key, error)
- func (c *Client) PutMulti(ctx context.Context, keys []*datastore.Key, vals interface{}) ([]*datastore.Key, error)
- func (c *Client) RunInTransaction(ctx context.Context, f func(tx *Transaction) error, ...) (cmt *datastore.Commit, err error)
- type ClientOption
- type CloudAccess
- type Filter
- type Item
- type Iterator
- type LocalAccess
- type MultiError
- type Mutation
- type Mutator
- type OnErrorFunc
- type Order
- type Query
- type Store
- type Transaction
- func (t *Transaction) Commit() (*datastore.Commit, error)
- func (t *Transaction) Delete(key *datastore.Key) error
- func (t *Transaction) DeleteMulti(keys []*datastore.Key) (err error)
- func (t *Transaction) Get(key *datastore.Key, dst interface{}) error
- func (t *Transaction) GetMulti(keys []*datastore.Key, dst interface{}) error
- func (t *Transaction) Mutate(muts ...*Mutation) ([]*datastore.PendingKey, error)
- func (t *Transaction) Put(key *datastore.Key, src interface{}) (*datastore.PendingKey, error)
- func (t *Transaction) PutMulti(keys []*datastore.Key, src interface{}) (ret []*datastore.PendingKey, err error)
- func (t *Transaction) Rollback() (err error)
- type TransactionMutator
- type TransactionStore
Constants ¶
This section is empty.
Variables ¶
var ( ErrCacheMiss = errors.New("dsorm: cache miss") ErrCASConflict = errors.New("dsorm: cas conflict") ErrNotStored = errors.New("dsorm: not stored") )
var (
// Tag Keys
KeyKind, _ = tag.NewKey("kind")
// Views
AllViews = []*view.View{
{
Name: "dsorm/cache_hit",
Description: "Cache hits",
Measure: mCacheHit,
Aggregation: view.Sum(),
TagKeys: []tag.Key{KeyKind},
},
{
Name: "dsorm/cache_miss",
Description: "Cache misses",
Measure: mCacheMiss,
Aggregation: view.Sum(),
TagKeys: []tag.Key{KeyKind},
},
}
)
Functions ¶
func MarshalPropertyList ¶
func MarshalPropertyList(pl datastore.PropertyList) ([]byte, error)
func NewCloudStore ¶
NewCloudStore wraps a datastore.Client
func UnmarshalPropertyList ¶
func UnmarshalPropertyList(data []byte, pl *datastore.PropertyList) error
Types ¶
type Cache ¶
type Cache interface {
// AddMulti adds items if keys are not in use. Returns ErrNotStored on conflict.
AddMulti(ctx context.Context, items []*Item) error
// CompareAndSwapMulti updates items if unchanged since Get. Returns ErrCASConflict or ErrNotStored.
CompareAndSwapMulti(ctx context.Context, items []*Item) error
// DeleteMulti removes keys.
DeleteMulti(ctx context.Context, keys []string) error
// GetMulti fetches keys. Returns map of found items. No error on miss.
GetMulti(ctx context.Context, keys []string) (map[string]*Item, error)
// SetMulti sets items blindly. Returns error per item on failure.
SetMulti(ctx context.Context, items []*Item) error
// Increment atomically increments a key's integer value by delta.
// Returns the new value after incrementing. Creates the key with
// value=delta and the given expiration if the key does not exist.
Increment(ctx context.Context, key string, delta int64, expiration time.Duration) (int64, error)
}
Cache interface for backend storage.
type Client ¶
type Client struct {
Store
// contains filtered or unexported fields
}
func (*Client) DeleteMulti ¶
DeleteMulti deletes multiple entities. - Batches requests (limit 500). - Manages cache locks directly.
func (*Client) GetMulti ¶
GetMulti retrieves entities by keys. - Batches requests (limit 1000). - Uses cache transparently. - Falls back to datastore on cache miss/fail.
func (*Client) Mutate ¶
Mutate applies mutations. - Locks affecting keys in cache. - Invalidates cache on success.
func (*Client) NewTransaction ¶
func (c *Client) NewTransaction(ctx context.Context, opts ...datastore.TransactionOption) (*Transaction, error)
NewTransaction starts a transaction with cache-aware context.
func (*Client) Put ¶
func (c *Client) Put(ctx context.Context, key *datastore.Key, val interface{}) (*datastore.Key, error)
Put saves an entity.
func (*Client) PutMulti ¶
func (c *Client) PutMulti(ctx context.Context, keys []*datastore.Key, vals interface{}) ([]*datastore.Key, error)
PutMulti saves entities. - Batches requests (limit 500). - Invalidates/Updates cache locks.
func (*Client) RunInTransaction ¶
func (c *Client) RunInTransaction(ctx context.Context, f func(tx *Transaction) error, opts ...datastore.TransactionOption) (cmt *datastore.Commit, err error)
RunInTransaction wrapper ensuring cache interaction.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption option for dsorm Client.
func WithCachePrefix ¶
func WithCachePrefix(prefix string) ClientOption
func WithDatastoreClient ¶
func WithDatastoreClient(ds *datastore.Client) ClientOption
func WithOnErrorFunc ¶
func WithOnErrorFunc(f OnErrorFunc) ClientOption
WithOnErrorFunc sets an error handler for internal non-fatal errors.
func WithStore ¶
func WithStore(s Store) ClientOption
type CloudAccess ¶
CloudAccess is an optional interface that cloud-backed Store implementations can implement to expose the underlying *datastore.Client:
if ca, ok := store.(CloudAccess); ok {
dsClient := ca.DatastoreClient()
}
type Item ¶
type Item struct {
Key string
Value []byte
Flags uint32
Expiration time.Duration
// contains filtered or unexported fields
}
Item cache entry.
func (*Item) SetCASInfo ¶
func (i *Item) SetCASInfo(value interface{})
SetCASInfo sets opaque CAS value once.
type LocalAccess ¶
LocalAccess is an optional interface that local Store implementations can implement to expose the underlying *sql.DB for a given namespace:
if la, ok := store.(LocalAccess); ok {
db, err := la.DB("")
}
type MultiError ¶
type MultiError []error
MultiError maps errors to input elements.
func (MultiError) Error ¶
func (m MultiError) Error() string
type Mutation ¶
type Mutation struct {
// contains filtered or unexported fields
}
Mutation represents a datastore mutation.
type Mutator ¶
type Mutator interface {
Mutate(ctx context.Context, muts ...*datastore.Mutation) ([]*datastore.Key, error)
}
Mutator is an optional interface for stores that support datastore mutations.
type OnErrorFunc ¶
type Query ¶
type Query interface {
Kind() string
Filters() []Filter
Orders() []Order
GetLimit() int
GetOffset() int
IsKeysOnly() bool
GetAncestor() *datastore.Key
GetCursor() string
GetNamespace() string
}
Query defines the methods required for a backend to translate a generic dsorm query.
type Store ¶
type Store interface {
Get(ctx context.Context, key *datastore.Key, dst interface{}) error
GetMulti(ctx context.Context, keys []*datastore.Key, dst interface{}) error
Put(ctx context.Context, key *datastore.Key, src interface{}) (*datastore.Key, error)
PutMulti(ctx context.Context, keys []*datastore.Key, src interface{}) ([]*datastore.Key, error)
Delete(ctx context.Context, key *datastore.Key) error
DeleteMulti(ctx context.Context, keys []*datastore.Key) error
Run(ctx context.Context, q Query) Iterator
NewTransaction(ctx context.Context, opts ...datastore.TransactionOption) (TransactionStore, error)
RunInTransaction(ctx context.Context, f func(tx TransactionStore) error, opts ...datastore.TransactionOption) (*datastore.Commit, error)
Close() error
}
Store is the interface that abstracts the underlying datastore. It allows replacing Google Cloud Datastore with implementations like LocalDB.
type Transaction ¶
Transaction wraps ds.TransactionStore with caching.
func (*Transaction) Commit ¶
func (t *Transaction) Commit() (*datastore.Commit, error)
Commit commits cache changes then TX.
func (*Transaction) DeleteMulti ¶
func (t *Transaction) DeleteMulti(keys []*datastore.Key) (err error)
DeleteMulti batch delete. Locks keys.
func (*Transaction) GetMulti ¶
func (t *Transaction) GetMulti(keys []*datastore.Key, dst interface{}) error
GetMulti batch get. Bypasses cache in TX.
func (*Transaction) Mutate ¶
func (t *Transaction) Mutate(muts ...*Mutation) ([]*datastore.PendingKey, error)
Mutate locks keys from mutations.
func (*Transaction) Put ¶
func (t *Transaction) Put(key *datastore.Key, src interface{}) (*datastore.PendingKey, error)
func (*Transaction) PutMulti ¶
func (t *Transaction) PutMulti(keys []*datastore.Key, src interface{}) (ret []*datastore.PendingKey, err error)
PutMulti batch put. Locks keys.
func (*Transaction) Rollback ¶
func (t *Transaction) Rollback() (err error)
Rollback passes through to TX.
type TransactionMutator ¶
type TransactionMutator interface {
Mutate(muts ...*datastore.Mutation) ([]*datastore.PendingKey, error)
}
TransactionMutator is an optional interface for transaction stores that support mutations.
type TransactionStore ¶
type TransactionStore interface {
Get(key *datastore.Key, dst interface{}) error
GetMulti(keys []*datastore.Key, dst interface{}) error
Put(key *datastore.Key, src interface{}) (*datastore.PendingKey, error)
PutMulti(keys []*datastore.Key, src interface{}) ([]*datastore.PendingKey, error)
Delete(key *datastore.Key) error
DeleteMulti(keys []*datastore.Key) error
Commit() (*datastore.Commit, error)
Rollback() error
}
TransactionStore abstracts datastore.Transaction