Google Cloud Datastore (docs) is a fully managed, schemaless database for storing non-relational data. Cloud Datastore automatically scales with your users and supports ACID transactions, high availability of reads and writes, strong consistency for reads and ancestor queries, and eventual consistency for all other queries.
Follow the activation instructions to use the Google Cloud Datastore API with your project.
- google-cloud-datastore API documentation
- google-cloud-datastore on RubyGems
- Google Cloud Datastore documentation
$ gem install google-cloud-datastore
This library uses Service Account credentials to connect to Google Cloud services. When running on Compute Engine the credentials will be discovered automatically. When running on other environments the Service Account credentials can be specified by providing the path to the JSON file, or the JSON itself, in environment variables.
Instructions and configuration options are covered in the Authentication Guide.
require "google/cloud/datastore"
datastore = Google::Cloud::Datastore.new(
project_id: "my-todo-project",
credentials: "/path/to/keyfile.json"
)
# Create a new task to demo datastore
task = datastore.entity "Task", "sampleTask" do |t|
t["type"] = "Personal"
t["done"] = false
t["priority"] = 4
t["description"] = "Learn Cloud Datastore"
end
# Save the new task
datastore.save task
# Run a query for all completed tasks
query = datastore.query("Task").
where("done", "=", false)
tasks = datastore.run query
To enable logging for this library, set the logger for the underlying gRPC library. The logger that you set may be a Ruby stdlib Logger
as shown below, or a Google::Cloud::Logging::Logger
that will write logs to Stackdriver Logging. See grpc/logconfig.rb and the gRPC spec_helper.rb for additional information.
Configuring a Ruby stdlib logger:
require "logger"
module MyLogger
LOGGER = Logger.new $stderr, level: Logger::WARN
def logger
LOGGER
end
end
# Define a gRPC module-level logger method before grpc/logconfig.rb loads.
module GRPC
extend MyLogger
end
This library is supported on Ruby 2.0+.
However, Ruby 2.3 or later is strongly recommended, as earlier releases have reached or are nearing end-of-life. After June 1, 2018, Google will provide official support only for Ruby versions that are considered current and supported by Ruby Core (that is, Ruby versions that are either in normal maintenance or in security maintenance). See https://www.ruby-lang.org/en/downloads/branches/ for further details.
This library follows Semantic Versioning.
Contributions to this library are always welcome and highly encouraged.
See the Contributing Guide for more information on how to get started.
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See Code of Conduct for more information.
This library is licensed under Apache 2.0. Full license text is available in LICENSE.
Please report bugs at the project on Github. Don't hesitate to ask questions about the client or APIs on StackOverflow.