ds

package module
v0.0.0-...-8083dd1 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2017 License: MIT Imports: 8 Imported by: 0

README

ds

Build Status Coverage Status Go Report Card GoDoc

Google Cloud Datastore helper library for Golang

Supports Go 1.7+

See godoc for more detail

Documentation

Overview

Package ds is the cloud datastore helper function

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCacheNotFound = errors.New("ds: cache not found")
)

Errors

Functions

func BuildIDKeys

func BuildIDKeys(kind string, ids []int64) []*datastore.Key

BuildIDKeys builds datastore keys from id keys

func BuildNameKeys

func BuildNameKeys(kind string, names []string) []*datastore.Key

BuildNameKeys builds datastore keys from name keys

func BuildStringIDKeys

func BuildStringIDKeys(kind string, ids []string) []*datastore.Key

BuildStringIDKeys builds datastore keys from string id keys

func ExtractKey

func ExtractKey(src interface{}) *datastore.Key

ExtractKey returns key from model

func ExtractKeys

func ExtractKeys(src interface{}) []*datastore.Key

ExtractKeys returns keys from models

func FieldMismatch

func FieldMismatch(err error) bool

FieldMismatch checks is error field mismatch

func Ignore

func Ignore(err error, f func(error) bool) error

Ignore removes error(s) from err if f(err)

func IgnoreFieldMismatch

func IgnoreFieldMismatch(err error) error

IgnoreFieldMismatch returns nil if err is field mismatch error(s)

func IgnoreNotFound

func IgnoreNotFound(err error) error

IgnoreNotFound returns nil if err is not found error(s)

func NotFound

func NotFound(err error) bool

NotFound checks is error means not found

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 SetID

func SetID(kind string, id int64, dst interface{})

SetID sets id to model

func SetIDs

func SetIDs(kind string, ids []int64, dst interface{})

SetIDs sets ids to models

func SetKey

func SetKey(key *datastore.Key, dst interface{})

SetKey sets key to model

func SetKeys

func SetKeys(keys []*datastore.Key, dst interface{})

SetKeys sets keys to models

func SetNameIDs

func SetNameIDs(kind string, names []string, dst interface{})

SetNameIDs sets name id to models

func SetStringID

func SetStringID(kind string, id string, dst interface{})

SetStringID sets string id to model

func SetStringIDs

func SetStringIDs(kind string, ids []string, dst interface{})

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

type Client struct {
	*datastore.Client
	Cache Cache
}

Client type

func NewClient

func NewClient(ctx context.Context, projectID string, opts ...option.ClientOption) (*Client, error)

NewClient creates new ds client which wrap datastore client

func (*Client) AllocateIDModel

func (client *Client) AllocateIDModel(ctx context.Context, kind string, src interface{}) error

AllocateIDModel allocates id for model

func (*Client) AllocateIDModels

func (client *Client) AllocateIDModels(ctx context.Context, kind string, src interface{}) error

AllocateIDModels allocates id for models

func (*Client) DeleteByID

func (client *Client) DeleteByID(ctx context.Context, kind string, id int64) error

DeleteByID deletes data from datastore by IDKey

func (*Client) DeleteByIDs

func (client *Client) DeleteByIDs(ctx context.Context, kind string, ids []int64) error

DeleteByIDs deletes data from datastore by IDKeys

func (*Client) DeleteByKey

func (client *Client) DeleteByKey(ctx context.Context, key *datastore.Key) error

DeleteByKey deletes data from datastore by key

func (*Client) DeleteByKeys

func (client *Client) DeleteByKeys(ctx context.Context, keys []*datastore.Key) error

DeleteByKeys deletes data from datastore by keys

func (*Client) DeleteByName

func (client *Client) DeleteByName(ctx context.Context, kind string, name string) error

DeleteByName deletes data from datastore by NameKey

func (*Client) DeleteByNames

func (client *Client) DeleteByNames(ctx context.Context, kind string, names []string) error

DeleteByNames deletes data from datastore by NameKeys

func (*Client) DeleteByStringID

func (client *Client) DeleteByStringID(ctx context.Context, kind string, id string) error

DeleteByStringID deletes data from datastore by IDKey

func (*Client) DeleteByStringIDs

func (client *Client) DeleteByStringIDs(ctx context.Context, kind string, ids []string) error

DeleteByStringIDs deletes data from datastore by IDKeys

func (*Client) DeleteModel

func (client *Client) DeleteModel(ctx context.Context, src interface{}) error

DeleteModel deletes data by get key from model

func (*Client) DeleteModels

func (client *Client) DeleteModels(ctx context.Context, src interface{}) error

DeleteModels deletes data by get keys from models

func (*Client) GetByID

func (client *Client) GetByID(ctx context.Context, kind string, id int64, dst interface{}) error

GetByID retrieves model from datastore by id

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) GetByKey

func (client *Client) GetByKey(ctx context.Context, key *datastore.Key, dst interface{}) error

GetByKey retrieves model from datastore by key

func (*Client) GetByKeys

func (client *Client) GetByKeys(ctx context.Context, keys []*datastore.Key, dst interface{}) error

GetByKeys retrieves models from datastore by keys

func (*Client) GetByModel

func (client *Client) GetByModel(ctx context.Context, dst interface{}) error

GetByModel retrieves model from datastore by key from model

func (*Client) GetByModels

func (client *Client) GetByModels(ctx context.Context, dst interface{}) error

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

func (client *Client) GetByQuery(ctx context.Context, q *datastore.Query, dst interface{}) error

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) PutModel

func (client *Client) PutModel(ctx context.Context, src interface{}) error

PutModel puts a model to datastore

func (*Client) PutModels

func (client *Client) PutModels(ctx context.Context, src interface{}) error

PutModels puts models to datastore

func (*Client) Query

func (client *Client) Query(ctx context.Context, kind string, dst interface{}, qs ...Query) error

Query run Get All dst is *[]*Model

func (*Client) QueryCount

func (client *Client) QueryCount(ctx context.Context, kind string, qs ...Query) (int, error)

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

func (*Client) SaveModel

func (client *Client) SaveModel(ctx context.Context, src interface{}) error

SaveModel saves model to datastore if key was not set in model, will call NewKey

func (*Client) SaveModels

func (client *Client) SaveModels(ctx context.Context, src interface{}) error

SaveModels saves models to datastore see more in SaveModel

type KeyGetSetter

type KeyGetSetter interface {
	KeyGetter
	KeySetter
}

KeyGetSetter interface

type KeyGetter

type KeyGetter interface {
	GetKey() *datastore.Key
}

KeyGetter interface

type KeyNewer

type KeyNewer interface {
	NewKey()
}

KeyNewer interface

type KeySetter

type KeySetter interface {
	SetKey(*datastore.Key)
}

KeySetter interface

type Model

type Model struct {
	Key *datastore.Key `datastore:"__key__"`
}

Model is the base model which id is int64

func (*Model) GetKey

func (x *Model) GetKey() *datastore.Key

GetKey returns key from model

func (*Model) ID

func (x *Model) ID() int64

ID returns id

func (*Model) NewIncomplateKey

func (x *Model) NewIncomplateKey(kind string, parent *datastore.Key)

NewIncomplateKey sets an incomplete key to model

func (*Model) SetID

func (x *Model) SetID(kind string, id int64)

SetID sets id key to model

func (*Model) SetKey

func (x *Model) SetKey(key *datastore.Key)

SetKey sets model key to given key

func (*Model) StringID

func (x *Model) StringID() string

StringID return id in string format

type Query

type Query func(q *datastore.Query) *datastore.Query

Query is the function for set datastore query

func Ancestor

func Ancestor(ancestor *datastore.Key) Query

Ancestor adds ancestor to query

func CreateAfter

func CreateAfter(t time.Time, equals bool) Query

CreateAfter quries is model created after (or equals) given time

func CreateBefore

func CreateBefore(t time.Time, equals bool) Query

CreateBefore quries is model created after (or equals) given time

func Distinct

func Distinct() Query

Distinct adds distinct to query

func DistinctOn

func DistinctOn(fieldNames ...string) Query

DistinctOn adds distinct on to query

func EventualConsistency

func EventualConsistency() Query

EventualConsistency adds eventual consistency to query

func Filter

func Filter(filterStr string, value interface{}) Query

Filter func

func Limit

func Limit(limit int) Query

Limit adds limit to query

func Namespace

func Namespace(ns string) Query

Namespace adds namespace to query

func Offset

func Offset(offset int) Query

Offset adds offset to query

func Order

func Order(fieldName string) Query

Order adds order to query

func Project

func Project(fieldNames ...string) Query

Project adds order to query

func Transaction

func Transaction(t *Tx) Query

Transaction adds transaction to query

func UpdateAfter

func UpdateAfter(t time.Time, equals bool) Query

UpdateAfter queries is model updated after (or equals) given time

func UpdateBefore

func UpdateBefore(t time.Time, equals bool) Query

UpdateBefore queries is model updated before (or equals) given time

type StampModel

type StampModel struct {
	CreatedAt time.Time
	UpdatedAt time.Time
}

StampModel is the stampable model

func (*StampModel) Stamp

func (x *StampModel) Stamp()

Stamp stamps current time to model

type Stampable

type Stampable interface {
	Stamp()
}

Stampable interface

type StringIDModel

type StringIDModel struct {
	Key *datastore.Key `datastore:"__key__"`
}

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) ID

func (x *StringIDModel) ID() string

ID return id

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

func (tx *Tx) DeleteByKey(key *datastore.Key) error

DeleteByKey deletes a model by key

func (*Tx) DeleteByKeys

func (tx *Tx) DeleteByKeys(keys []*datastore.Key) error

DeleteByKeys deletes models by keys

func (*Tx) GetByID

func (tx *Tx) GetByID(kind string, id int64, dst interface{}) error

GetByID retrieves model from datastore by id

func (*Tx) GetByIDs

func (tx *Tx) GetByIDs(kind string, ids []int64, dst interface{}) error

GetByIDs retrieves models from datastore by ids

func (*Tx) GetByKey

func (tx *Tx) GetByKey(key *datastore.Key, dst interface{}) error

GetByKey retrieves model from datastore by key

func (*Tx) GetByKeys

func (tx *Tx) GetByKeys(keys []*datastore.Key, dst interface{}) error

GetByKeys retrieves models from datastore by keys

func (*Tx) GetByModel

func (tx *Tx) GetByModel(dst interface{}) error

GetByModel retrieves model from datastore by key from model

func (*Tx) GetByModels

func (tx *Tx) GetByModels(dst interface{}) error

GetByModels retrieves models from datastore by keys from models

func (*Tx) GetByName

func (tx *Tx) GetByName(kind string, name string, dst interface{}) error

GetByName retrieves model from datastore by name

func (*Tx) GetByNames

func (tx *Tx) GetByNames(kind string, names []string, dst interface{}) error

GetByNames retrieves models from datastore by names

func (*Tx) GetByStringID

func (tx *Tx) GetByStringID(kind string, id string, dst interface{}) error

GetByStringID retrieves model from datastore by string id

func (*Tx) GetByStringIDs

func (tx *Tx) GetByStringIDs(kind string, ids []string, dst interface{}) error

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

Directories

Path Synopsis
cache

Jump to

Keyboard shortcuts

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