cequel 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -58,11 +58,8 @@ module Cequel
58
58
  private :new
59
59
 
60
60
  def load(*keys)
61
- options = keys.extract_options!
62
61
  keys.flatten!
63
- batch_size = options[:columns] || options[:batch_size] ||
64
- default_batch_size
65
- column_family.select(:first => batch_size).
62
+ column_family.
66
63
  where(key_alias.to_s => keys).
67
64
  map { |row| new(row.delete(key_alias.to_s), row) }
68
65
  end
@@ -100,6 +97,21 @@ module Cequel
100
97
  end
101
98
  end
102
99
 
100
+ def first
101
+ @loaded ? @row.first : slice(:first => 1).first
102
+ end
103
+
104
+ def last
105
+ if @loaded
106
+ unless @row.empty?
107
+ key = @row.keys.last
108
+ [key, @row[key]]
109
+ end
110
+ else
111
+ slice(:last => 1).first
112
+ end
113
+ end
114
+
103
115
  def key?(column)
104
116
  @row.key?(column) || load_raw_slice([column])[column].present?
105
117
  end
@@ -1,3 +1,3 @@
1
1
  module Cequel
2
- VERSION = '0.5.0'
2
+ VERSION = '0.5.1'
3
3
  end
@@ -77,6 +77,24 @@ shared_examples 'readable dictionary' do
77
77
  end
78
78
  end
79
79
 
80
+ describe '#first' do
81
+ it 'should load value from data store' do
82
+ connection.should_receive(:execute).
83
+ with("SELECT FIRST 1 * FROM #{cf} WHERE ? = ? LIMIT 1", :blog_id, 1).
84
+ and_return result_stub('blog_id' => 1, uuid1 => 1)
85
+ dictionary.first.should == [uuid1, 1]
86
+ end
87
+ end
88
+
89
+ describe '#last' do
90
+ it 'should load value from data store' do
91
+ connection.should_receive(:execute).
92
+ with("SELECT FIRST 1 REVERSED * FROM #{cf} WHERE ? = ? LIMIT 1", :blog_id, 1).
93
+ and_return result_stub('blog_id' => 1, uuid3 => 3)
94
+ dictionary.last.should == [uuid3, 3]
95
+ end
96
+ end
97
+
80
98
  end
81
99
 
82
100
  context 'with data loaded in memory' do
@@ -116,6 +134,18 @@ shared_examples 'readable dictionary' do
116
134
  end
117
135
  end
118
136
 
137
+ describe '#first' do
138
+ it 'should return first element in memory' do
139
+ dictionary.first.should == [uuid1, 1]
140
+ end
141
+ end
142
+
143
+ describe '#last' do
144
+ it 'should return first element in memory' do
145
+ dictionary.last.should == [uuid3, 3]
146
+ end
147
+ end
148
+
119
149
  describe '#keys' do
120
150
  it 'should return keys from memory' do
121
151
  dictionary.keys.should == [uuid1, uuid2, uuid3]
@@ -140,7 +170,7 @@ shared_examples 'readable dictionary' do
140
170
  it 'should load all rows in one query' do
141
171
  connection.stub(:execute).
142
172
  with(
143
- 'SELECT FIRST 1000 * FROM post_comments WHERE ? IN (?)',
173
+ 'SELECT * FROM post_comments WHERE ? IN (?)',
144
174
  'post_id', [1, 2]
145
175
  ).and_return result_stub(
146
176
  *comments.each_with_index.
@@ -150,19 +180,6 @@ shared_examples 'readable dictionary' do
150
180
  rows.map { |row| row.post_id }.should == [1, 2]
151
181
  rows.map { |row| row.values.first }.should == comments
152
182
  end
153
-
154
- it 'should respect columns option' do
155
- connection.stub(:execute).
156
- with(
157
- 'SELECT FIRST 20 * FROM post_comments WHERE ? IN (?)',
158
- 'post_id', [1, 2]
159
- ).and_return result_stub(
160
- *comments.each_with_index.
161
- map { |comment, i| {'post_id' => i+1, i+4 => comment.to_json} }
162
- )
163
- rows = PostComments.load(1, 2, :columns => 20)
164
- rows.map { |row| row.post_id }.should == [1, 2]
165
- end
166
183
  end
167
184
 
168
185
  private
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: 0.5.0
4
+ version: 0.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-10-29 00:00:00.000000000 Z
14
+ date: 2012-10-30 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport