datastore

package
v0.0.0-...-519d24f Latest Latest
Warning

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

Go to latest
Published: May 5, 2020 License: BSD-3-Clause Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const CrudEntsLimit = 200

CrudEntsLimit is a limit of the number of entities that can be handled in one put or delete transaction

View Source
const LoggerKey = "gae.datastore"

LoggerKey is a key for logger in this package

Variables

View Source
var (
	// ErrTooManyEnts is returned when the user passes too many entities to PutMulti or DeleteMulti.
	ErrTooManyEnts = fmt.Errorf("too many entities to operate (max: %d)", CrudEntsLimit)
)

Functions

func GetCacheKey

func GetCacheKey(k *datastore.Key) string

GetCacheKey returns a string representation for the cache key

func IsDatastoreError

func IsDatastoreError(err error) bool

IsDatastoreError returns true if err is not ErrNoSuchEntity

func NewKey

func NewKey(kind string, k interface{}) *datastore.Key

NewKey returns a new *datastore.Key for `kind`. if k is *datastore.Key, it returns the same object. if k is not a string nor an int, k is converted by fmt.Sprintf("%s").

func NormalizeKeys

func NormalizeKeys(keys interface{}, kind string, namespace string) ([]*datastore.Key, error)

NormalizeKeys to normalize keys from []string, []interface{} to []*datastore.Key

func WithClient

func WithClient(ctx context.Context, client *Client) context.Context

WithClient setup a *Client for the current context which can be referred by FromContext

Types

type AfterSave

type AfterSave interface {
	AfterSave(context.Context) error
}

AfterSave is an interface to run a logic before save

type BeforeSave

type BeforeSave interface {
	BeforeSave(context.Context) error
}

BeforeSave is an interface to run a logic before save

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a wrapper for datastore.Client

func FromContext

func FromContext(ctx context.Context) *Client

FromContext returns a *Client for the current context

func NewClient

func NewClient(ctx context.Context, projectID string, options ...Option) *Client

NewClient returns a new Client

func NewClientFromClient

func NewClientFromClient(ctx context.Context, c *datastore.Client, options ...Option) *Client

NewClientFromClient returns a new *Client from the *datastore.Client

func (*Client) Close

func (c *Client) Close() error

Close closes the connection

func (*Client) Count

func (c *Client) Count(ctx context.Context, q *Query) (int, error)

Count returns a count

func (*Client) DeleteAll

func (c *Client) DeleteAll(ctx context.Context, kind string) error

DeleteAll deletes the all `kind` entities stored in datastore

func (*Client) DeleteMulti

func (c *Client) DeleteMulti(ctx context.Context, keys []*datastore.Key, options ...Option) error

DeleteMulti is wrapper for google.golang.org/appengine/datastore.DeleteMulti

func (*Client) GetAll

func (c *Client) GetAll(ctx context.Context, q *Query, dst interface{}) ([]*datastore.Key, error)

GetAll fills the query result into dst and returns corresponding *datastore.Key

func (*Client) GetMulti

func (c *Client) GetMulti(ctx context.Context, keys []*datastore.Key, entities interface{}, options ...Option) error

GetMulti is wrapper for google.golang.org/appengine/datastore.GetMulti

func (*Client) PutMulti

func (c *Client) PutMulti(ctx context.Context, keys []*datastore.Key, ent interface{}, options ...Option) ([]*datastore.Key, error)

PutMulti is wrapper for google.golang.org/appengine/datastore.PutMulti

func (*Client) Run

func (c *Client) Run(ctx context.Context, q *Query) (*datastore.Iterator, error)

Run runs a query and returns *datastore.Iterator

type Option

type Option func(*clientConfig) *clientConfig

Option is a function to configure CRUD operation

func Cache

func Cache(c cache.Cache) Option

Cache to set the cache storage

type Query

type Query struct {
	// contains filtered or unexported fields
}

Query is a wrapper for datasatore.Query

func NewQuery

func NewQuery(k string) *Query

NewQuery returns a *Query for the kind k

func (*Query) Ancestor

func (q *Query) Ancestor(a *datastore.Key) *Query

Ancestor sets the ancestor filter

func (*Query) Asc

func (q *Query) Asc(name string) *Query

Asc specifies ascending order on the given filed.

func (*Query) Desc

func (q *Query) Desc(name string) *Query

Desc specifies descending order on the given filed.

func (*Query) End

func (q *Query) End(value string) *Query

End sets the end cursor

func (*Query) Eq

func (q *Query) Eq(name string, value interface{}) *Query

Eq sets the "=" filter on the `name` field.

func (*Query) Ge

func (q *Query) Ge(name string, value interface{}) *Query

Ge sets the `>=` filter on the `name` field.

func (*Query) Gt

func (q *Query) Gt(name string, value interface{}) *Query

Gt sets the `>` filter on the `name` field.

func (*Query) KeysOnly

func (q *Query) KeysOnly() *Query

KeysOnly sets the query to return only keys

func (*Query) Le

func (q *Query) Le(name string, value interface{}) *Query

Le sets the `<=` filter on the `name` field.

func (*Query) Limit

func (q *Query) Limit(value int) *Query

Limit sets the limit

func (*Query) Lt

func (q *Query) Lt(name string, value interface{}) *Query

Lt sets the `<` filter on the `name` field.

func (*Query) Namespace

func (q *Query) Namespace(ns string) *Query

Namespace sets the namespace filter

func (*Query) Ne

func (q *Query) Ne(name string, value interface{}) *Query

Ne sets the `!=` filter on the `name` field.

func (*Query) Start

func (q *Query) Start(value string) *Query

Start sets the start cursor

func (*Query) String

func (q *Query) String() string

type TestEnv

type TestEnv struct {
	// contains filtered or unexported fields
}

TestEnv is a struct to provide a helper

func MustNewTestEnv

func MustNewTestEnv() *TestEnv

MustNewTestEnv is like MustNewTestEnv, but panic if an error occurs

func NewTestEnv

func NewTestEnv() (*TestEnv, error)

NewTestEnv returns a new TestEnv instance

func (*TestEnv) GetCache

func (te *TestEnv) GetCache() cache.Cache

GetCache returns a cache client

func (*TestEnv) LoadFixture

func (te *TestEnv) LoadFixture(path string) error

LoadFixture loads the fixture data from `path`

func (*TestEnv) MustLoadFixture

func (te *TestEnv) MustLoadFixture(path string)

MustLoadFixture is like LoadFixture but panic if an error occurs

func (*TestEnv) NewClient

func (te *TestEnv) NewClient() *Client

NewClient returns a *datastore.Client that sends requests to the test environment emulator

func (*TestEnv) Reset

func (te *TestEnv) Reset() error

Reset resets the environment

func (*TestEnv) Shutdown

func (te *TestEnv) Shutdown() error

Shutdown shuts down the environment

Directories

Path Synopsis
example
Code generated by github.com/yssk22/go/generator DO NOT EDIT.
Code generated by github.com/yssk22/go/generator DO NOT EDIT.

Jump to

Keyboard shortcuts

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