example

package
v0.0.0-...-ed9fe1d Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2018 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const ExampleKindLoggerKey = "ent.example"

ExampleKindLoggerKey is a logger key name for the ent

View Source
const ExampleQueryLoggerKey = "ent.query.example"

ExampleQueryLoggerKey is a logger key name for the ent

View Source
const ExampleSearchIndexName = "ent.Example"

Variables

View Source
var DefaultExampleKind = &ExampleKind{}

DefaultExampleKind is a default value of *ExampleKind

Functions

This section is empty.

Types

type A

type A struct {
}

no target

type AliasNotUsed

type AliasNotUsed int

type Example

type Example struct {
	ID                  string             `json:"id" ent:"id"`
	Digit               int                `json:"digit" ent:"form,resetifmissing" default:"10"`
	Desc                string             `json:"desc" ent:"form,search" default:"This is default value"`
	ContentBytes        []byte             `json:"content_bytes" ent:"form,search"`
	SliceType           []string           `json:"slice_type" ent:"form"`
	BoolType            bool               `json:"bool_type" ent:"form,search"`
	FloatType           float64            `json:"float_type" ent:"form,search"`
	CreatedAt           time.Time          `json:"created_at" default:"$now"`
	UpdatedAt           time.Time          `json:"updated_at" ent:"timestamp"`
	DefaultTime         time.Time          `json:"default_time" default:"2016-01-01T20:12:10Z"`
	BeforeSaveProcessed bool               `json:"before_save_processed"`
	CustomType          rgb.RGB            `json:"custom_type" ent:"form" parser:"github.com/speedland/go/rgb.MustParseRGB"`
	Location            appengine.GeoPoint `json:"location" ent:"search"`
}

Example is an example of datastore model.

func NewExample

func NewExample() *Example

NewExample returns a new *Example with default field values.

func (*Example) BeforeSave

func (e *Example) BeforeSave(ctx context.Context) error

func (*Example) NewKey

func (e *Example) NewKey(ctx context.Context) *datastore.Key

func (*Example) ToSearchDoc

func (e *Example) ToSearchDoc() *ExampleSearchDoc

ToSearchDoc returns a new *ExampleSearchDoc

func (*Example) UpdateByForm

func (e *Example) UpdateByForm(form *keyvalue.GetProxy)

UpdateByForm updates the fields by form values. All values should be validated before calling this function.

type ExampleKind

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

func (*ExampleKind) Delete

func (k *ExampleKind) Delete(ctx context.Context, key interface{}) (*datastore.Key, error)

Delete deletes the entity from datastore

func (*ExampleKind) DeleteMatched

func (k *ExampleKind) DeleteMatched(ctx context.Context, q *ExampleQuery) (int, error)

DeleteMatched deletes the all ents that match with the query. This func modify Limit/StartKey condition in the query so that you should restore it if you want to reuse the query.

func (*ExampleKind) DeleteMulti

func (k *ExampleKind) DeleteMulti(ctx context.Context, keys interface{}) ([]*datastore.Key, error)

DeleteMulti do Delete with multiple keys

func (*ExampleKind) EnforceNamespace

func (k *ExampleKind) EnforceNamespace(ns string, b bool) *ExampleKind

EnforceNamespace enforces namespace for Get/Put/Delete or not.

func (*ExampleKind) Get

func (k *ExampleKind) Get(ctx context.Context, key interface{}) (*datastore.Key, *Example, error)

Get gets the kind entity from datastore

func (*ExampleKind) GetMulti

func (k *ExampleKind) GetMulti(ctx context.Context, keys interface{}) ([]*datastore.Key, []*Example, error)

GetMulti do Get with multiple keys. keys must be []string, []*datastore.Key, or []interface{}

func (*ExampleKind) MustDelete

func (k *ExampleKind) MustDelete(ctx context.Context, key interface{}) *datastore.Key

MustDelete is like Delete but panic if an error occurs

func (*ExampleKind) MustDeleteMulti

func (k *ExampleKind) MustDeleteMulti(ctx context.Context, keys interface{}) []*datastore.Key

MustDeleteMulti is like DeleteMulti but panic if an error occurs

func (*ExampleKind) MustGet

func (k *ExampleKind) MustGet(ctx context.Context, key interface{}) *Example

MustGet is like Get but returns only values and panic if error happens.

func (*ExampleKind) MustGetMulti

func (k *ExampleKind) MustGetMulti(ctx context.Context, keys interface{}) []*Example

MustGetMulti is like GetMulti but returns only values and panic if error happens.

func (*ExampleKind) MustPut

func (k *ExampleKind) MustPut(ctx context.Context, ent *Example) *datastore.Key

MustPut is like Put and panic if an error occurrs.

func (*ExampleKind) MustPutMulti

func (k *ExampleKind) MustPutMulti(ctx context.Context, ents []*Example) []*datastore.Key

MustPutMulti is like PutMulti but panic if an error occurs

func (*ExampleKind) MustReplace

func (k *ExampleKind) MustReplace(ctx context.Context, ent *Example, replacer ExampleKindReplacer) (*datastore.Key, *Example)

func (*ExampleKind) MustReplaceMulti

func (k *ExampleKind) MustReplaceMulti(ctx context.Context, ents []*Example, replacer ExampleKindReplacer) ([]*datastore.Key, []*Example)

func (*ExampleKind) Put

func (k *ExampleKind) Put(ctx context.Context, ent *Example) (*datastore.Key, error)

Put puts the entity to datastore.

func (*ExampleKind) PutMulti

func (k *ExampleKind) PutMulti(ctx context.Context, ents []*Example) ([]*datastore.Key, error)

PutMulti do Put with multiple keys

func (*ExampleKind) Replace

func (k *ExampleKind) Replace(ctx context.Context, ent *Example, replacer ExampleKindReplacer) (*datastore.Key, *Example, error)

func (*ExampleKind) ReplaceMulti

func (k *ExampleKind) ReplaceMulti(ctx context.Context, ents []*Example, replacer ExampleKindReplacer) ([]*datastore.Key, []*Example, error)

func (*ExampleKind) SearchKeys

func (k *ExampleKind) SearchKeys(ctx context.Context, query string, opts *search.SearchOptions) (*ExamplePagination, error)

SearchKeys returns the a result as *ExamplePagination object. It only containd valid []*datastore.Keys

func (*ExampleKind) SearchValues

func (k *ExampleKind) SearchValues(ctx context.Context, query string, opts *search.SearchOptions) (*ExamplePagination, error)

SearchValues returns the a result as *ExamplePagination object with filling Data field.

func (*ExampleKind) UseDefaultIfNil

func (k *ExampleKind) UseDefaultIfNil(b bool) *ExampleKind

type ExampleKindReplacer

type ExampleKindReplacer interface {
	Replace(*Example, *Example) *Example
}

type ExampleKindReplacerFunc

type ExampleKindReplacerFunc func(*Example, *Example) *Example

func (ExampleKindReplacerFunc) Replace

func (f ExampleKindReplacerFunc) Replace(ent1 *Example, ent2 *Example) *Example

type ExamplePagination

type ExamplePagination struct {
	Start string           `json:"start"`
	End   string           `json:"end"`
	Count int              `json:"count,omitempty"`
	Data  []*Example       `json:"data"`
	Keys  []*datastore.Key `json:"-"`
}

type ExampleQuery

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

ExampleQuery helps to build and execute a query

func NewExampleQuery

func NewExampleQuery() *ExampleQuery

func (*ExampleQuery) Ancestor

func (q *ExampleQuery) Ancestor(a lazy.Value) *ExampleQuery

Ancestor sets the ancestor filter

func (*ExampleQuery) Asc

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

Asc specifies ascending order on the given filed.

func (*ExampleQuery) Count

func (q *ExampleQuery) Count(ctx context.Context) (int, error)

Count returns the count of entities

func (*ExampleQuery) Desc

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

Desc specifies descending order on the given filed.

func (*ExampleQuery) End

func (q *ExampleQuery) End(value lazy.Value) *ExampleQuery

Limit specifies the numbe of limit returend by this query.

func (*ExampleQuery) Eq

func (q *ExampleQuery) Eq(name string, value lazy.Value) *ExampleQuery

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

func (*ExampleQuery) Ge

func (q *ExampleQuery) Ge(name string, value lazy.Value) *ExampleQuery

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

func (*ExampleQuery) GetAll

func (q *ExampleQuery) GetAll(ctx context.Context) ([]*datastore.Key, []*Example, error)

GetAll returns all key and value of the query.

func (*ExampleQuery) GetAllValues

func (q *ExampleQuery) GetAllValues(ctx context.Context) ([]*Example, error)

GetAllValues is like GetAll but returns only values

func (*ExampleQuery) Gt

func (q *ExampleQuery) Gt(name string, value lazy.Value) *ExampleQuery

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

func (*ExampleQuery) Le

func (q *ExampleQuery) Le(name string, value lazy.Value) *ExampleQuery

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

func (*ExampleQuery) Limit

func (q *ExampleQuery) Limit(n lazy.Value) *ExampleQuery

Limit specifies the numbe of limit returend by this query.

func (*ExampleQuery) Lt

func (q *ExampleQuery) Lt(name string, value lazy.Value) *ExampleQuery

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

func (*ExampleQuery) MustCount

func (q *ExampleQuery) MustCount(ctx context.Context) int

MustCount returns the count of entities

func (*ExampleQuery) MustGetAll

func (q *ExampleQuery) MustGetAll(ctx context.Context) ([]*datastore.Key, []*Example)

MustGetAll is like GetAll but panic if an error occurrs.

func (*ExampleQuery) MustGetAllValues

func (q *ExampleQuery) MustGetAllValues(ctx context.Context) []*Example

MustGetAllValues is like GetAllValues but panic if an error occurrs

func (*ExampleQuery) MustRun

func (q *ExampleQuery) MustRun(ctx context.Context) *ExamplePagination

MustRun is like Run but panic if an error occurrs

func (*ExampleQuery) Ne

func (q *ExampleQuery) Ne(name string, value lazy.Value) *ExampleQuery

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

func (*ExampleQuery) Run

Run returns the a result as *ExamplePagination object

func (*ExampleQuery) Start

func (q *ExampleQuery) Start(value lazy.Value) *ExampleQuery

Limit specifies the numbe of limit returend by this query.

func (*ExampleQuery) ViaKeys

func (q *ExampleQuery) ViaKeys(k *ExampleKind) *ExampleQuery

ViaKeys optimize to execute keys-only query then call k.GetMulti() to fetch values. This would reduce the datastore query and maximize the memcache usage if the query called many times in a short time window.

type ExampleSearchDoc

type ExampleSearchDoc struct {
	ID           string // TODO: Support non-string key as ID
	Desc         string
	ContentBytes search.HTML
	BoolType     search.Atom
	FloatType    float64
	Location     appengine.GeoPoint
}

ExampleSearchDoc is a object for search indexes.

Jump to

Keyboard shortcuts

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