Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 0 additions & 55 deletions datastore/sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,21 +364,7 @@ def keys_only_query
select("__key__")
# [END datastore_keys_only_query]

# [START datastore_run_keys_only_query]
keys = datastore.run(query).map(&:key)
# [END datastore_run_keys_only_query]
end

def distinct_query
datastore = Google::Cloud::Datastore.new

# [START datastore_distinct_query]
query = datastore.query("Task").
select("category", "priority").
distinct_on("category", "priority").
order("category").
order("priority")
# [END datastore_distinct_query]
end

def distinct_on_query
Expand Down Expand Up @@ -673,44 +659,3 @@ def property_filtering_run_query
end
# [END datastore_property_filtering_run_query]
end

def gql_run_query
# [START datastore_gql_run_query]
gql_query = Google::Cloud::Datastore::GqlQuery.new
gql_query.query_string = "SELECT * FROM Task ORDER BY created ASC"
tasks = datastore.run gql_query
# [END datastore_gql_run_query]
end

def gql_named_binding_query
# [START datastore_gql_named_binding_query]
gql_query = Google::Cloud::Datastore::GqlQuery.new
gql_query.query_string = "SELECT * FROM Task " \
"WHERE done = @done AND priority = @priority"
gql_query.named_bindings = { done: false, priority: 4 }
# [END datastore_gql_named_binding_query]

gql_query
end

def gql_positional_binding_query
# [START datastore_gql_positional_binding_query]
gql_query = Google::Cloud::Datastore::GqlQuery.new
gql_query.query_string = "SELECT * FROM Task " \
"WHERE done = @1 AND priority = @2"
gql_query.positional_bindings = [false, 4]
# [END datastore_gql_positional_binding_query]

gql_query
end

def gql_literal_query
# [START datastore_gql_literal_query]
gql_query = Google::Cloud::Datastore::GqlQuery.new
gql_query.query_string = "SELECT * FROM Task " \
"WHERE done = false AND priority = 4"
gql_query.allow_literals = true
# [END datastore_gql_literal_query]

gql_query
end
53 changes: 1 addition & 52 deletions datastore/spec/sample_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,24 +305,13 @@ def delete_accounts
expect(percent_completes.first).to eq(10.0)
end

it "supports keys_only_query run_keys_only_query" do
it "supports keys_only_query" do
keys = keys_only_query

expect(keys.empty?).to be(false)
expect(keys.first.kind).to eq("Task")
end

it "supports distinct_query" do
query = distinct_on_query
tasks = datastore.run query

expect(tasks.empty?).to be(false)
expect(tasks.first.key.kind).to eq("Task")
expect(tasks.first["category"]).to eq("Personal")
expect(tasks.first["priority"]).to eq(4)
expect(tasks.first.properties.to_h.size).to eq(2)
end

it "supports distinct_on_query" do
query = distinct_on_query
tasks = datastore.run query
Expand Down Expand Up @@ -529,46 +518,6 @@ def delete_accounts
expect(properties_by_kind["Task"]).to include "tag"
end

it "supports gql_run_query" do
tasks = gql_run_query

expect(tasks.empty?).to be(false)
tasks.each { |t| expect_basic_task t }
end

it "supports gql_named_binding_query" do
gql_query = gql_named_binding_query
tasks = datastore.run gql_query

expect(tasks.empty?).to be(false)
tasks.each do |t|
expect_basic_task t
expect(t["priority"]).to eq(4)
end
end

it "supports gql_positional_binding_query" do
gql_query = gql_positional_binding_query
tasks = datastore.run gql_query

expect(tasks.empty?).to be(false)
tasks.each do |t|
expect_basic_task t
expect(t["priority"]).to eq(4)
end
end

it "supports gql_literal_query" do
gql_query = gql_literal_query
tasks = datastore.run gql_query

expect(tasks.empty?).to be(false)
tasks.each do |t|
expect_basic_task t
expect(t["priority"]).to eq(4)
end
end

def expect_basic_task task
expect(task.key.kind).to eq("Task")
expect(task["category"]).to eq("Personal")
Expand Down