google-cloud-spanner 1.3.1 → 1.4.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: 3ed2386d9ad779724db65c4f41c42e78271e5cd94fe6785bb576083057b8cfae
4
- data.tar.gz: 19a748cfaf89324614928996273a424aa0416d3804c60aa86eb6404736f2c30e
3
+ metadata.gz: 1e9faf33e2e5945db9c82ec262ec12b68c703cdfa42413d1c2da9605bcacca88
4
+ data.tar.gz: dabf39029f6106cc4f3a6d126e32a46e77cf06120f41a4ecf7c0ab4460cfb6c5
5
5
  SHA512:
6
- metadata.gz: bd287ff170bdd0c48aad7407b8a7cf92af5e0cc1479396a477c579e01d15de61c5f8d1e935fd54bff9ed035f35f66788aaec17b26a96695374d203644702fa88
7
- data.tar.gz: 4fe37f4d9e0b166a941fb631704e43e54a698e1eba6b74d7c16b2afc7fc6dc9e5b39e947e3f3a99d2035302f8eb2949913fca2e35fb922942f2f74599c125ecf
6
+ metadata.gz: a0e446f217517f5feeb2f342694d57a83981e782a6d2586ba4182b18d06c536aa24c2a2527a064d76af5e317d57ce313b6ad689422a92f2a138ade9410ef5571
7
+ data.tar.gz: a3ee7508a48f04a77e4b42ee809a6bdcd3134e7b25fb27349283e27e61754ae34d05d7c9a98b0fc6c66bed1deda69dd828e0fd4626c120ba9d95500b145cd1cf
@@ -21,6 +21,7 @@ require "google/cloud/spanner/session"
21
21
  require "google/cloud/spanner/transaction"
22
22
  require "google/cloud/spanner/snapshot"
23
23
  require "google/cloud/spanner/range"
24
+ require "google/cloud/spanner/column_value"
24
25
  require "google/cloud/spanner/convert"
25
26
 
26
27
  module Google
@@ -936,6 +937,35 @@ module Google
936
937
  exclude_end: exclude_end
937
938
  end
938
939
 
940
+ ##
941
+ # Creates a column value object representing setting a field's value to
942
+ # the timestamp of the commit. (See {ColumnValue.commit_timestamp})
943
+ #
944
+ # This placeholder value can only be used for timestamp columns that
945
+ # have set the option "(allow_commit_timestamp=true)" in the schema.
946
+ #
947
+ # @return [ColumnValue] The commit timestamp column value object.
948
+ #
949
+ # @example
950
+ # require "google/cloud/spanner"
951
+ #
952
+ # spanner = Google::Cloud::Spanner.new
953
+ #
954
+ # db = spanner.client "my-instance", "my-database"
955
+ #
956
+ # # create column value object
957
+ # commit_timestamp = db.commit_timestamp
958
+ #
959
+ # db.commit do |c|
960
+ # c.insert "users", [
961
+ # { id: 5, name: "Murphy", updated_at: commit_timestamp }
962
+ # ]
963
+ # end
964
+ #
965
+ def commit_timestamp
966
+ ColumnValue.commit_timestamp
967
+ end
968
+
939
969
  ##
940
970
  # Closes the client connection and releases resources.
941
971
  #
@@ -0,0 +1,115 @@
1
+ # Copyright 2018 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ module Google
17
+ module Cloud
18
+ module Spanner
19
+ ##
20
+ # # ColumnValue
21
+ #
22
+ # Represents a change to be made to a row's column value by the Spanner
23
+ # API.
24
+ #
25
+ # @example
26
+ # require "google/cloud/spanner"
27
+ #
28
+ # spanner = Google::Cloud::Spanner.new
29
+ #
30
+ # db = spanner.client "my-instance", "my-database"
31
+ #
32
+ # # create column value object
33
+ # commit_timestamp = db.commit_timestamp
34
+ #
35
+ # db.commit do |c|
36
+ # c.insert "users", [
37
+ # { id: 5, name: "Murphy", updated_at: commit_timestamp }
38
+ # ]
39
+ # end
40
+ #
41
+ class ColumnValue
42
+ ##
43
+ # @private Creates a column value object representing changes made to
44
+ # fields in document data.
45
+ def initialize type
46
+ @type = type
47
+ end
48
+
49
+ ##
50
+ # @private
51
+ # The type of change to make to a row's column value.
52
+ #
53
+ # @return [Symbol] The type of the column value.
54
+ #
55
+ # @example
56
+ # require "google/cloud/spanner"
57
+ #
58
+ # spanner = Google::Cloud::Spanner.new
59
+ #
60
+ # db = spanner.client "my-instance", "my-database"
61
+ #
62
+ # # create column value object
63
+ # commit_timestamp = db.commit_timestamp
64
+ #
65
+ # db.commit do |c|
66
+ # c.insert "users", [
67
+ # { id: 5, name: "Murphy", updated_at: commit_timestamp }
68
+ # ]
69
+ # end
70
+ #
71
+ def type
72
+ @type
73
+ end
74
+
75
+ ##
76
+ # Creates a column value object representing setting a field's value to
77
+ # the timestamp of the commit. (See {Client#commit_timestamp} and
78
+ # {Transaction#commit_timestamp})
79
+ #
80
+ # This placeholder value can only be used for timestamp columns that
81
+ # have set the option "(allow_commit_timestamp=true)" in the schema.
82
+ #
83
+ # @return [ColumnValue] The commit timestamp column value object.
84
+ #
85
+ # @example
86
+ # require "google/cloud/spanner"
87
+ #
88
+ # spanner = Google::Cloud::Spanner.new
89
+ #
90
+ # db = spanner.client "my-instance", "my-database"
91
+ #
92
+ # # create column value object
93
+ # commit_timestamp = \
94
+ # Google::Cloud::Spanner::ColumnValue.commit_timestamp
95
+ #
96
+ # db.commit do |c|
97
+ # c.insert "users", [
98
+ # { id: 5, name: "Murphy", updated_at: commit_timestamp }
99
+ # ]
100
+ # end
101
+ #
102
+ def self.commit_timestamp
103
+ new :commit_timestamp
104
+ end
105
+
106
+ ##
107
+ # @private The actual value that is sent to Spanner for the field.
108
+ def to_column_value
109
+ # We only have one ColumnValue, so hard-code this for now.
110
+ "spanner.commit_timestamp()"
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
@@ -37,6 +37,7 @@ module Google
37
37
  end
38
38
 
39
39
  def raw_to_value_and_type obj, type = nil
40
+ obj = obj.to_column_value if obj.respond_to? :to_column_value
40
41
  if NilClass === obj
41
42
  if type
42
43
  if type.is_a?(Array) && type.count == 1
@@ -115,6 +116,8 @@ module Google
115
116
  end
116
117
 
117
118
  def raw_to_value obj
119
+ obj = obj.to_column_value if obj.respond_to? :to_column_value
120
+
118
121
  if NilClass === obj
119
122
  Google::Protobuf::Value.new null_value: :NULL_VALUE
120
123
  elsif String === obj
@@ -503,6 +503,32 @@ module Google
503
503
  exclude_end: exclude_end
504
504
  end
505
505
 
506
+ ##
507
+ # Creates a column value object representing setting a field's value to
508
+ # the timestamp of the commit. (See {Client#commit_timestamp})
509
+ #
510
+ # This placeholder value can only be used for timestamp columns that
511
+ # have set the option "(allow_commit_timestamp=true)" in the schema.
512
+ #
513
+ # @return [ColumnValue] The commit timestamp column value object.
514
+ #
515
+ # @example
516
+ # require "google/cloud/spanner"
517
+ #
518
+ # spanner = Google::Cloud::Spanner.new
519
+ #
520
+ # db = spanner.client "my-instance", "my-database"
521
+ #
522
+ # db.transaction do |tx|
523
+ # tx.insert "users", [
524
+ # { id: 5, name: "Murphy", updated_at: tx.commit_timestamp }
525
+ # ]
526
+ # end
527
+ #
528
+ def commit_timestamp
529
+ ColumnValue.commit_timestamp
530
+ end
531
+
506
532
  ##
507
533
  # @private
508
534
  # Keeps the transaction current by creating a new transaction.
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Spanner
19
- VERSION = "1.3.1".freeze
19
+ VERSION = "1.4.0".freeze
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-spanner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.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: 2018-02-27 00:00:00.000000000 Z
12
+ date: 2018-03-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-cloud-core
@@ -228,6 +228,7 @@ files:
228
228
  - lib/google/cloud/spanner/batch_client.rb
229
229
  - lib/google/cloud/spanner/batch_snapshot.rb
230
230
  - lib/google/cloud/spanner/client.rb
231
+ - lib/google/cloud/spanner/column_value.rb
231
232
  - lib/google/cloud/spanner/commit.rb
232
233
  - lib/google/cloud/spanner/convert.rb
233
234
  - lib/google/cloud/spanner/credentials.rb