Class: Google::Cloud::Datastore::Commit

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/datastore/commit.rb

Overview

Commit

Object yielded from commit methods to allow multiple changes to be made in a single commit.

See Dataset#commit and Transaction#commit.

Examples:

gcloud = Google::Cloud.new
datastore = gcloud.datastore
datastore.commit do |c|
  c.save task1, task2
  c.delete entity1, entity2
end

Instance Method Summary collapse

Instance Method Details

#delete(*entities_or_keys) ⇒ Object

Remove entities from the Datastore.

Examples:

gcloud = Google::Cloud.new
datastore = gcloud.datastore
datastore.commit do |c|
  c.delete task1, task2
end

Parameters:

  • entities_or_keys (Entity, Key)

    One or more Entity or Key objects to remove.



116
117
118
119
120
121
122
123
# File 'lib/google/cloud/datastore/commit.rb', line 116

def delete *entities_or_keys
  keys = Array(entities_or_keys).flatten.map do |e_or_k|
    e_or_k.respond_to?(:key) ? e_or_k.key : e_or_k
  end
  @shared_deletes += keys unless keys.empty?
  # Do not delete yet
  true
end

#insert(*entities) ⇒ Object

Inserts entities to the Datastore.

Examples:

gcloud = Google::Cloud.new
datastore = gcloud.datastore
datastore.commit do |c|
  c.insert task1, task2
end

Parameters:

  • entities (Entity)

    One or more Entity objects to insert.



77
78
79
80
81
82
# File 'lib/google/cloud/datastore/commit.rb', line 77

def insert *entities
  entities = Array(entities).flatten
  @shared_inserts += entities unless entities.empty?
  # Do not insert yet
  entities
end

#save(*entities) ⇒ Object Also known as: upsert

Saves entities to the Datastore.

Examples:

gcloud = Google::Cloud.new
datastore = gcloud.datastore
datastore.commit do |c|
  c.save task1, task2
end

Parameters:

  • entities (Entity)

    One or more Entity objects to save.



57
58
59
60
61
62
# File 'lib/google/cloud/datastore/commit.rb', line 57

def save *entities
  entities = Array(entities).flatten
  @shared_upserts += entities unless entities.empty?
  # Do not save yet
  entities
end

#update(*entities) ⇒ Object

Updates entities to the Datastore.

Examples:

gcloud = Google::Cloud.new
datastore = gcloud.datastore
datastore.commit do |c|
  c.update task1, task2
end

Parameters:

  • entities (Entity)

    One or more Entity objects to update.



96
97
98
99
100
101
# File 'lib/google/cloud/datastore/commit.rb', line 96

def update *entities
  entities = Array(entities).flatten
  @shared_updates += entities unless entities.empty?
  # Do not update yet
  entities
end