cequel 1.0.0 → 1.0.1

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
  SHA1:
3
- metadata.gz: df5fb851e4ce9dda4900d848faf903c32d63d069
4
- data.tar.gz: 38d3ea0bda230427ddb452269976612fc2519026
3
+ metadata.gz: cbbbc8b19ddcc607473f72539c53fb5aaf00aa7e
4
+ data.tar.gz: b417bdbf6d4308074b1c83cc348cd8370913252e
5
5
  SHA512:
6
- metadata.gz: b43b31556885f28cefc1c0285214448de5dcca189d3fbe414702bd887c4e7e20924affa0a5cc94cdfaa06acbd77c6418626b8ab136c974234d6bf8227f8ef8f4
7
- data.tar.gz: e8790f4c65c31b17ec3dc2bd2b838403cbd456e6a95e425a9adc11a8a2a9ec504727d6e842b377c6a8c9002c05a28b875be65736c6407c5e3c32d8303e1aa35c
6
+ metadata.gz: b7259fcb8ca0ce0ef51d8417b1060726c6de8579041a066dfaf676a43902bfe3d652e086eaf62552627f47579bef4314df04770a165cfd8af6ba4a43be64c277
7
+ data.tar.gz: f397e3c887fe4bfcecd4de9666b3b53885576a3cc192cdd3a6fb14ae3f432b55026bfd665ebb7f99f37034f6a255dfee39dcd8e764309e20d543b7cb57fd0034
@@ -12,6 +12,14 @@ module Cequel
12
12
  # @since 1.0.0
13
13
  #
14
14
  class Updater < Writer
15
+ #
16
+ # @see Writer#initialize
17
+ #
18
+ def initialize(*)
19
+ @column_updates = {}
20
+ super
21
+ end
22
+
15
23
  #
16
24
  # Directly set column values
17
25
  #
@@ -22,10 +30,7 @@ module Cequel
22
30
  #
23
31
  def set(data)
24
32
  data.each_pair do |column, value|
25
- prepare_upsert_value(value) do |binding, *values|
26
- statements << "#{column} = #{binding}"
27
- bind_vars.concat(values)
28
- end
33
+ column_updates[column.to_sym] = value
29
34
  end
30
35
  end
31
36
 
@@ -131,12 +136,28 @@ module Cequel
131
136
 
132
137
  private
133
138
 
139
+ attr_reader :column_updates
140
+
141
+ def empty?
142
+ super && column_updates.empty?
143
+ end
144
+
134
145
  def write_to_statement(statement)
146
+ prepare_column_updates
135
147
  statement.append("UPDATE #{table_name}")
136
148
  .append(generate_upsert_options)
137
149
  .append(" SET ")
138
150
  .append(statements.join(', '), *bind_vars)
139
151
  end
152
+
153
+ def prepare_column_updates
154
+ column_updates.each_pair do |column, value|
155
+ prepare_upsert_value(value) do |binding, *values|
156
+ statements << "#{column} = #{binding}"
157
+ bind_vars.concat(values)
158
+ end
159
+ end
160
+ end
140
161
  end
141
162
  end
142
163
  end
@@ -82,6 +82,9 @@ module Cequel
82
82
  # @option options [Boolean] :auto (false) automatically initialize this
83
83
  # key with a UUID value for new records. Only valid for `uuid` and
84
84
  # `timeuuid` columns.
85
+ # @option options [:asc,:desc] :order whether rows should be ordered
86
+ # ascending or descending by this column. Only valid for clustering
87
+ # columns
85
88
  # @return [void]
86
89
  #
87
90
  # @note {Associations::ClassMethods#belongs_to belongs_to} implicitly
@@ -102,7 +102,7 @@ module Cequel
102
102
  if options[:partition]
103
103
  table_schema.add_partition_key(name, type)
104
104
  else
105
- table_schema.add_key(name, type)
105
+ table_schema.add_key(name, type, options[:order])
106
106
  end
107
107
  end
108
108
 
@@ -1,4 +1,4 @@
1
1
  module Cequel
2
2
  # The current version of the library
3
- VERSION = '1.0.0'
3
+ VERSION = '1.0.1'
4
4
  end
@@ -152,6 +152,18 @@ describe Cequel::Metal::DataSet do
152
152
  cequel[:posts].where(row_keys).first[:categories].
153
153
  should == %w(Scalability Fault-Tolerance)
154
154
  end
155
+
156
+ it 'should use the last value set for a given column' do
157
+ cequel[:posts].insert(
158
+ row_keys.merge(title: 'Big Data',
159
+ body: 'Cassandra',
160
+ categories: ['Scalability']))
161
+ cequel[:posts].where(row_keys).update do
162
+ set(title: 'Bigger Data')
163
+ set(title: 'Even Bigger Data')
164
+ end
165
+ cequel[:posts].where(row_keys).first[:title].should == 'Even Bigger Data'
166
+ end
155
167
  end
156
168
 
157
169
  describe '#list_prepend' do
@@ -45,6 +45,28 @@ describe Cequel::Record::Schema do
45
45
  end
46
46
  end
47
47
 
48
+ context 'CQL3 table with reversed clustering column' do
49
+
50
+ let(:model) do
51
+ Class.new do
52
+ include Cequel::Record
53
+ self.table_name = 'posts'
54
+
55
+ key :blog_id, :uuid
56
+ key :id, :timeuuid, order: :desc
57
+ column :title, :text
58
+ end
59
+ end
60
+
61
+ before { model.synchronize_schema }
62
+ after { cequel.schema.drop_table(:posts) }
63
+ subject { cequel.schema.read_table(:posts) }
64
+
65
+ it 'should order clustering column descending' do
66
+ subject.clustering_columns.first.clustering_order.should == :desc
67
+ end
68
+ end
69
+
48
70
  context 'wide-row legacy table' do
49
71
  let(:legacy_model) do
50
72
  Class.new do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mat Brown
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-02-08 00:00:00.000000000 Z
15
+ date: 2014-02-09 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activesupport