tree: d60e83aed83ace287ccfd2b8bdbd927e9ed941b7 [path history] [tgz]
  1. admin/
  2. aliasshim/
  3. apiv1/
  4. internal/
  5. testdata/
  6. CHANGES.md
  7. client.go
  8. datastore.go
  9. datastore.replay
  10. datastore_test.go
  11. doc.go
  12. errors.go
  13. example_test.go
  14. go.mod
  15. go.sum
  16. integration_test.go
  17. key.go
  18. key_test.go
  19. keycompat.go
  20. keycompat_test.go
  21. load.go
  22. load_test.go
  23. mock_test.go
  24. mutation.go
  25. mutation_test.go
  26. option.go
  27. prop.go
  28. prop_test.go
  29. query.go
  30. query_test.go
  31. README.md
  32. save.go
  33. save_test.go
  34. time.go
  35. time_test.go
  36. transaction.go
  37. transaction_test.go
  38. util_test.go
datastore/README.md

Cloud Datastore Go Reference

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