tree: 97bd039878b9f2b59cc8f4cea48747466b122416 [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. go.mod
  11. go.sum
  12. go_mod_tidy_hack.go
  13. integration_test.go
  14. key.go
  15. key_test.go
  16. keycompat.go
  17. keycompat_test.go
  18. load.go
  19. load_test.go
  20. mutation.go
  21. mutation_test.go
  22. oc_test.go
  23. prop.go
  24. query.go
  25. query_test.go
  26. README.md
  27. save.go
  28. save_test.go
  29. time.go
  30. time_test.go
  31. transaction.go
  32. 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)
}