baza 0.0.12 → 0.0.13

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.12
1
+ 0.0.13
data/baza.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "baza"
8
- s.version = "0.0.12"
8
+ s.version = "0.0.13"
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"]
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
28
28
  "baza.gemspec",
29
29
  "include/db.rb",
30
30
  "include/dbtime.rb",
31
+ "include/drivers/active_record/active_record.rb",
31
32
  "include/drivers/mysql/mysql.rb",
32
33
  "include/drivers/mysql/mysql_columns.rb",
33
34
  "include/drivers/mysql/mysql_indexes.rb",
data/include/db.rb CHANGED
@@ -28,7 +28,7 @@ class Baza::Db
28
28
  next unless File.directory?(fp)
29
29
 
30
30
  driver_file = "#{fp}/#{file}.rb"
31
- class_name = "#{file.slice(0, 1).to_s.upcase}#{file.slice(1, file.length)}".to_sym
31
+ class_name = StringCases.snake_to_camel(file).to_sym
32
32
 
33
33
  drivers << {
34
34
  :name => file,
@@ -54,7 +54,9 @@ class Baza::Db
54
54
  obj = const.from_object(args)
55
55
  if obj.is_a?(Hash) and obj[:type] == :success
56
56
  if obj[:args]
57
- return Baza::Db.new(obj[:args])
57
+ new_args = obj[:args]
58
+ new_args = new_args.merge(args[:new_args]) if args[:new_args]
59
+ return Baza::Db.new(new_args)
58
60
  else
59
61
  raise "Didnt know what to do."
60
62
  end
@@ -100,7 +102,7 @@ class Baza::Db
100
102
  @opts[:subtype] = "ironruby"
101
103
  end
102
104
 
103
- @type_cc = "#{@opts[:type].to_s.slice(0, 1).upcase}#{@opts[:type].to_s.slice(1, @opts[:type].to_s.length)}"
105
+ @type_cc = StringCases.snake_to_camel(@opts[:type])
104
106
  self.connect
105
107
  end
106
108
 
@@ -142,14 +144,14 @@ class Baza::Db
142
144
 
143
145
  thread_cur = Thread.current
144
146
  tid = self.__id__
145
- thread_cur[:knjdb] = {} if !thread_cur[:knjdb]
147
+ thread_cur[:baza] = {} if !thread_cur[:baza]
146
148
 
147
- if thread_cur[:knjdb][tid]
149
+ if thread_cur[:baza][tid]
148
150
  #An object has already been spawned - free that first to avoid endless "used" objects.
149
151
  self.free_thread
150
152
  end
151
153
 
152
- thread_cur[:knjdb][tid] = @conns.get_and_lock if !thread_cur[:knjdb][tid]
154
+ thread_cur[:baza][tid] = @conns.get_and_lock if !thread_cur[:baza][tid]
153
155
 
154
156
  #If block given then be ensure to free thread after yielding.
155
157
  if block_given?
@@ -166,9 +168,9 @@ class Baza::Db
166
168
  thread_cur = Thread.current
167
169
  tid = self.__id__
168
170
 
169
- if thread_cur[:knjdb] and thread_cur[:knjdb].key?(tid)
170
- db = thread_cur[:knjdb][tid]
171
- thread_cur[:knjdb].delete(tid)
171
+ if thread_cur[:baza] and thread_cur[:baza].key?(tid)
172
+ db = thread_cur[:baza][tid]
173
+ thread_cur[:baza].delete(tid)
172
174
  @conns.free(db) if @conns
173
175
  end
174
176
  end
@@ -584,11 +586,11 @@ class Baza::Db
584
586
  # str = driver.escape('something̈́')
585
587
  # end
586
588
  def conn_exec
587
- if tcur = Thread.current and tcur[:knjdb]
589
+ if tcur = Thread.current and tcur[:baza]
588
590
  tid = self.__id__
589
591
 
590
- if tcur[:knjdb].key?(tid)
591
- yield(tcur[:knjdb][tid])
592
+ if tcur[:baza].key?(tid)
593
+ yield(tcur[:baza][tid])
592
594
  return nil
593
595
  end
594
596
  end
@@ -779,7 +781,7 @@ class Baza::Db
779
781
  #Returns the table-module and spawns it if it isnt already spawned.
780
782
  def tables
781
783
  if !@tables
782
- require "#{File.dirname(__FILE__)}/drivers/#{@opts[:type]}/#{@opts[:type]}_tables" if (!@opts.key?(:require) or @opts[:require])
784
+ require "#{File.dirname(__FILE__)}/drivers/#{@opts[:type]}/#{@opts[:type]}_tables" if (!@opts.key?(:require) or @opts[:require]) unless Baza::Driver.const_get(@type_cc).const_defined?(:Tables)
783
785
  @tables = Baza::Driver.const_get(@type_cc).const_get(:Tables).new(
784
786
  :db => self
785
787
  )
@@ -791,7 +793,7 @@ class Baza::Db
791
793
  #Returns the columns-module and spawns it if it isnt already spawned.
792
794
  def cols
793
795
  if !@cols
794
- require "#{File.dirname(__FILE__)}/drivers/#{@opts[:type]}/#{@opts[:type]}_columns" if (!@opts.key?(:require) or @opts[:require])
796
+ require "#{File.dirname(__FILE__)}/drivers/#{@opts[:type]}/#{@opts[:type]}_columns" if (!@opts.key?(:require) or @opts[:require]) unless Baza::Driver.const_get(@type_cc).const_defined?(:Columns)
795
797
  @cols = Baza::Driver.const_get(@type_cc).const_get(:Columns).new(
796
798
  :db => self
797
799
  )
@@ -803,7 +805,7 @@ class Baza::Db
803
805
  #Returns the index-module and spawns it if it isnt already spawned.
804
806
  def indexes
805
807
  if !@indexes
806
- require "#{File.dirname(__FILE__)}/drivers/#{@opts[:type]}/#{@opts[:type]}_indexes" if (!@opts.key?(:require) or @opts[:require])
808
+ require "#{File.dirname(__FILE__)}/drivers/#{@opts[:type]}/#{@opts[:type]}_indexes" if (!@opts.key?(:require) or @opts[:require]) unless Baza::Driver.const_get(@type_cc).const_defined?(:Indexes)
807
809
  @indexes = Baza::Driver.const_get(@type_cc).const_get(:Indexes).new(
808
810
  :db => self
809
811
  )
@@ -815,7 +817,7 @@ class Baza::Db
815
817
  #Returns the SQLSpec-module and spawns it if it isnt already spawned.
816
818
  def sqlspecs
817
819
  if !@sqlspecs
818
- require "#{File.dirname(__FILE__)}/drivers/#{@opts[:type]}/#{@opts[:type]}_sqlspecs" if (!@opts.key?(:require) or @opts[:require])
820
+ require "#{File.dirname(__FILE__)}/drivers/#{@opts[:type]}/#{@opts[:type]}_sqlspecs" if (!@opts.key?(:require) or @opts[:require]) unless Baza::Driver.const_get(@type_cc).const_defined?(:Sqlspecs)
819
821
  @sqlspecs = Baza::Driver.const_get(@type_cc).const_get(:Sqlspecs).new(
820
822
  :db => self
821
823
  )
@@ -861,11 +863,16 @@ class Baza::Db
861
863
  end
862
864
  end
863
865
 
864
- raise "Method not found: #{method_name}"
866
+ raise "Method not found: '#{method_name}'."
865
867
  end
866
868
  end
867
869
 
868
870
  #Subclass that contains all the drivers as further subclasses.
869
871
  class Baza::Driver
870
-
872
+ #Autoloader for drivers.
873
+ def self.const_missing(name)
874
+ require_relative "drivers/#{StringCases.camel_to_snake(name)}/#{StringCases.camel_to_snake(name)}.rb"
875
+ raise LoadError, "Still not loaded: '#{name}'." unless Baza::Driver.const_defined?(name)
876
+ return Baza::Driver.const_get(name)
877
+ end
871
878
  end
@@ -0,0 +1,112 @@
1
+ class Baza::Driver::ActiveRecord
2
+ attr_reader :baza, :conn, :sep_table, :sep_col, :sep_val, :symbolize, :conn_type
3
+ attr_accessor :tables, :cols, :indexes
4
+
5
+ def self.from_object(args)
6
+ if args[:object].class.name.include?("ActiveRecord::ConnectionAdapters")
7
+ return {
8
+ :type => :success,
9
+ :args => {
10
+ :type => :active_record,
11
+ :conn => args[:object]
12
+ }
13
+ }
14
+ end
15
+
16
+ return nil
17
+ end
18
+
19
+ def initialize(baza)
20
+ @baza = baza
21
+ @conn = @baza.opts[:conn]
22
+ conn_name = @conn.class.name.to_s.downcase
23
+
24
+ if conn_name.include?("mysql")
25
+ @sep_table = "`"
26
+ @sep_col = "`"
27
+ @sep_val = "'"
28
+ @conn_type = :mysql
29
+ elsif conn_name.include?("sqlite")
30
+ @sep_table = "`"
31
+ @sep_col = "`"
32
+ @sep_val = "'"
33
+ @conn_type = :sqlite3
34
+ else
35
+ raise "Unknown type: '#{conn_name}'."
36
+ end
37
+ end
38
+
39
+ def query(str)
40
+ Baza::Driver::ActiveRecord::Result.new(self, @conn.execute(str))
41
+ end
42
+
43
+ def escape(str)
44
+ @conn.quote_string(str.to_s)
45
+ end
46
+
47
+ def esc_col(string)
48
+ string = string.to_s
49
+ raise "Invalid column-string: #{string}" if string.include?(@sep_col)
50
+ return string
51
+ end
52
+
53
+ def esc_table(string)
54
+ string = string.to_s
55
+ raise "Invalid column-string: #{string}" if string.include?(@sep_col)
56
+ return string
57
+ end
58
+ end
59
+
60
+ class Baza::Driver::ActiveRecord::Result
61
+ def initialize(db, res)
62
+ @db = db
63
+ @res = res
64
+ end
65
+
66
+ def each
67
+ @res.each(:as => :hash) do |hash|
68
+ yield hash.symbolize_keys!
69
+ end
70
+
71
+ nil
72
+ end
73
+ end
74
+
75
+ class Baza::Driver::ActiveRecord::Tables
76
+ def initialize(args)
77
+ @args = args
78
+
79
+ require_relative "../#{@args[:db].conn.conn_type}/#{@args[:db].conn.conn_type}_tables"
80
+ @proxy_to = ::Baza::Driver.const_get(StringCases.snake_to_camel(@args[:db].conn.conn_type)).const_get(:Tables).new(@args)
81
+ end
82
+
83
+ def method_missing(name, *args, &blk)
84
+ @proxy_to.__send__(name, *args, &blk)
85
+ end
86
+ end
87
+
88
+ class Baza::Driver::ActiveRecord::Columns
89
+ def initialize(args)
90
+ @args = args
91
+
92
+ require_relative "../#{@args[:db].conn.conn_type}/#{@args[:db].conn.conn_type}_columns"
93
+ @proxy_to = ::Baza::Driver.const_get(StringCases.snake_to_camel(@args[:db].conn.conn_type)).const_get(:Columns).new(@args)
94
+ end
95
+
96
+ def method_missing(name, *args, &blk)
97
+ @proxy_to.__send__(name, *args, &blk)
98
+ end
99
+ end
100
+
101
+ class Baza::Driver::ActiveRecord::Indexes
102
+ def initialize(args)
103
+ @args = args
104
+
105
+ require_relative "../#{@args[:db].conn.conn_type}/#{@args[:db].conn.conn_type}_indexes"
106
+ @proxy_to = ::Baza::Driver.const_get(StringCases.snake_to_camel(@args[:db].conn.conn_type)).const_get(:Indexes).new(@args)
107
+ end
108
+
109
+ def method_missing(name, *args, &blk)
110
+ @proxy_to.__send__(name, *args, &blk)
111
+ end
112
+ end
@@ -1,5 +1,5 @@
1
1
  class Baza::Driver::Mysql
2
- attr_reader :knjdb, :conn, :conns, :sep_table, :sep_col, :sep_val
2
+ attr_reader :baza, :conn, :conns, :sep_table, :sep_col, :sep_val
3
3
  attr_accessor :tables, :cols, :indexes
4
4
 
5
5
  #Helper to enable automatic registering of database using Baza::Db.from_object
@@ -10,7 +10,11 @@ class Baza::Driver::Mysql
10
10
  :args => {
11
11
  :type => :mysql,
12
12
  :subtype => :mysql2,
13
- :conn => args[:object]
13
+ :conn => args[:object],
14
+ :query_args => {
15
+ :as => :hash,
16
+ :symbolize_keys => true
17
+ }
14
18
  }
15
19
  }
16
20
  end
@@ -18,9 +22,9 @@ class Baza::Driver::Mysql
18
22
  return nil
19
23
  end
20
24
 
21
- def initialize(knjdb_ob)
22
- @knjdb = knjdb_ob
23
- @opts = @knjdb.opts
25
+ def initialize(baza_db_obj)
26
+ @baza_db = baza_db_obj
27
+ @opts = @baza_db.opts
24
28
  @sep_table = "`"
25
29
  @sep_col = "`"
26
30
  @sep_val = "'"
@@ -34,14 +38,14 @@ class Baza::Driver::Mysql
34
38
  @encoding = "utf8"
35
39
  end
36
40
 
37
- if @knjdb.opts.key?(:port)
38
- @port = @knjdb.opts[:port].to_i
41
+ if @baza_db.opts.key?(:port)
42
+ @port = @baza_db.opts[:port].to_i
39
43
  else
40
44
  @port = 3306
41
45
  end
42
46
 
43
47
  @java_rs_data = {}
44
- @subtype = @knjdb.opts[:subtype]
48
+ @subtype = @baza_db.opts[:subtype]
45
49
  @subtype = :mysql if @subtype.to_s.empty?
46
50
  self.reconnect
47
51
  end
@@ -66,16 +70,16 @@ class Baza::Driver::Mysql
66
70
  @mutex.synchronize do
67
71
  case @subtype
68
72
  when :mysql
69
- @conn = Mysql.real_connect(@knjdb.opts[:host], @knjdb.opts[:user], @knjdb.opts[:pass], @knjdb.opts[:db], @port)
73
+ @conn = Mysql.real_connect(@baza_db.opts[:host], @baza_db.opts[:user], @baza_db.opts[:pass], @baza_db.opts[:db], @port)
70
74
  when :mysql2
71
75
  require "rubygems"
72
76
  require "mysql2"
73
77
 
74
78
  args = {
75
- :host => @knjdb.opts[:host],
76
- :username => @knjdb.opts[:user],
77
- :password => @knjdb.opts[:pass],
78
- :database => @knjdb.opts[:db],
79
+ :host => @baza_db.opts[:host],
80
+ :username => @baza_db.opts[:user],
81
+ :password => @baza_db.opts[:pass],
82
+ :database => @baza_db.opts[:db],
79
83
  :port => @port,
80
84
  :symbolize_keys => true,
81
85
  :cache_rows => false
@@ -83,11 +87,11 @@ class Baza::Driver::Mysql
83
87
 
84
88
  #Symbolize keys should also be given here, else table-data wont be symbolized for some reason - knj.
85
89
  @query_args = {:symbolize_keys => true}
86
- @query_args.merge!(@knjdb.opts[:query_args]) if @knjdb.opts[:query_args]
90
+ @query_args.merge!(@baza_db.opts[:query_args]) if @baza_db.opts[:query_args]
87
91
 
88
92
  pos_args = [:as, :async, :cast_booleans, :database_timezone, :application_timezone, :cache_rows, :connect_flags, :cast]
89
93
  pos_args.each do |key|
90
- args[key] = @knjdb.opts[key] if @knjdb.opts.key?(key)
94
+ args[key] = @baza_db.opts[key] if @baza_db.opts.key?(key)
91
95
  end
92
96
 
93
97
  args[:as] = :array if @opts[:result] == "array"
@@ -95,8 +99,8 @@ class Baza::Driver::Mysql
95
99
  tries = 0
96
100
  begin
97
101
  tries += 1
98
- if @knjdb.opts[:conn]
99
- @conn = @knjdb.opts[:conn]
102
+ if @baza_db.opts[:conn]
103
+ @conn = @baza_db.opts[:conn]
100
104
  else
101
105
  @conn = Mysql2::Client.new(args)
102
106
  end
@@ -104,6 +108,7 @@ class Baza::Driver::Mysql
104
108
  if tries <= 3
105
109
  if e.message == "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)"
106
110
  sleep 1
111
+ tries += 1
107
112
  retry
108
113
  end
109
114
  end
@@ -118,7 +123,7 @@ class Baza::Driver::Mysql
118
123
  @jdbc_loaded = true
119
124
  end
120
125
 
121
- @conn = java.sql::DriverManager.getConnection("jdbc:mysql://#{@knjdb.opts[:host]}:#{@port}/#{@knjdb.opts[:db]}?user=#{@knjdb.opts[:user]}&password=#{@knjdb.opts[:pass]}&populateInsertRowWithDefaultValues=true&zeroDateTimeBehavior=round&characterEncoding=#{@encoding}&holdResultsOpenOverStatementClose=true")
126
+ @conn = java.sql::DriverManager.getConnection("jdbc:mysql://#{@baza_db.opts[:host]}:#{@port}/#{@baza_db.opts[:db]}?user=#{@baza_db.opts[:user]}&password=#{@baza_db.opts[:pass]}&populateInsertRowWithDefaultValues=true&zeroDateTimeBehavior=round&characterEncoding=#{@encoding}&holdResultsOpenOverStatementClose=true")
122
127
  self.query("SET SQL_MODE = ''")
123
128
  else
124
129
  raise "Unknown subtype: #{@subtype} (#{@subtype.class.name})"
@@ -158,7 +163,7 @@ class Baza::Driver::Mysql
158
163
 
159
164
  begin
160
165
  res = stmt.execute_query(str)
161
- ret = Baza::Driver::Mysql::ResultJava.new(@knjdb, @opts, res)
166
+ ret = Baza::Driver::Mysql::ResultJava.new(@baza_db, @opts, res)
162
167
  id = ret.__id__
163
168
 
164
169
  #If ID is being reused we have to free the result.
@@ -222,7 +227,7 @@ class Baza::Driver::Mysql
222
227
 
223
228
  begin
224
229
  res = stmt.executeQuery(str)
225
- ret = Baza::Driver::Mysql::ResultJava.new(@knjdb, @opts, res)
230
+ ret = Baza::Driver::Mysql::ResultJava.new(@baza_db, @opts, res)
226
231
 
227
232
  #Save reference to result and statement, so we can close them when they are garbage collected.
228
233
  @java_rs_data[ret.__id__] = {:res => res, :stmt => stmt}
@@ -271,7 +276,7 @@ class Baza::Driver::Mysql
271
276
  #Escapes a string to be safe to use as a column in a query.
272
277
  def esc_col(string)
273
278
  string = string.to_s
274
- raise "Invalid column-string: #{string}" if string.index(@sep_col) != nil
279
+ raise "Invalid column-string: #{string}" if string.include?(@sep_col)
275
280
  return string
276
281
  end
277
282
 
@@ -306,7 +311,7 @@ class Baza::Driver::Mysql
306
311
  #Destroyes the connection.
307
312
  def destroy
308
313
  @conn = nil
309
- @knjdb = nil
314
+ @baza_db = nil
310
315
  @mutex = nil
311
316
  @subtype = nil
312
317
  @encoding = nil
@@ -352,7 +357,7 @@ class Baza::Driver::Mysql
352
357
  sql << ","
353
358
  end
354
359
 
355
- sql << @knjdb.sqlval(val)
360
+ sql << @baza_db.sqlval(val)
356
361
  end
357
362
  else
358
363
  hash.each do |key, val|
@@ -362,7 +367,7 @@ class Baza::Driver::Mysql
362
367
  sql << ","
363
368
  end
364
369
 
365
- sql << @knjdb.sqlval(val)
370
+ sql << @baza_db.sqlval(val)
366
371
  end
367
372
  end
368
373
  end
@@ -393,13 +398,13 @@ class Baza::Driver::Mysql
393
398
 
394
399
  #Starts a transaction, yields the database and commits at the end.
395
400
  def transaction
396
- @knjdb.q("START TRANSACTION")
401
+ @baza_db.q("START TRANSACTION")
397
402
 
398
403
  begin
399
- yield(@knjdb)
400
- @knjdb.q("COMMIT")
404
+ yield(@baza_db)
405
+ @baza_db.q("COMMIT")
401
406
  rescue
402
- @knjdb.q("ROLLBACK")
407
+ @baza_db.q("ROLLBACK")
403
408
  raise
404
409
  end
405
410
  end
@@ -552,7 +557,7 @@ end
552
557
  class Baza::Driver::Mysql::ResultJava
553
558
  #Constructor. This should not be called manually.
554
559
  def initialize(knjdb, opts, result)
555
- @knjdb = knjdb
560
+ @baza_db = knjdb
556
561
  @result = result
557
562
 
558
563
  if !opts.key?(:result) or opts[:result] == "hash"
@@ -45,6 +45,7 @@ class Baza::Driver::Mysql::Tables
45
45
 
46
46
  @list_mutex.synchronize do
47
47
  @db.q(sql) do |d_tables|
48
+ raise "No name was given from: #{d_tables}" unless d_tables.is_a?(Hash) && d_tables[:Name]
48
49
  name = d_tables[:Name].to_sym
49
50
  obj = @list.get!(name)
50
51
 
@@ -11,18 +11,18 @@ class KnjDB_java_sqlite3
11
11
  return "'"
12
12
  end
13
13
 
14
- def initialize(knjdb_ob)
15
- @knjdb = knjdb_ob
14
+ def initialize(baza_db_obj)
15
+ @baza_db = baza_db_obj
16
16
 
17
- if @knjdb.opts[:sqlite_driver]
18
- require @knjdb.opts[:sqlite_driver]
17
+ if @baza_db.opts[:sqlite_driver]
18
+ require @baza_db.opts[:sqlite_driver]
19
19
  else
20
20
  require File.dirname(__FILE__) + "/sqlitejdbc-v056.jar"
21
21
  end
22
22
 
23
23
  require "java"
24
24
  import "org.sqlite.JDBC"
25
- @conn = java.sql.DriverManager::getConnection("jdbc:sqlite:" + @knjdb.opts[:path])
25
+ @conn = java.sql.DriverManager::getConnection("jdbc:sqlite:" + @baza_db.opts[:path])
26
26
  @stat = @conn.createStatement
27
27
  end
28
28
 
@@ -14,9 +14,9 @@ class Baza::Driver::Sqlite3_ironruby
14
14
  return "'"
15
15
  end
16
16
 
17
- def initialize(knjdb_ob)
18
- @knjdb = knjdb_ob
19
- @conn = Mono::Data::SqliteClient::SqliteConnection.new("URI=file:" + @knjdb.opts[:path] + ",version=3")
17
+ def initialize(baza_db_obj)
18
+ @baza_db = baza_db_obj
19
+ @conn = Mono::Data::SqliteClient::SqliteConnection.new("URI=file:" + @baza_db.opts[:path] + ",version=3")
20
20
  @conn.Open
21
21
  end
22
22
 
@@ -1,6 +1,6 @@
1
1
  #This class handels SQLite3-specific behaviour.
2
2
  class Baza::Driver::Sqlite3
3
- attr_reader :knjdb, :conn, :sep_table, :sep_col, :sep_val, :symbolize
3
+ attr_reader :baza, :conn, :sep_table, :sep_col, :sep_val, :symbolize
4
4
  attr_accessor :tables, :cols, :indexes
5
5
 
6
6
  #Helper to enable automatic registering of database using Baza::Db.from_object
@@ -19,34 +19,34 @@ class Baza::Driver::Sqlite3
19
19
  end
20
20
 
21
21
  #Constructor. This should not be called manually.
22
- def initialize(knjdb_ob)
22
+ def initialize(baza_db_obj)
23
23
  @sep_table = "`"
24
24
  @sep_col = "`"
25
25
  @sep_val = "'"
26
26
 
27
- @knjdb = knjdb_ob
28
- @path = @knjdb.opts[:path] if @knjdb.opts[:path]
29
- @path = @knjdb.opts["path"] if @knjdb.opts["path"]
27
+ @baza_db = baza_db_obj
28
+ @path = @baza_db.opts[:path] if @baza_db.opts[:path]
29
+ @path = @baza_db.opts["path"] if @baza_db.opts["path"]
30
30
 
31
- @knjdb.opts[:subtype] = "java" if !@knjdb.opts.key?(:subtype) and RUBY_ENGINE == "jruby"
31
+ @baza_db.opts[:subtype] = "java" if !@baza_db.opts.key?(:subtype) and RUBY_ENGINE == "jruby"
32
32
 
33
- if @knjdb.opts[:conn]
34
- @conn = @knjdb.opts[:conn]
33
+ if @baza_db.opts[:conn]
34
+ @conn = @baza_db.opts[:conn]
35
35
  else
36
36
  raise "No path was given." if !@path
37
37
 
38
- if @knjdb.opts[:subtype] == "java"
39
- if @knjdb.opts[:sqlite_driver]
40
- require @knjdb.opts[:sqlite_driver]
38
+ if @baza_db.opts[:subtype] == "java"
39
+ if @baza_db.opts[:sqlite_driver]
40
+ require @baza_db.opts[:sqlite_driver]
41
41
  else
42
42
  require "#{File.dirname(__FILE__)}/../../../jruby/sqlitejdbc-v056.jar"
43
43
  end
44
44
 
45
45
  require "java"
46
46
  import "org.sqlite.JDBC"
47
- @conn = java.sql.DriverManager::getConnection("jdbc:sqlite:#{@knjdb.opts[:path]}")
47
+ @conn = java.sql.DriverManager::getConnection("jdbc:sqlite:#{@baza_db.opts[:path]}")
48
48
  @stat = @conn.createStatement
49
- elsif @knjdb.opts[:subtype] == "rhodes"
49
+ elsif @baza_db.opts[:subtype] == "rhodes"
50
50
  @conn = SQLite3::Database.new(@path, @path)
51
51
  else
52
52
  @conn = SQLite3::Database.open(@path)
@@ -58,9 +58,9 @@ class Baza::Driver::Sqlite3
58
58
 
59
59
  #Executes a query against the driver.
60
60
  def query(string)
61
- if @knjdb.opts[:subtype] == :rhodes
61
+ if @baza_db.opts[:subtype] == :rhodes
62
62
  return Baza::Driver::Sqlite3::Result.new(self, @conn.execute(string, string))
63
- elsif @knjdb.opts[:subtype] == :java
63
+ elsif @baza_db.opts[:subtype] == :java
64
64
  begin
65
65
  return Baza::Driver::Sqlite3::ResultJava.new(self, @stat.executeQuery(string))
66
66
  rescue java.sql.SQLException => e
@@ -109,16 +109,16 @@ class Baza::Driver::Sqlite3
109
109
  #Starts a transaction, yields the database and commits.
110
110
  def transaction
111
111
  @conn.transaction do
112
- yield(@knjdb)
112
+ yield(@baza_db)
113
113
  end
114
114
  end
115
115
 
116
116
  def insert_multi(tablename, arr_hashes, args = nil)
117
117
  sql = [] if args and args[:return_sql]
118
118
 
119
- @knjdb.transaction do
119
+ @baza_db.transaction do
120
120
  arr_hashes.each do |hash|
121
- res = @knjdb.insert(tablename, hash, args)
121
+ res = @baza_db.insert(tablename, hash, args)
122
122
  sql << res if args and args[:return_sql]
123
123
  end
124
124
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: baza
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.12
5
+ version: 0.0.13
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kasper Johansen
@@ -206,6 +206,7 @@ files:
206
206
  - baza.gemspec
207
207
  - include/db.rb
208
208
  - include/dbtime.rb
209
+ - include/drivers/active_record/active_record.rb
209
210
  - include/drivers/mysql/mysql.rb
210
211
  - include/drivers/mysql/mysql_columns.rb
211
212
  - include/drivers/mysql/mysql_indexes.rb
@@ -249,7 +250,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
249
250
  - !ruby/object:Gem::Version
250
251
  segments:
251
252
  - 0
252
- hash: -4416024205593696077
253
+ hash: -1432230654984551532
253
254
  version: '0'
254
255
  required_rubygems_version: !ruby/object:Gem::Requirement
255
256
  none: false