tree: a5d15cb367ce8569816c737cd06587984ea3c54c [path history] [tgz]
  1. internal/
  2. testdata/
  3. client.go
  4. datastore.go
  5. datastore.replay
  6. datastore_test.go
  7. doc.go
  8. errors.go
  9. example_test.go
  10. integration_test.go
  11. key.go
  12. key_test.go
  13. keycompat.go
  14. keycompat_test.go
  15. load.go
  16. load_test.go
  17. mutation.go
  18. mutation_test.go
  19. oc_test.go
  20. prop.go
  21. query.go
  22. query_test.go
  23. README.md
  24. save.go
  25. save_test.go
  26. time.go
  27. time_test.go
  28. transaction.go
  29. transaction_test.go
datastore/README.md

Cloud Datastore GoDoc

Example Usage

First create a datastore.Client to use throughout your application:

client, err := datastore.NewClient(ctx, "my-project-id")
if err != nil {
	log.Fatal(err)
}

Then use that client to interact with the API:

type Post struct {
	Title       string
	Body        string `datastore:",noindex"`
	PublishedAt time.Time
}
keys := []*datastore.Key{
	datastore.NameKey("Post", "post1", nil),
	datastore.NameKey("Post", "post2", nil),
}
posts := []*Post{
	{Title: "Post 1", Body: "...", PublishedAt: time.Now()},
	{Title: "Post 2", Body: "...", PublishedAt: time.Now()},
}
if _, err := client.PutMulti(ctx, keys, posts); err != nil {
	log.Fatal(err)
}