sessionm-cassandra_object 4.0.10 → 4.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- M2Q1NWZkM2IwNWRiNmE0MTZjYTQzMTIxMDljOGM5NWJiNjEyOGQ5Nw==
5
- data.tar.gz: !binary |-
6
- MmM3MWFjYTYzY2FhZjE4ZjZiZGM5NzJkYTU1YTU2MGIxYzM0ZTVlOA==
2
+ SHA1:
3
+ metadata.gz: 1e09d42c44da63c37887407613d4abfab560b4ba
4
+ data.tar.gz: d712eee439e1832cee073e0829b235016b1248ff
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- M2UyNTUxMWIyNjNhZmVkYmIyNmJmOTZkZGNmYmZiYTk2ZmU0NTM4OTZlMjdj
10
- NWUwNTMxM2ZiNjdiYWE0M2QzOTY2OTJiNTBjYmNjYTU1MjFjZDE0ZGQyYWZh
11
- MmMzOWRjNDc4ZDAwYmUzMTYxYjdiNTg3YjliODNkM2I0MmUwZGM=
12
- data.tar.gz: !binary |-
13
- MWIxZjU2YTczYWIyYjY2MjUxNzI4OGI0YzM1ZjZhYzc1Mjg4OTk4NGNkZTQy
14
- ZTczNTFmYTBhMGI3YzU3YjNkMjk3NzM1Zjk5ZjUyYTVlMmQ3ZDQwMDhlOGUz
15
- NjVmYTk3ZTRlNDQ4YzEzZmI1YjViOWMyMzljMDQwOTdlOWRiZmM=
6
+ metadata.gz: 2a72f143c68b66fb4b29f88968504e50ad361af01d22c40316047142863ec87136bb0402ad570d59a36851151d7e6e84066e7dd0eaf0cd350fc23abb484f4c1d
7
+ data.tar.gz: 617502c23d8ecb0f42b07f423ebfa180ec4d228e5f4a3ae48cd73b39895dc534decf3edc4fa79d5aabdb4b1097e8304cec787d63b1ea88b38ae888c1d6d73d45
@@ -75,7 +75,7 @@ module CassandraObject
75
75
 
76
76
  query = "BEGIN BATCH\n"
77
77
  query << values.map do |name, value|
78
- " INSERT INTO \"#{column_family}\" (#{KEY_FIELD}, #{NAME_FIELD}, #{VALUE_FIELD}) VALUES (#{key}, '#{name}', '#{value}')#{insert_into_options}"
78
+ " INSERT INTO \"#{column_family}\" (#{KEY_FIELD}, #{NAME_FIELD}, #{VALUE_FIELD}) VALUES (#{key}, #{escape(name, opts.try(:[], :name_type))}, #{escape(value, opts.try(:[], :value_type))})#{insert_into_options}"
79
79
  end.join("\n")
80
80
  query << "\nAPPLY BATCH;"
81
81
 
@@ -171,6 +171,24 @@ module CassandraObject
171
171
  results
172
172
  end
173
173
 
174
+ def get_slice(column_family, key, column, start, finish, count, reversed, consistency, opts={})
175
+ opts[:consistency] = consistency
176
+
177
+ key = "textAsBlob('#{key}')"
178
+
179
+ query = "SELECT * FROM \"#{column_family}\" WHERE #{KEY_FIELD} = #{key}"
180
+ query << " AND #{NAME_FIELD} = #{escape(column, opts[:name_type])}" if column
181
+ query << " AND #{NAME_FIELD} >= #{escape(start, opts[:name_type])}" unless start.empty?
182
+ query << " AND #{NAME_FIELD} <= #{escape(finish, opts[:name_type])}" unless finish.empty?
183
+ query << " ORDER BY #{NAME_FIELD} #{opts[:reverse_comparator] ? 'ASC' : 'DESC'}" if reversed
184
+ query << " LIMIT #{count}"
185
+
186
+ self.execute(query, execute_options(opts)).inject({}) do |results, row|
187
+ results[decode(row[NAME_FIELD], opts[:name_type])] = decode(row[VALUE_FIELD], opts[:value_type])
188
+ results
189
+ end
190
+ end
191
+
174
192
  def execute_options(opts)
175
193
  opts.try(:slice,
176
194
  :consistency,
@@ -224,6 +242,36 @@ CQL
224
242
 
225
243
  self.column_families[column_family.name.to_s] = column_family
226
244
  end
245
+
246
+ def escape(str, type)
247
+ case type
248
+ when :timeuuid
249
+ convert_str_to_timeuuid str
250
+ when :blob
251
+ convert_str_to_hex str
252
+ else
253
+ "'#{str}'"
254
+ end
255
+ end
256
+
257
+ def decode(val, type)
258
+ case type
259
+ when :timeuuid
260
+ SimpleUUID::UUID.new(val.to_s).to_s # binary version
261
+ else
262
+ val
263
+ end
264
+ end
265
+
266
+ # when the column names are timeuuid
267
+ def convert_str_to_timeuuid(str)
268
+ SimpleUUID::UUID.new(str).to_guid
269
+ end
270
+
271
+ # insert a blob
272
+ def convert_str_to_hex(str)
273
+ '0x' << str.unpack('H*').first
274
+ end
227
275
  end
228
276
  end
229
277
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'sessionm-cassandra_object'
5
- s.version = '4.0.10'
5
+ s.version = '4.0.11'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
 
9
- s.authors = ["Michael Koziarski", "gotime", "sessionm"]
9
+ s.authors = ["Doug Youch", "sessionm"]
10
10
  s.email = 'doug@sessionm.com'
11
11
  s.homepage = 'http://github.com/sessionm/cassandra_object'
12
12
 
metadata CHANGED
@@ -1,16 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sessionm-cassandra_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.10
4
+ version: 4.0.11
5
5
  platform: ruby
6
6
  authors:
7
- - Michael Koziarski
8
- - gotime
7
+ - Doug Youch
9
8
  - sessionm
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2015-12-22 00:00:00.000000000 Z
12
+ date: 2016-02-26 00:00:00.000000000 Z
14
13
  dependencies: []
15
14
  description: Cassandra ActiveModel
16
15
  email: doug@sessionm.com
@@ -19,9 +18,9 @@ extensions: []
19
18
  extra_rdoc_files:
20
19
  - README.markdown
21
20
  files:
22
- - .gitignore
23
- - .ruby-gemset
24
- - .ruby-version
21
+ - ".gitignore"
22
+ - ".ruby-gemset"
23
+ - ".ruby-version"
25
24
  - CHANGELOG
26
25
  - Gemfile
27
26
  - Gemfile.lock
@@ -142,12 +141,12 @@ require_paths:
142
141
  - lib
143
142
  required_ruby_version: !ruby/object:Gem::Requirement
144
143
  requirements:
145
- - - ! '>='
144
+ - - ">="
146
145
  - !ruby/object:Gem::Version
147
146
  version: '0'
148
147
  required_rubygems_version: !ruby/object:Gem::Requirement
149
148
  requirements:
150
- - - ! '>='
149
+ - - ">="
151
150
  - !ruby/object:Gem::Version
152
151
  version: '0'
153
152
  requirements: []