Module: Google::Cloud::Firestore

Defined in:
lib/google/cloud/firestore.rb,
lib/google/cloud/firestore/v1.rb,
lib/google/cloud/firestore/admin.rb,
lib/google/cloud/firestore/batch.rb,
lib/google/cloud/firestore/query.rb,
lib/google/cloud/firestore/client.rb,
lib/google/cloud/firestore/convert.rb,
lib/google/cloud/firestore/service.rb,
lib/google/cloud/firestore/v1beta1.rb,
lib/google/cloud/firestore/version.rb,
lib/google/cloud/firestore/admin/v1.rb,
lib/google/cloud/firestore/generate.rb,
lib/google/cloud/firestore/field_path.rb,
lib/google/cloud/firestore/credentials.rb,
lib/google/cloud/firestore/field_value.rb,
lib/google/cloud/firestore/transaction.rb,
lib/google/cloud/firestore/watch/order.rb,
lib/google/cloud/firestore/query_listener.rb,
lib/google/cloud/firestore/query_snapshot.rb,
lib/google/cloud/firestore/v1/credentials.rb,
lib/google/cloud/firestore/watch/listener.rb,
lib/google/cloud/firestore/commit_response.rb,
lib/google/cloud/firestore/document_change.rb,
lib/google/cloud/firestore/watch/inventory.rb,
lib/google/cloud/firestore/document_listener.rb,
lib/google/cloud/firestore/document_snapshot.rb,
lib/google/cloud/firestore/document_reference.rb,
lib/google/cloud/firestore/v1/firestore_client.rb,
lib/google/cloud/firestore/v1beta1/credentials.rb,
lib/google/cloud/firestore/admin/v1/credentials.rb,
lib/google/cloud/firestore/collection_reference.rb,
lib/google/cloud/firestore/watch/enumerator_queue.rb,
lib/google/cloud/firestore/document_reference/list.rb,
lib/google/cloud/firestore/v1beta1/firestore_client.rb,
lib/google/cloud/firestore/admin/v1/firestore_admin_client.rb

Overview

Cloud Firestore

Cloud Firestore is a NoSQL document database built for automatic scaling, high performance, and ease of application development. While the Cloud Firestore interface has many of the same features as traditional databases, as a NoSQL database it differs from them in the way it describes relationships between data objects.

See Firestore Overview.

Defined Under Namespace

Modules: Admin, V1, V1beta1 Classes: Batch, Client, CollectionReference, CommitResponse, Credentials, DocumentChange, DocumentListener, DocumentReference, DocumentSnapshot, FieldPath, FieldValue, Query, QueryListener, QuerySnapshot, Transaction

Constant Summary collapse

VERSION =
"1.4.3".freeze

Class Method Summary collapse

Class Method Details

.configure {|Google::Cloud.configure.firestore| ... } ⇒ Google::Cloud::Config

Configure the Google Cloud Firestore library.

The following Firestore configuration parameters are supported:

  • project_id - (String) Identifier for a Firestore project. (The parameter project is considered deprecated, but may also be 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) (The parameter keyfile is considered deprecated, but may also be used.)
  • scope - (String, Array) The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access.
  • timeout - (Integer) Default timeout to use in requests.
  • client_config - (Hash) A hash of values to override the default behavior of the API client.
  • endpoint - (String) Override of the endpoint host name, or nil to use the default endpoint.
  • emulator_host - (String) Host name of the emulator. Defaults to ENV["FIRESTORE_EMULATOR_HOST"]

Yields:

Returns:

  • (Google::Cloud::Config)

    The configuration object the Google::Cloud::Firestore library uses.



145
146
147
148
149
# File 'lib/google/cloud/firestore.rb', line 145

def self.configure
  yield Google::Cloud.configure.firestore if block_given?

  Google::Cloud.configure.firestore
end

.new(project_id: nil, credentials: nil, scope: nil, timeout: nil, client_config: nil, endpoint: nil, emulator_host: nil, project: nil, keyfile: nil) ⇒ Google::Cloud::Firestore::Client

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

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

Examples:

require "google/cloud/firestore"

firestore = Google::Cloud::Firestore.new

Parameters:

  • project_id (String) (defaults to: nil)

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

  • credentials (String, Hash, Google::Auth::Credentials) (defaults to: nil)

    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>) (defaults to: nil)

    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) (defaults to: nil)

    Default timeout to use in requests. Optional.

  • client_config (Hash) (defaults to: nil)

    A hash of values to override the default behavior of the API client. Optional.

  • endpoint (String) (defaults to: nil)

    Override of the endpoint host name. Optional. If the param is nil, uses the default endpoint.

  • emulator_host (String) (defaults to: nil)

    Firestore emulator host. Optional. If the param is nil, uses the value of the emulator_host config.

  • project (String) (defaults to: nil)

    Alias for the project_id argument. Deprecated.

  • keyfile (String) (defaults to: nil)

    Alias for the credentials argument. Deprecated.

Returns:

Raises:

  • (ArgumentError)


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/google/cloud/firestore.rb', line 76

def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil,
             client_config: nil, endpoint: nil, emulator_host: nil,
             project: nil, keyfile: nil
  project_id    ||= (project || default_project_id)
  scope         ||= configure.scope
  timeout       ||= configure.timeout
  client_config ||= configure.client_config
  endpoint      ||= configure.endpoint
  emulator_host ||= configure.emulator_host

  if emulator_host
    project_id = project_id.to_s
    raise ArgumentError, "project_id is missing" if project_id.empty?

    return Firestore::Client.new(
      Firestore::Service.new(
        project_id, :this_channel_is_insecure,
        host: emulator_host, timeout: timeout,
        client_config: client_config
      )
    )
  end

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

  if credentials.respond_to? :project_id
    project_id ||= credentials.project_id
  end
  project_id = project_id.to_s
  raise ArgumentError, "project_id is missing" if project_id.empty?

  Firestore::Client.new(
    Firestore::Service.new(
      project_id, credentials,
      host: endpoint, timeout: timeout, client_config: client_config
    )
  )
end