aedatastore

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package aedatastore provides AppEngine Datastore implementation of datastore.Client. This package wrapping google.golang.org/appengine/v2/datastore package.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromContext

func FromContext(ctx context.Context, opts ...w.ClientOption) (w.Client, error)

FromContext make new Client by specified context.

Example
inst, err := aetest.NewInstance(&aetest.Options{StronglyConsistentDatastore: true, SuppressDevAppServerLog: true})
if err != nil {
	panic(err)
}
defer inst.Close()
r, err := inst.NewRequest("GET", "/", nil)
if err != nil {
	panic(err)
}
ctx := appengine.NewContext(r)

client, err := aedatastore.FromContext(
	ctx,
)
if err != nil {
	panic(err)
}
defer client.Close()

type Data struct {
	Name string
}

key := client.IncompleteKey("Data", nil)
entity := &Data{Name: "mercari"}
key, err = client.Put(ctx, key, entity)
if err != nil {
	panic(err)
}

entity = &Data{}
err = client.Get(ctx, key, entity)
if err != nil {
	panic(err)
}

fmt.Println(entity.Name)
Output:

mercari

func IsAEDatastoreClient

func IsAEDatastoreClient(client w.Client) bool

IsAEDatastoreClient returns check result that client is this package's client or not.

func TransactionContext

func TransactionContext(tx w.Transaction) context.Context

TransactionContext returns context that is under the AppEngine Datastore's transaction.

Example
ctx, cancelFn := appengineContext()
go cancelFn()

client, err := aedatastore.FromContext(ctx)
if err != nil {
	panic(err)
}
defer client.Close()

tx, err := client.NewTransaction(ctx)
if err != nil {
	panic(err)
}
go tx.Commit()

txCtx := aedatastore.TransactionContext(tx)

// join task to Transaction!
task := taskqueue.NewPOSTTask("/foobar", url.Values{})
_, err = taskqueue.Add(txCtx, task, "")
if err != nil {
	panic(err)
}
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

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