cassandro 1.0.7 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjFhNGEwMGIyYTgyOTkyMmExODA3NGZlZDJiNGJkM2ZjNzM2Nzk0Zg==
4
+ MGY2MDljZDAzYjFhOGZmYzZhZjM4MjE0YTcyOTIwNDYxZTIwNTQ4OA==
5
5
  data.tar.gz: !binary |-
6
- ZjMxYzk2YWY1ODM2MGZjOWVjYTk2ZmE1ZWJmMDk1ZWQ0NDZiMzQyNw==
6
+ Y2M3MTA2ZTVjMGJkOTZjNTdiNWZmNGY0NzE0YzU4ZjMyNTM3NmFmNw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZjNlZjIyMjQ5ZWY3MjliMWNiMDZmNGE1NmI0Y2ZiYWRhYTJjNTY1NmQ1ZDIx
10
- MWE1MmRmMzRkOTRiNmU0OTczN2NiOTBkODI0NDMwNGIyYTAwMjFkMWFmNGIx
11
- OWYzOWI1ZGNlOWUzYjBlOGE5NGI1ZDAzYjY4MzdlMWVlY2FhZmQ=
9
+ MjNjYjQ5MjA5MmJmZGNmMjVlZWE3NWRkNzdlYWQ5OTg1NWVhZjlhMmU0OTE1
10
+ N2E5NjNjZGVlNTFjZDE2NDAwNTJmMWY4ZmIyMzRkMWMyN2M1ODU1OTE0ODBi
11
+ MDhkODlhN2FmMjhkNWM3NjJlYWRiNzBhNmRlZDU5MjFlZTNlYWE=
12
12
  data.tar.gz: !binary |-
13
- YWEyNGJlZWY1MDVmYjVhZDRiMDRkODczM2YwMDZkYTEzYWVjMmNjNTllNGJk
14
- NjhmOGZjNWE2YzAyYWM4ZmNhMzMyYjUxZTM3ZTFjNDQ4MzFiODEzZmQwNjNi
15
- ZTgzNzZkNmQ5MmFhOTJhZTQxNzRmOTM0N2RhYmQ0NzNkNTkwMzY=
13
+ MDc2OTk4YTA4NDc3MzI1MGZmMmViMWYxYjdjMjBkNGFiYTIyNjI4MmVlMDIz
14
+ ZGM5N2EzZDk1Y2ZlYjM0N2IwMmJmODM1NWU4ZWNkNDkxMmM3NDFjYmUzMTIy
15
+ ZTdlZDQ4MmRhMGRlOTM1YzAwMGNjYTZmYmMwZTM0YTU4MjY2ZGY=
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "cassandro"
5
- s.version = "1.0.7"
5
+ s.version = "1.1.0"
6
6
  s.summary = "Ruby ORM for Apache Cassandra"
7
7
  s.license = "MIT"
8
8
  s.description = "Lightweight Apache Cassandra ORM for Ruby"
@@ -152,10 +152,14 @@ module Cassandro
152
152
  end
153
153
 
154
154
  def self.[](value)
155
+ return nil if value.nil? || (value.respond_to?(:empty?) && value.empty?)
156
+
155
157
  if value.is_a?(Hash)
156
- where = "#{value.map { |k,v| "#{k.to_s} = #{cast_as(k, v)}" }.join(' AND ')} ALLOW FILTERING"
158
+ where = "#{value.keys.map{ |k| "#{k} = ?" }.join(' AND ')} ALLOW FILTERING"
159
+ values = value.map{ |k,v| casts[k] == :uuid ? Cassandra::Uuid.new(v) : v }
157
160
  else
158
- where = "#{partition_key} = #{cast_as(partition_key, value)}"
161
+ where = "#{partition_key} = ?"
162
+ values = [casts[partition_key] == :uuid ? Cassandra::Uuid.new(value) : value]
159
163
  end
160
164
 
161
165
  query = <<-QUERY
@@ -164,7 +168,9 @@ module Cassandro
164
168
  WHERE #{where}
165
169
  QUERY
166
170
 
167
- result = Cassandro.execute(query)
171
+ st = Cassandro.client.prepare(query)
172
+ result = Cassandro.client.execute(st, *values)
173
+
168
174
  return nil unless result.any?
169
175
 
170
176
  self.new(result.first, true)
@@ -204,12 +210,17 @@ module Cassandro
204
210
  results
205
211
  end
206
212
 
207
- def self.count(key, value)
208
- key = key.to_sym
209
- query = "SELECT count(*) FROM #{table_name} WHERE #{key} = ? ALLOW FILTERING"
213
+ def self.count(key = nil, value = nil)
214
+ query = "SELECT count(*) FROM #{table_name}"
210
215
 
211
- st = Cassandro.client.prepare(query)
212
- results = Cassandro.client.execute(st, value)
216
+ if key && value
217
+ key = key.to_sym
218
+ query << " WHERE #{key} = ? ALLOW FILTERING"
219
+ st = Cassandro.client.prepare(query)
220
+ results = Cassandro.client.execute(st, value)
221
+ else
222
+ results = Cassandro.client.execute(query)
223
+ end
213
224
 
214
225
  results.first["count"]
215
226
  end
@@ -47,7 +47,7 @@ Protest.describe "Cassandro Model" do
47
47
  test "allows setting and getting attributes" do
48
48
  uuid = SecureRandom.uuid
49
49
  test = Test.new(test_col_1: uuid, test_col_2: 'test_value_2')
50
- assert_equal uuid, test.test_col_1
50
+ assert_equal uuid.to_s, test.test_col_1
51
51
  assert_equal 'test_value_2', test.test_col_2
52
52
  end
53
53
  end
@@ -124,9 +124,35 @@ Protest.describe "Cassandro Model" do
124
124
  uuid = SecureRandom.uuid
125
125
  Test.create(test_col_1: uuid, test_col_2: 'test_value_2')
126
126
  test = Test[uuid]
127
- assert_equal uuid, test.test_col_1.to_s
127
+ assert_equal uuid.to_s, test.test_col_1.to_s
128
128
  assert_equal "test_value_2", test.test_col_2
129
129
  end
130
+
131
+ test "gets row with nil or empty values" do
132
+ test = Test[nil]
133
+ assert_equal nil, test
134
+
135
+ test = Test[""]
136
+ assert_equal nil, test
137
+
138
+ test = Test[{}]
139
+ assert_equal nil, test
140
+ end
141
+
142
+ test "counts the rows" do
143
+ Test.create(test_col_1: SecureRandom.uuid, test_col_2: 'test_value_2')
144
+ Test.create(test_col_1: SecureRandom.uuid, test_col_2: 'test_value_2')
145
+
146
+ assert_equal Test.all.size, Test.count
147
+ end
148
+
149
+ test "counts the rows with filter" do
150
+ uuid = SecureRandom.uuid
151
+ Test.create(test_col_1: uuid, test_col_2: 'test_value_2')
152
+ Test.create(test_col_1: SecureRandom.uuid, test_col_2: 'test_value_2')
153
+
154
+ assert_equal 1, Test.count(:test_col_1, Cassandra::Uuid.new(uuid))
155
+ end
130
156
  end
131
157
 
132
158
  context 'Updating' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cassandro
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lautaro Orazi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-06 00:00:00.000000000 Z
12
+ date: 2015-03-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cassandra-driver