Documentation
¶
Overview ¶
Package ds is the cloud datastore helper function
Index ¶
- Variables
- func BuildIDKeys(kind string, ids []int64) []*datastore.Key
- func BuildNameKeys(kind string, names []string) []*datastore.Key
- func BuildStringIDKeys(kind string, ids []string) []*datastore.Key
- func ExtractKey(src interface{}) *datastore.Key
- func ExtractKeys(src interface{}) []*datastore.Key
- func FieldMismatch(err error) bool
- func Ignore(err error, f func(error) bool) error
- func IgnoreFieldMismatch(err error) error
- func IgnoreNotFound(err error) error
- func NotFound(err error) bool
- func SetCommitKey(commit *datastore.Commit, pendingKey *datastore.PendingKey, dst interface{})
- func SetCommitKeys(commit *datastore.Commit, pendingKeys []*datastore.PendingKey, dst interface{})
- func SetID(kind string, id int64, dst interface{})
- func SetIDs(kind string, ids []int64, dst interface{})
- func SetKey(key *datastore.Key, dst interface{})
- func SetKeys(keys []*datastore.Key, dst interface{})
- func SetNameIDs(kind string, names []string, dst interface{})
- func SetStringID(kind string, id string, dst interface{})
- func SetStringIDs(kind string, ids []string, dst interface{})
- type Cache
- type Client
- func (client *Client) AllocateIDModel(ctx context.Context, kind string, src interface{}) error
- func (client *Client) AllocateIDModels(ctx context.Context, kind string, src interface{}) error
- func (client *Client) DeleteByID(ctx context.Context, kind string, id int64) error
- func (client *Client) DeleteByIDs(ctx context.Context, kind string, ids []int64) error
- func (client *Client) DeleteByKey(ctx context.Context, key *datastore.Key) error
- func (client *Client) DeleteByKeys(ctx context.Context, keys []*datastore.Key) error
- func (client *Client) DeleteByName(ctx context.Context, kind string, name string) error
- func (client *Client) DeleteByNames(ctx context.Context, kind string, names []string) error
- func (client *Client) DeleteByStringID(ctx context.Context, kind string, id string) error
- func (client *Client) DeleteByStringIDs(ctx context.Context, kind string, ids []string) error
- func (client *Client) DeleteModel(ctx context.Context, src interface{}) error
- func (client *Client) DeleteModels(ctx context.Context, src interface{}) error
- func (client *Client) GetByID(ctx context.Context, kind string, id int64, dst interface{}) error
- func (client *Client) GetByIDs(ctx context.Context, kind string, ids []int64, dst interface{}) error
- func (client *Client) GetByKey(ctx context.Context, key *datastore.Key, dst interface{}) error
- func (client *Client) GetByKeys(ctx context.Context, keys []*datastore.Key, dst interface{}) error
- func (client *Client) GetByModel(ctx context.Context, dst interface{}) error
- func (client *Client) GetByModels(ctx context.Context, dst interface{}) error
- func (client *Client) GetByName(ctx context.Context, kind string, name string, dst interface{}) error
- func (client *Client) GetByNames(ctx context.Context, kind string, names []string, dst interface{}) error
- func (client *Client) GetByQuery(ctx context.Context, q *datastore.Query, dst interface{}) error
- func (client *Client) GetByStringID(ctx context.Context, kind string, id string, dst interface{}) error
- func (client *Client) GetByStringIDs(ctx context.Context, kind string, ids []string, dst interface{}) error
- func (client *Client) PutModel(ctx context.Context, src interface{}) error
- func (client *Client) PutModels(ctx context.Context, src interface{}) error
- func (client *Client) Query(ctx context.Context, kind string, dst interface{}, qs ...Query) error
- func (client *Client) QueryCount(ctx context.Context, kind string, qs ...Query) (int, error)
- func (client *Client) QueryFirst(ctx context.Context, kind string, dst interface{}, qs ...Query) error
- func (client *Client) QueryKeys(ctx context.Context, kind string, qs ...Query) ([]*datastore.Key, error)
- func (client *Client) RunInTx(ctx context.Context, f func(tx *Tx) error, opts ...datastore.TransactionOption) (*datastore.Commit, error)
- func (client *Client) SaveModel(ctx context.Context, src interface{}) error
- func (client *Client) SaveModels(ctx context.Context, src interface{}) error
- type KeyGetSetter
- type KeyGetter
- type KeyNewer
- type KeySetter
- type Model
- type Query
- func Ancestor(ancestor *datastore.Key) Query
- func CreateAfter(t time.Time, equals bool) Query
- func CreateBefore(t time.Time, equals bool) Query
- func Distinct() Query
- func DistinctOn(fieldNames ...string) Query
- func EventualConsistency() Query
- func Filter(filterStr string, value interface{}) Query
- func Limit(limit int) Query
- func Namespace(ns string) Query
- func Offset(offset int) Query
- func Order(fieldName string) Query
- func Project(fieldNames ...string) Query
- func Transaction(t *Tx) Query
- func UpdateAfter(t time.Time, equals bool) Query
- func UpdateBefore(t time.Time, equals bool) Query
- type StampModel
- type Stampable
- type StringIDModel
- func (x *StringIDModel) GetKey() *datastore.Key
- func (x *StringIDModel) ID() string
- func (x *StringIDModel) NewIncomplateKey(kind string, parent *datastore.Key)
- func (x *StringIDModel) SetID(kind string, id int64)
- func (x *StringIDModel) SetKey(key *datastore.Key)
- func (x *StringIDModel) SetNameID(kind string, name string)
- func (x *StringIDModel) SetStringID(kind string, id string)
- type Tx
- func (tx *Tx) DeleteByKey(key *datastore.Key) error
- func (tx *Tx) DeleteByKeys(keys []*datastore.Key) error
- func (tx *Tx) GetByID(kind string, id int64, dst interface{}) error
- func (tx *Tx) GetByIDs(kind string, ids []int64, dst interface{}) error
- func (tx *Tx) GetByKey(key *datastore.Key, dst interface{}) error
- func (tx *Tx) GetByKeys(keys []*datastore.Key, dst interface{}) error
- func (tx *Tx) GetByModel(dst interface{}) error
- func (tx *Tx) GetByModels(dst interface{}) error
- func (tx *Tx) GetByName(kind string, name string, dst interface{}) error
- func (tx *Tx) GetByNames(kind string, names []string, dst interface{}) error
- func (tx *Tx) GetByStringID(kind string, id string, dst interface{}) error
- func (tx *Tx) GetByStringIDs(kind string, ids []string, dst interface{}) error
- func (tx *Tx) PutModel(src interface{}) (*datastore.PendingKey, error)
- func (tx *Tx) PutModels(src interface{}) ([]*datastore.PendingKey, error)
- func (tx *Tx) SaveModel(src interface{}) (*datastore.PendingKey, error)
- func (tx *Tx) SaveModels(src interface{}) ([]*datastore.PendingKey, error)
Constants ¶
This section is empty.
Variables ¶
var (
ErrCacheNotFound = errors.New("ds: cache not found")
)
Errors
Functions ¶
func BuildIDKeys ¶
BuildIDKeys builds datastore keys from id keys
func BuildNameKeys ¶
BuildNameKeys builds datastore keys from name keys
func BuildStringIDKeys ¶
BuildStringIDKeys builds datastore keys from string id keys
func ExtractKeys ¶
ExtractKeys returns keys from models
func FieldMismatch ¶
FieldMismatch checks is error field mismatch
func IgnoreFieldMismatch ¶
IgnoreFieldMismatch returns nil if err is field mismatch error(s)
func IgnoreNotFound ¶
IgnoreNotFound returns nil if err is not found error(s)
func SetCommitKey ¶
func SetCommitKey(commit *datastore.Commit, pendingKey *datastore.PendingKey, dst interface{})
SetCommitKey sets commit pending key to model
func SetCommitKeys ¶
func SetCommitKeys(commit *datastore.Commit, pendingKeys []*datastore.PendingKey, dst interface{})
SetCommitKeys sets commit pending keys to models
func SetNameIDs ¶
SetNameIDs sets name id to models
func SetStringID ¶
SetStringID sets string id to model
func SetStringIDs ¶
SetStringIDs sets string id to models
Types ¶
type Cache ¶
type Cache interface { Get(*datastore.Key, interface{}) error GetMulti([]*datastore.Key, interface{}) error Set(*datastore.Key, interface{}) error SetMulti([]*datastore.Key, interface{}) error Del(*datastore.Key) error DelMulti([]*datastore.Key) error }
Cache interface
type Client ¶
Client type
func (*Client) AllocateIDModel ¶
AllocateIDModel allocates id for model
func (*Client) AllocateIDModels ¶
AllocateIDModels allocates id for models
func (*Client) DeleteByID ¶
DeleteByID deletes data from datastore by IDKey
func (*Client) DeleteByIDs ¶
DeleteByIDs deletes data from datastore by IDKeys
func (*Client) DeleteByKey ¶
DeleteByKey deletes data from datastore by key
func (*Client) DeleteByKeys ¶
DeleteByKeys deletes data from datastore by keys
func (*Client) DeleteByName ¶
DeleteByName deletes data from datastore by NameKey
func (*Client) DeleteByNames ¶
DeleteByNames deletes data from datastore by NameKeys
func (*Client) DeleteByStringID ¶
DeleteByStringID deletes data from datastore by IDKey
func (*Client) DeleteByStringIDs ¶
DeleteByStringIDs deletes data from datastore by IDKeys
func (*Client) DeleteModel ¶
DeleteModel deletes data by get key from model
func (*Client) DeleteModels ¶
DeleteModels deletes data by get keys from models
func (*Client) GetByIDs ¶
func (client *Client) GetByIDs(ctx context.Context, kind string, ids []int64, dst interface{}) error
GetByIDs retrieves models from datastore by ids
func (*Client) GetByModel ¶
GetByModel retrieves model from datastore by key from model
func (*Client) GetByModels ¶
GetByModels retrieves models from datastore by keys from models
func (*Client) GetByName ¶
func (client *Client) GetByName(ctx context.Context, kind string, name string, dst interface{}) error
GetByName retrieves model from datastore by name
func (*Client) GetByNames ¶
func (client *Client) GetByNames(ctx context.Context, kind string, names []string, dst interface{}) error
GetByNames retrieves models from datastore by names
func (*Client) GetByQuery ¶
GetByQuery retrieves model from datastore by datastore query
func (*Client) GetByStringID ¶
func (client *Client) GetByStringID(ctx context.Context, kind string, id string, dst interface{}) error
GetByStringID retrieves model from datastore by string id
func (*Client) GetByStringIDs ¶
func (client *Client) GetByStringIDs(ctx context.Context, kind string, ids []string, dst interface{}) error
GetByStringIDs retrieves models from datastore by string ids
func (*Client) QueryCount ¶
QueryCount counts entity
func (*Client) QueryFirst ¶
func (client *Client) QueryFirst(ctx context.Context, kind string, dst interface{}, qs ...Query) error
QueryFirst run Get to get the first result
func (*Client) QueryKeys ¶
func (client *Client) QueryKeys(ctx context.Context, kind string, qs ...Query) ([]*datastore.Key, error)
QueryKeys queries only key
func (*Client) RunInTx ¶
func (client *Client) RunInTx(ctx context.Context, f func(tx *Tx) error, opts ...datastore.TransactionOption) (*datastore.Commit, error)
RunInTx is the RunInTransaction wrapper
type Model ¶
Model is the base model which id is int64
func (*Model) NewIncomplateKey ¶
NewIncomplateKey sets an incomplete key to model
type Query ¶
Query is the function for set datastore query
func CreateAfter ¶
CreateAfter quries is model created after (or equals) given time
func CreateBefore ¶
CreateBefore quries is model created after (or equals) given time
func EventualConsistency ¶
func EventualConsistency() Query
EventualConsistency adds eventual consistency to query
func UpdateAfter ¶
UpdateAfter queries is model updated after (or equals) given time
type StampModel ¶
StampModel is the stampable model
type StringIDModel ¶
StringIDModel is the base model which id is string but can use both id key and name key
func (*StringIDModel) GetKey ¶
func (x *StringIDModel) GetKey() *datastore.Key
GetKey returns key from model
func (*StringIDModel) NewIncomplateKey ¶
func (x *StringIDModel) NewIncomplateKey(kind string, parent *datastore.Key)
NewIncomplateKey sets an incomplete key to model
func (*StringIDModel) SetID ¶
func (x *StringIDModel) SetID(kind string, id int64)
SetID sets id to model
func (*StringIDModel) SetKey ¶
func (x *StringIDModel) SetKey(key *datastore.Key)
SetKey sets model key to given key if key is not name key, it will use id key
func (*StringIDModel) SetNameID ¶
func (x *StringIDModel) SetNameID(kind string, name string)
SetNameID sets name id to model
func (*StringIDModel) SetStringID ¶
func (x *StringIDModel) SetStringID(kind string, id string)
SetStringID sets string id to model
type Tx ¶
type Tx struct { *datastore.Transaction // contains filtered or unexported fields }
Tx is the datastore transaction wrapper
func (*Tx) DeleteByKey ¶
DeleteByKey deletes a model by key
func (*Tx) DeleteByKeys ¶
DeleteByKeys deletes models by keys
func (*Tx) GetByModel ¶
GetByModel retrieves model from datastore by key from model
func (*Tx) GetByModels ¶
GetByModels retrieves models from datastore by keys from models
func (*Tx) GetByNames ¶
GetByNames retrieves models from datastore by names
func (*Tx) GetByStringID ¶
GetByStringID retrieves model from datastore by string id
func (*Tx) GetByStringIDs ¶
GetByStringIDs retrieves models from datastore by string ids
func (*Tx) PutModel ¶
func (tx *Tx) PutModel(src interface{}) (*datastore.PendingKey, error)
PutModel puts a model to datastore
func (*Tx) PutModels ¶
func (tx *Tx) PutModels(src interface{}) ([]*datastore.PendingKey, error)
PutModels puts models to datastore
func (*Tx) SaveModel ¶
func (tx *Tx) SaveModel(src interface{}) (*datastore.PendingKey, error)
SaveModel saves model to datastore
func (*Tx) SaveModels ¶
func (tx *Tx) SaveModels(src interface{}) ([]*datastore.PendingKey, error)
SaveModels saves models to datastore