Module: Google::Cloud::Datastore

Defined in:
lib/google/cloud/datastore.rb,
lib/google/cloud/datastore/key.rb,
lib/google/cloud/datastore/query.rb,
lib/google/cloud/datastore/commit.rb,
lib/google/cloud/datastore/cursor.rb,
lib/google/cloud/datastore/entity.rb,
lib/google/cloud/datastore/errors.rb,
lib/google/cloud/datastore/convert.rb,
lib/google/cloud/datastore/dataset.rb,
lib/google/cloud/datastore/service.rb,
lib/google/cloud/datastore/version.rb,
lib/google/cloud/datastore/gql_query.rb,
lib/google/cloud/datastore/properties.rb,
lib/google/cloud/datastore/credentials.rb,
lib/google/cloud/datastore/transaction.rb,
lib/google/cloud/datastore/v1/doc/overview.rb,
lib/google/cloud/datastore/v1/datastore_client.rb,
lib/google/cloud/datastore/dataset/query_results.rb,
lib/google/cloud/datastore/read_only_transaction.rb,
lib/google/cloud/datastore/dataset/lookup_results.rb

Overview

Ruby Client for Google Cloud Datastore API (Alpha)

Google Cloud Datastore API: Accesses the schemaless NoSQL database to provide fully managed, robust, scalable storage for your application.

Quick Start

In order to use this library, you first need to go through the following steps:

  1. Select or create a Cloud Platform project.
  2. Enable the Google Cloud Datastore API.
  3. Setup Authentication.

Installation

$ gem install google-cloud-datastore

Next Steps

Defined Under Namespace

Modules: V1 Classes: Commit, Credentials, Cursor, Dataset, Entity, GqlQuery, Key, KeyError, Properties, PropertyError, Query, ReadOnlyTransaction, Transaction, TransactionError

Constant Summary collapse

VERSION =
"1.3.0"

Class Method Summary collapse

Class Method Details

.new(project_id: nil, credentials: nil, scope: nil, timeout: nil, client_config: nil, emulator_host: nil, project: nil, keyfile: nil) ⇒ Google::Cloud::Datastore::Dataset

Creates a new object for connecting to the Datastore service. Each call creates a new connection.

For more information on connecting to Google Cloud see the Authentication Guide.

Examples:

require "google/cloud/datastore"

datastore = Google::Cloud::Datastore.new(
  project_id: "my-todo-project",
  credentials: "/path/to/keyfile.json"
)

task = datastore.entity "Task", "sampleTask" do |t|
  t["type"] = "Personal"
  t["done"] = false
  t["priority"] = 4
  t["description"] = "Learn Cloud Datastore"
end

datastore.save task

Parameters:

  • project_id (String)

    Identifier for a Datastore project. If not present, the default project for the credentials is used.

  • credentials (String, Hash, Google::Auth::Credentials)

    The path to the keyfile as a String, the contents of the keyfile as a Hash, or a Google::Auth::Credentials object. (See Credentials)

  • scope (String, Array<String>)

    The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access. See Using OAuth 2.0 to Access Google APIs.

    The default scope is:

    • https://www.googleapis.com/auth/datastore
  • timeout (Integer)

    Default timeout to use in requests. Optional.

  • client_config (Hash)

    A hash of values to override the default behavior of the API client. See Google::Gax::CallSettings. Optional.

  • emulator_host (String)

    Datastore emulator host. Optional. If the param is nil, ENV["DATASTORE_EMULATOR_HOST"] will be used.

  • project (String)

    Alias for the project_id argument. Deprecated.

  • keyfile (String)

    Alias for the credentials argument. Deprecated.

Returns:



613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
# File 'lib/google/cloud/datastore.rb', line 613

def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil,
             client_config: nil, emulator_host: nil, project: nil,
             keyfile: nil
  project_id ||= (project || Datastore::Dataset.default_project_id)
  project_id = project_id.to_s # Always cast to a string
  fail ArgumentError, "project_id is missing" if project_id.empty?

  emulator_host ||= ENV["DATASTORE_EMULATOR_HOST"]
  if emulator_host
    return Datastore::Dataset.new(
      Datastore::Service.new(
        project_id, :this_channel_is_insecure,
        host: emulator_host, client_config: client_config))
  end

  credentials ||= keyfile
  credentials ||= Datastore::Credentials.default(scope: scope)
  unless credentials.is_a? Google::Auth::Credentials
    credentials = Datastore::Credentials.new credentials, scope: scope
  end

  Datastore::Dataset.new(
    Datastore::Service.new(
      project_id, credentials,
      timeout: timeout, client_config: client_config))
end