datastore: go.mercari.io/datastore/aedatastore Index | Examples | Files

package aedatastore

import "go.mercari.io/datastore/aedatastore"

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

Index

Examples

Package Files

bridge.go client.go convert.go doc.go key.go query.go transaction.go

func FromContext Uses

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

FromContext make new Client by specified context.

Code:

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 Uses

func IsAEDatastoreClient(client w.Client) bool

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

func TransactionContext Uses

func TransactionContext(tx w.Transaction) context.Context

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

Code:

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

Package aedatastore imports 11 packages (graph) and is imported by 4 packages. Updated 2018-06-01. Refresh now. Tools for package owners.