baza 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "baza"
8
- s.version = "0.0.7"
8
+ s.version = "0.0.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kasper Johansen"]
@@ -195,7 +195,7 @@ class Baza::Db
195
195
 
196
196
  #Clones the current database-connection with possible extra arguments.
197
197
  def clone_conn(args = {})
198
- conn = Baza::Db.new(@opts.clone.merge(args))
198
+ conn = Baza::Db.new(opts = @opts.clone.merge(args))
199
199
 
200
200
  if block_given?
201
201
  begin
@@ -609,7 +609,7 @@ class Baza::Db
609
609
  end
610
610
  end
611
611
 
612
- raise "Could not figure out how to find a driver to use?"
612
+ raise "Could not figure out which driver to use?"
613
613
  end
614
614
 
615
615
  #Executes a query and returns the result.
@@ -835,6 +835,8 @@ class Baza::Db
835
835
  self.conn_exec do |driver|
836
836
  driver.transaction(&block)
837
837
  end
838
+
839
+ return nil
838
840
  end
839
841
 
840
842
  #Optimizes all tables in the database.
@@ -397,8 +397,10 @@ class Baza::Driver::Mysql
397
397
 
398
398
  begin
399
399
  yield(@knjdb)
400
- ensure
401
400
  @knjdb.q("COMMIT")
401
+ rescue
402
+ @knjdb.q("ROLLBACK")
403
+ raise
402
404
  end
403
405
  end
404
406
  end
@@ -15,12 +15,25 @@ class Baza::QueryBuffer
15
15
  STDOUT.puts "Query buffer started." if @debug
16
16
 
17
17
  if block_given?
18
- begin
19
- yield(self)
20
- ensure
21
- self.flush
22
- thread_async_join
23
- end
18
+ if @args[:flush_async]
19
+ @args[:db].clone_conn do |db_flush_async|
20
+ @db_flush_async = db_flush_async
21
+
22
+ begin
23
+ yield(self)
24
+ ensure
25
+ flush
26
+ thread_async_join
27
+ end
28
+ end
29
+ else
30
+ begin
31
+ yield(self)
32
+ ensure
33
+ flush
34
+ thread_async_join
35
+ end
36
+ end
24
37
  end
25
38
  end
26
39
 
@@ -32,7 +45,7 @@ class Baza::QueryBuffer
32
45
  @queries_count += 1
33
46
  end
34
47
 
35
- self.flush if @queries_count >= 1000
48
+ flush if @queries_count >= 1000
36
49
  return nil
37
50
  end
38
51
 
@@ -41,7 +54,7 @@ class Baza::QueryBuffer
41
54
  # buffer.delete(:users, {:id => 5})
42
55
  def delete(table, where)
43
56
  STDOUT.puts "Delete called on table #{table} with arguments: '#{where}'." if @debug
44
- self.query(@args[:db].delete(table, where, :return_sql => true))
57
+ query(@args[:db].delete(table, where, :return_sql => true))
45
58
  return nil
46
59
  end
47
60
 
@@ -50,7 +63,7 @@ class Baza::QueryBuffer
50
63
  # buffer.update(:users, {:name => "Kasper"}, {:id => 5})
51
64
  def update(table, update, terms)
52
65
  STDOUT.puts "Update called on table #{table}." if @debug
53
- self.query(@args[:db].update(table, update, terms, :return_sql => true))
66
+ query(@args[:db].update(table, update, terms, :return_sql => true))
54
67
  return nil
55
68
  end
56
69
 
@@ -66,7 +79,7 @@ class Baza::QueryBuffer
66
79
  #===Examples
67
80
  # buffer.insert(:users, {:name => "John Doe"})
68
81
  def insert(table, data)
69
- self.query(@args[:db].insert(table, data, :return_sql => true))
82
+ query(@args[:db].insert(table, data, :return_sql => true))
70
83
  return nil
71
84
  end
72
85
 
@@ -86,7 +99,12 @@ class Baza::QueryBuffer
86
99
  thread_async_join
87
100
 
88
101
  @thread_async = Thread.new do
89
- flush_real
102
+ begin
103
+ flush_real(@db_flush_async)
104
+ rescue => e
105
+ $stderr.puts e.inspect
106
+ $stderr.puts e.backtrace
107
+ end
90
108
  end
91
109
  end
92
110
 
@@ -97,16 +115,17 @@ class Baza::QueryBuffer
97
115
  end
98
116
 
99
117
  #Flushes the queries for real.
100
- def flush_real
118
+ def flush_real(db = nil)
101
119
  return nil if @queries_count <= 0
120
+ db = @args[:db] if db == nil
102
121
 
103
122
  @lock.synchronize do
104
123
  if !@queries.empty?
105
124
  while !@queries.empty?
106
- @args[:db].transaction do
125
+ db.transaction do
107
126
  @queries.shift(1000).each do |str|
108
127
  STDOUT.print "Executing via buffer: #{str}\n" if @debug
109
- @args[:db].q(str)
128
+ db.q(str)
110
129
  end
111
130
  end
112
131
  end
@@ -115,7 +134,7 @@ class Baza::QueryBuffer
115
134
  @inserts.each do |table, datas_arr|
116
135
  while !datas_arr.empty?
117
136
  datas_chunk_arr = datas_arr.shift(1000)
118
- @args[:db].insert_multi(table, datas_chunk_arr)
137
+ @db.insert_multi(table, datas_chunk_arr)
119
138
  end
120
139
  end
121
140
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baza
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -235,7 +235,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
235
235
  version: '0'
236
236
  segments:
237
237
  - 0
238
- hash: 3943301269923844356
238
+ hash: 3231877095185720850
239
239
  required_rubygems_version: !ruby/object:Gem::Requirement
240
240
  none: false
241
241
  requirements: