sessionm-cassandra_object 4.0.26 → 4.0.27

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: c95d37c29798d4b4b4a205482e29246e5704fe10
4
- data.tar.gz: 99e1416d2948790d7afa64b111321349f3c1c440
3
+ metadata.gz: 1c93aa37334ac497b7c97b5c0a1c04350502e230
4
+ data.tar.gz: 894c0e7ffac48271d0efa1b75defe0c67f7c3b47
5
5
  SHA512:
6
- metadata.gz: 66d3159473f341ec86f13c8e51b9c9951feb0a23ee24c2e3fda3504a1740320322798252528fae9ec76a16fabf864648a4ecb92ec18bbf9c446167e384e4cb60
7
- data.tar.gz: 61a629a5df9908850bdcaba861044a745d9873e250a28c7e40e9fce33e253f48e9e0822e88699cef0c64cdea809b60d52f27fabdd502a9ad08a4071bc6cbcb4d
6
+ metadata.gz: 4162a2b08feefbe4ed8cffa60826421344b6982f4e82b31627495dcf2e6dcfbe2f3af4cc666051918a868d2e410a9d97077f34c14e2d651c164206870a24684d
7
+ data.tar.gz: 936877179c08b6e3b3ffdf4d74d7384bc3da5e32dbafb29f4d361daa10b2a417be76e20fee99139858a7db7399aa495400112aee04a4882258eef77d9e899c70
@@ -99,13 +99,18 @@ module CassandraObject
99
99
 
100
100
  insert_into_options = ttl ? " USING TTL #{ttl}" : ''
101
101
 
102
- query = "BEGIN BATCH\n"
103
- query << values.map do |name, value|
104
- " INSERT INTO \"#{column_family}\" (#{KEY_FIELD}, #{NAME_FIELD}, #{VALUE_FIELD}) VALUES (#{escape(key, key_type(column_family))}, #{escape(name, name_type(column_family))}, #{escape(value, value_type(column_family))})#{insert_into_options}"
102
+ insert_query = values.map do |name, value|
103
+ " INSERT INTO \"#{column_family}\" (#{KEY_FIELD}, #{NAME_FIELD}, #{VALUE_FIELD}) VALUES (#{escape(key, key_type(column_family))}, #{escape(name, name_type(column_family))}, #{escape(value, value_type(column_family))})#{insert_into_options}"
105
104
  end.join("\n")
106
- query << "\nAPPLY BATCH;"
107
105
 
108
- async ? self.execute_async(query, execute_options(opts)) : self.execute(query, execute_options(opts))
106
+ if batch_mode?
107
+ @batched_queries << insert_query
108
+ else
109
+ query = "BEGIN BATCH\n"
110
+ query << insert_query
111
+ query << "\nAPPLY BATCH;"
112
+ async ? self.execute_async(query, execute_options(opts)) : self.execute(query, execute_options(opts))
113
+ end
109
114
  end
110
115
 
111
116
  def get(column_family, key, *columns_options)
@@ -261,8 +266,28 @@ module CassandraObject
261
266
  @column_families ||= self.cluster.keyspace(session.keyspace).tables.inject({}) { |hsh, table| hsh[table.name] = table; hsh }
262
267
  end
263
268
 
264
- def batch
265
- yield
269
+ def batch_mode?
270
+ !! @batched_queries
271
+ end
272
+
273
+ def batch(opts=false)
274
+ if @batched_queries
275
+ yield
276
+ else
277
+ begin
278
+ async = opts.try(:[], :async)
279
+ @batched_queries ||= []
280
+ yield
281
+ query = "BEGIN BATCH\n"
282
+ query << @batched_queries.join("\n")
283
+ query << "\nAPPLY BATCH;"
284
+ async ? self.execute_async(query, execute_options(opts)) : self.execute(query, execute_options(opts))
285
+ rescue Exception => e
286
+ raise e
287
+ ensure
288
+ @batched_queries = nil
289
+ end
290
+ end
266
291
  end
267
292
 
268
293
  def schema(reload=false)
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'sessionm-cassandra_object'
5
- s.version = '4.0.26'
5
+ s.version = '4.0.27'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sessionm-cassandra_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.26
4
+ version: 4.0.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doug Youch
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-12-04 00:00:00.000000000 Z
12
+ date: 2017-12-05 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Cassandra ActiveModel
15
15
  email: doug@sessionm.com