google-cloud-datastore 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c5cb153ea77e6581236392f42ec5755cde46733fc2331d6c6b7f204e171c4006
4
- data.tar.gz: 57e1bde4b98c1f21b7d65d56255d66b79ab19c7d0a62d03d67fdbc90027fe1ca
3
+ metadata.gz: ded45a15f44ec5a2e095ef0369db26c2a4a65e59c2af1e08bb8f6028736062ea
4
+ data.tar.gz: 8d7321547294a1c1ab492df132e19300a0466f252e74f9c7122fb7941bbaeac7
5
5
  SHA512:
6
- metadata.gz: 950fa042833ec644777f8b2e89ed0078f4c4629f4f32d6833b6de20d7f4f09a4563c96fbb9515a0eb6e3d76ace6d610e63178033a6d6318a0b2b897b91ccfb4e
7
- data.tar.gz: 4c6757326810a722fc9c2543bcbb0135b15ad698cd5b9b5bfdfe33ae4f84bf8e9df437d8838784f0a71c3debf7c51d8a6be70ed671efc9382cefddd10ec2c672
6
+ metadata.gz: 8a4039bbc1c34698507c3b7a1e2c22b011f4df3ea66a57927c7dd147c4468d97c85f15b49efa6c06dcb124815ad5fc4098eeaa8e6f54d23570489e6da0d8dbf3
7
+ data.tar.gz: af0981ba4ea2bd054ba35ddd372399addbbb5e0d0c8e4032f518b48ab03065771af8a6185dea29483a9948ae42147011c0f6a100c747dd08100736780a5cb286
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Release History
2
2
 
3
+ ### 2.5.0 (2023-02-09)
4
+
5
+ #### Features
6
+
7
+ * Added support for multiple database ([#20038](https://github.com/googleapis/google-cloud-ruby/issues/20038))
8
+
3
9
  ### 2.4.0 (2023-02-02)
4
10
 
5
11
  #### Features
@@ -84,6 +84,26 @@ module Google
84
84
  end
85
85
  alias project project_id
86
86
 
87
+ ##
88
+ # The Datastore database connected to.
89
+ #
90
+ # @return [String] ID of the database
91
+ #
92
+ # @example
93
+ # require "google/cloud/datastore"
94
+ #
95
+ # datastore = Google::Cloud::Datastore.new(
96
+ # project_id: "my-todo-project",
97
+ # credentials: "/path/to/keyfile.json",
98
+ # database_id: "my-database"
99
+ # )
100
+ #
101
+ # datastore.database_id #=> "my-database"
102
+ #
103
+ def database_id
104
+ service.database
105
+ end
106
+
87
107
  ##
88
108
  # Generate IDs for a Key before creating an entity.
89
109
  #
@@ -69,6 +69,27 @@ module Google
69
69
  alias dataset_id project
70
70
  alias dataset_id= project=
71
71
 
72
+ ##
73
+ # The database of the Key.
74
+ #
75
+ # @return [String]
76
+ #
77
+ # @example
78
+ # require "google/cloud/datastore"
79
+ #
80
+ # datastore = Google::Cloud::Datastore.new(
81
+ # project: "my-todo-project",
82
+ # database: "my-todo-database",
83
+ # keyfile: "/path/to/keyfile.json"
84
+ # )
85
+ #
86
+ # task = datastore.find "Task", "sampleTask"
87
+ # task.key.database #=> "my-todo-database"
88
+ #
89
+ attr_accessor :database
90
+ alias database_id database
91
+ alias database_id= database=
92
+
72
93
  ##
73
94
  # The namespace of the Key.
74
95
  #
@@ -281,9 +302,9 @@ module Google
281
302
  Google::Cloud::Datastore::V1::Key::PathElement.new path_args
282
303
  end
283
304
  grpc = Google::Cloud::Datastore::V1::Key.new path: grpc_path
284
- if project || namespace
305
+ if project || database || namespace
285
306
  grpc.partition_id = Google::Cloud::Datastore::V1::PartitionId.new(
286
- project_id: project.to_s, namespace_id: namespace.to_s
307
+ project_id: project.to_s, database_id: database.to_s, namespace_id: namespace.to_s
287
308
  )
288
309
  end
289
310
  grpc
@@ -304,6 +325,7 @@ module Google
304
325
  end
305
326
  if key_grpc.partition_id
306
327
  key.project = key_grpc.partition_id.project_id
328
+ key.database = key_grpc.partition_id.database_id
307
329
  key.namespace = key_grpc.partition_id.namespace_id
308
330
  end
309
331
  key.parent = Key.from_grpc key_grpc if key_grpc.path.count.positive?
@@ -29,14 +29,16 @@ module Google
29
29
  attr_accessor :credentials
30
30
  attr_accessor :host
31
31
  attr_accessor :timeout
32
+ attr_accessor :database
32
33
 
33
34
  ##
34
35
  # Creates a new Service instance.
35
- def initialize project, credentials, host: nil, timeout: nil
36
+ def initialize project, credentials, database, host: nil, timeout: nil
36
37
  @project = project
37
38
  @credentials = credentials
38
39
  @host = host
39
40
  @timeout = timeout
41
+ @database = database
40
42
  end
41
43
 
42
44
  def service
@@ -47,7 +49,7 @@ module Google
47
49
  config.endpoint = host if host
48
50
  config.lib_name = "gccl"
49
51
  config.lib_version = Google::Cloud::Datastore::VERSION
50
- config.metadata = { "google-cloud-resource-prefix": "projects/#{@project}" }
52
+ config.metadata = { "google-cloud-resource-prefix": "projects/#{@project}/databases/#{database}" }
51
53
  end
52
54
  end
53
55
  attr_accessor :mocked_service
@@ -56,7 +58,7 @@ module Google
56
58
  # Allocate IDs for incomplete keys.
57
59
  # (This is useful for referencing an entity before it is inserted.)
58
60
  def allocate_ids *incomplete_keys
59
- service.allocate_ids project_id: project, keys: incomplete_keys
61
+ service.allocate_ids project_id: project, database_id: database, keys: incomplete_keys
60
62
  end
61
63
 
62
64
  ##
@@ -64,7 +66,7 @@ module Google
64
66
  def lookup *keys, consistency: nil, transaction: nil
65
67
  read_options = generate_read_options consistency, transaction
66
68
 
67
- service.lookup project_id: project, keys: keys, read_options: read_options
69
+ service.lookup project_id: project, database_id: database, keys: keys, read_options: read_options
68
70
  end
69
71
 
70
72
  # Query for entities.
@@ -82,6 +84,7 @@ module Google
82
84
  end
83
85
 
84
86
  service.run_query project_id: project,
87
+ database_id: database,
85
88
  partition_id: partition_id,
86
89
  read_options: read_options,
87
90
  query: query,
@@ -125,7 +128,7 @@ module Google
125
128
  )
126
129
  transaction_options.read_write = rw
127
130
  end
128
- service.begin_transaction project_id: project, transaction_options: transaction_options
131
+ service.begin_transaction project_id: project, database_id: database, transaction_options: transaction_options
129
132
  end
130
133
 
131
134
  ##
@@ -133,17 +136,18 @@ module Google
133
136
  # some entities.
134
137
  def commit mutations, transaction: nil
135
138
  mode = transaction.nil? ? :NON_TRANSACTIONAL : :TRANSACTIONAL
136
- service.commit project_id: project, mode: mode, mutations: mutations, transaction: transaction
139
+ service.commit project_id: project, database_id: database, mode: mode,
140
+ mutations: mutations, transaction: transaction
137
141
  end
138
142
 
139
143
  ##
140
144
  # Roll back a transaction.
141
145
  def rollback transaction
142
- service.rollback project_id: project, transaction: transaction
146
+ service.rollback project_id: project, database_id: database, transaction: transaction
143
147
  end
144
148
 
145
149
  def inspect
146
- "#{self.class}(#{@project})"
150
+ "#{self.class}(#{@project})(#{database})"
147
151
  end
148
152
 
149
153
  protected
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Datastore
19
- VERSION = "2.4.0".freeze
19
+ VERSION = "2.5.0".freeze
20
20
  end
21
21
  end
22
22
  end
@@ -74,6 +74,8 @@ module Google
74
74
  # If the param is nil, uses the default endpoint.
75
75
  # @param [String] emulator_host Datastore emulator host. Optional.
76
76
  # If the param is nil, uses the value of the `emulator_host` config.
77
+ # @param [String] database_id Identifier for a Datastore database in the project. If not
78
+ # present, the default database of the project will be used.
77
79
  # @param [String] project Alias for the `project_id` argument. Deprecated.
78
80
  # @param [String] keyfile Alias for the `credentials` argument.
79
81
  # Deprecated.
@@ -103,13 +105,15 @@ module Google
103
105
  timeout: nil,
104
106
  endpoint: nil,
105
107
  emulator_host: nil,
108
+ database_id: nil,
106
109
  project: nil,
107
110
  keyfile: nil
108
- project_id ||= (project || default_project_id)
109
- scope ||= configure.scope
110
- timeout ||= configure.timeout
111
- endpoint ||= configure.endpoint
111
+ project_id = get_project_id project_id, project
112
+ scope ||= configure.scope
113
+ timeout ||= configure.timeout
114
+ endpoint ||= configure.endpoint
112
115
  emulator_host ||= configure.emulator_host
116
+ database_id ||= configure.database_id
113
117
 
114
118
  if emulator_host
115
119
  project_id = project_id.to_s # Always cast to a string
@@ -117,7 +121,7 @@ module Google
117
121
 
118
122
  return Datastore::Dataset.new(
119
123
  Datastore::Service.new(
120
- project_id, :this_channel_is_insecure,
124
+ project_id, :this_channel_is_insecure, database_id,
121
125
  host: emulator_host, timeout: timeout
122
126
  )
123
127
  )
@@ -136,7 +140,7 @@ module Google
136
140
 
137
141
  Datastore::Dataset.new(
138
142
  Datastore::Service.new(
139
- project_id, credentials,
143
+ project_id, credentials, database_id,
140
144
  host: endpoint, timeout: timeout
141
145
  )
142
146
  )
@@ -175,6 +179,14 @@ module Google
175
179
  Google::Cloud.configure.datastore
176
180
  end
177
181
 
182
+ ##
183
+ # @private Default project.
184
+ def self.get_project_id project_id, project
185
+ project_id || project || Google::Cloud.configure.datastore.project_id ||
186
+ Google::Cloud.configure.project_id ||
187
+ Google::Cloud.env.project_id
188
+ end
189
+
178
190
  ##
179
191
  # @private Default project.
180
192
  def self.default_project_id
@@ -67,9 +67,10 @@ module Google
67
67
  # platform_scope = "https://www.googleapis.com/auth/cloud-platform"
68
68
  # datastore = gcloud.datastore scope: platform_scope
69
69
  #
70
- def datastore scope: nil, timeout: nil
70
+ def datastore scope: nil, timeout: nil, database_id: nil
71
71
  Google::Cloud.datastore @project, @keyfile,
72
- scope: scope, timeout: (timeout || @timeout)
72
+ scope: scope, timeout: (timeout || @timeout),
73
+ database_id: database_id
73
74
  end
74
75
 
75
76
  ##
@@ -112,11 +113,12 @@ module Google
112
113
  # datastore.save task
113
114
  #
114
115
  def self.datastore project_id = nil, credentials = nil, scope: nil,
115
- timeout: nil
116
+ timeout: nil, database_id: nil
116
117
  require "google/cloud/datastore"
117
118
  Google::Cloud::Datastore.new project_id: project_id,
118
119
  credentials: credentials,
119
- scope: scope, timeout: timeout
120
+ scope: scope, timeout: timeout,
121
+ database_id: database_id
120
122
  end
121
123
  end
122
124
  end
@@ -136,8 +138,7 @@ Google::Cloud.configure.add_config! :datastore do |config|
136
138
  ENV["DATASTORE_EMULATOR_HOST"]
137
139
  end
138
140
  default_scopes = [
139
- "https://www.googleapis.com/auth/cloud-platform",
140
- "https://www.googleapis.com/auth/datastore"
141
+ "https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/datastore"
141
142
  ]
142
143
 
143
144
  config.add_field! :project_id, default_project, match: String, allow_nil: true
@@ -149,4 +150,5 @@ Google::Cloud.configure.add_config! :datastore do |config|
149
150
  config.add_field! :timeout, nil, match: Integer
150
151
  config.add_field! :emulator_host, default_emulator, match: String, allow_nil: true
151
152
  config.add_field! :endpoint, "datastore.googleapis.com", match: String
153
+ config.add_field! :database_id, "", match: String
152
154
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-datastore
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-02-03 00:00:00.000000000 Z
12
+ date: 2023-02-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-cloud-core