func ExampleClient_DeleteMulti() { ctx := context.Background() client, err := datastore.NewClient(ctx, "project-id") if err != nil { // TODO: Handle error. } var keys []*datastore.Key for i := 1; i <= 10; i++ { keys = append(keys, datastore.IDKey("Article", int64(i), nil)) } if err := client.DeleteMulti(ctx, keys); err != nil { // TODO: Handle error. } }
// [START update_entity] // MarkDone marks the task done with the given ID. func MarkDone(ctx context.Context, client *datastore.Client, taskID int64) error { // Create a key using the given integer ID. key := datastore.IDKey("Task", taskID, nil) // In a transaction load each task, set done to true and store. _, err := client.RunInTransaction(ctx, func(tx *datastore.Transaction) error { var task Task if err := tx.Get(key, &task); err != nil { return err } task.Done = true _, err := tx.Put(key, &task) return err }) return err }
func ExampleIDKey() { // Key with numeric ID. k := datastore.IDKey("Article", 1, nil) _ = k // TODO: Use key. }
func ExampleKey_Encode() { key := datastore.IDKey("Article", 1, nil) encoded := key.Encode() fmt.Println(encoded) // Output: EgsKB0FydGljbGUQAQ }
func (db *datastoreDB) datastoreKey(id int64) *datastore.Key { return datastore.IDKey("Book", id, nil) }
// [START delete_entity] // DeleteTask deletes the task with the given ID. func DeleteTask(ctx context.Context, client *datastore.Client, taskID int64) error { return client.Delete(ctx, datastore.IDKey("Task", taskID, nil)) }