baza 0.0.19 → 0.0.20
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 +4 -4
- data/.rubocop_todo.yml +157 -0
- data/Gemfile +11 -9
- data/Gemfile.lock +41 -9
- data/README.md +1 -1
- data/Rakefile +19 -16
- data/VERSION +1 -1
- data/baza.gemspec +31 -7
- data/config/best_project_practice_rubocop.yml +2 -0
- data/config/best_project_practice_rubocop_todo.yml +157 -0
- data/lib/baza/base_sql_driver.rb +79 -20
- data/lib/baza/cloner.rb +2 -2
- data/lib/baza/column.rb +6 -0
- data/lib/baza/database.rb +33 -0
- data/lib/baza/database_model.rb +26 -0
- data/lib/baza/database_model_functionality.rb +10 -0
- data/lib/baza/database_model_name.rb +16 -0
- data/lib/baza/db.rb +210 -413
- data/lib/baza/dbtime.rb +20 -20
- data/lib/baza/driver.rb +3 -3
- data/lib/baza/drivers/active_record/columns.rb +1 -1
- data/lib/baza/drivers/active_record/indexes.rb +1 -1
- data/lib/baza/drivers/active_record/result.rb +3 -5
- data/lib/baza/drivers/active_record/tables.rb +2 -2
- data/lib/baza/drivers/active_record.rb +30 -16
- data/lib/baza/drivers/mysql/column.rb +51 -48
- data/lib/baza/drivers/mysql/columns.rb +8 -8
- data/lib/baza/drivers/mysql/database.rb +28 -0
- data/lib/baza/drivers/mysql/databases.rb +35 -0
- data/lib/baza/drivers/mysql/index.rb +32 -22
- data/lib/baza/drivers/mysql/result.rb +24 -24
- data/lib/baza/drivers/mysql/sqlspecs.rb +1 -1
- data/lib/baza/drivers/mysql/table.rb +80 -91
- data/lib/baza/drivers/mysql/tables.rb +30 -32
- data/lib/baza/drivers/mysql/unbuffered_result.rb +5 -5
- data/lib/baza/drivers/mysql.rb +127 -220
- data/lib/baza/drivers/mysql2/database.rb +2 -0
- data/lib/baza/drivers/mysql2/databases.rb +2 -0
- data/lib/baza/drivers/mysql2/result.rb +3 -5
- data/lib/baza/drivers/mysql2.rb +21 -106
- data/lib/baza/drivers/mysql_java/database.rb +2 -0
- data/lib/baza/drivers/mysql_java/databases.rb +2 -0
- data/lib/baza/drivers/mysql_java.rb +16 -12
- data/lib/baza/drivers/sqlite3/column.rb +33 -33
- data/lib/baza/drivers/sqlite3/columns.rb +6 -6
- data/lib/baza/drivers/sqlite3/database.rb +2 -0
- data/lib/baza/drivers/sqlite3/databases.rb +25 -0
- data/lib/baza/drivers/sqlite3/index.rb +20 -6
- data/lib/baza/drivers/sqlite3/result.rb +16 -17
- data/lib/baza/drivers/sqlite3/sqlspecs.rb +1 -1
- data/lib/baza/drivers/sqlite3/table.rb +99 -100
- data/lib/baza/drivers/sqlite3/tables.rb +30 -23
- data/lib/baza/drivers/sqlite3/unbuffered_result.rb +2 -2
- data/lib/baza/drivers/sqlite3.rb +27 -14
- data/lib/baza/drivers/sqlite3_java/database.rb +2 -0
- data/lib/baza/drivers/sqlite3_java/unbuffered_result.rb +2 -2
- data/lib/baza/drivers/sqlite3_java.rb +12 -10
- data/lib/baza/drivers/sqlite3_rhodes.rb +9 -7
- data/lib/baza/dump.rb +55 -55
- data/lib/baza/errors.rb +5 -0
- data/lib/baza/idquery.rb +25 -25
- data/lib/baza/index.rb +6 -0
- data/lib/baza/jdbc_driver.rb +6 -8
- data/lib/baza/jdbc_result.rb +1 -1
- data/lib/baza/model.rb +299 -309
- data/lib/baza/model_custom.rb +74 -72
- data/lib/baza/model_handler.rb +244 -255
- data/lib/baza/model_handler_sqlhelper.rb +122 -132
- data/lib/baza/mysql_base_driver.rb +112 -0
- data/lib/baza/query_buffer.rb +23 -23
- data/lib/baza/result_base.rb +2 -2
- data/lib/baza/revision.rb +67 -67
- data/lib/baza/row.rb +82 -84
- data/lib/baza/sqlspecs.rb +1 -1
- data/lib/baza/table.rb +31 -0
- data/lib/baza.rb +43 -10
- data/shippable.yml +1 -0
- data/spec/cloner_spec.rb +4 -4
- data/spec/drivers/active_record_mysql2_spec.rb +3 -3
- data/spec/drivers/active_record_mysql_spec.rb +2 -2
- data/spec/drivers/active_record_sqlite3_spec.rb +2 -2
- data/spec/drivers/mysql2_spec.rb +1 -0
- data/spec/drivers/mysql_spec.rb +1 -0
- data/spec/drivers/sqlite3_spec.rb +4 -5
- data/spec/info_active_record_example.rb +4 -6
- data/spec/info_active_record_mysql.rb +6 -7
- data/spec/info_active_record_mysql2.rb +2 -4
- data/spec/info_active_record_mysql2_shippable.rb +2 -4
- data/spec/info_active_record_mysql_shippable.rb +2 -4
- data/spec/info_active_record_sqlite3.rb +5 -6
- data/spec/info_mysql2_example.rb +1 -1
- data/spec/info_mysql2_shippable.rb +1 -1
- data/spec/info_mysql_example.rb +1 -1
- data/spec/info_mysql_shippable.rb +1 -1
- data/spec/info_sqlite3.rb +4 -3
- data/spec/model_handler_spec.rb +102 -115
- data/spec/spec_helper.rb +5 -5
- data/spec/support/driver_collection.rb +98 -95
- data/spec/support/driver_columns_collection.rb +18 -22
- data/spec/support/driver_databases_collection.rb +29 -0
- data/spec/support/driver_indexes_collection.rb +7 -6
- data/spec/support/driver_tables_collection.rb +38 -26
- metadata +49 -3
data/lib/baza/row.rb
CHANGED
@@ -1,23 +1,26 @@
|
|
1
1
|
class Baza::Row
|
2
|
+
include Baza::DatabaseModelFunctionality
|
3
|
+
|
2
4
|
attr_reader :args, :data
|
3
|
-
|
4
|
-
def
|
5
|
-
|
5
|
+
|
6
|
+
def knj?
|
7
|
+
true
|
8
|
+
end
|
9
|
+
|
6
10
|
def initialize(args)
|
7
11
|
@args = {}
|
8
12
|
args.each do |key, value|
|
9
13
|
@args[key.to_sym] = value
|
10
14
|
end
|
11
|
-
|
12
|
-
@args[:
|
13
|
-
@args[:
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
if @args[:data] and (@args[:data].is_a?(Integer) or @args[:data].is_a?(Fixnum) or @args[:data].is_a?(String))
|
15
|
+
|
16
|
+
@args[:objects] = $objects if !@args[:objects] && $objects && $objects.is_a?(Baza::ModelHandler)
|
17
|
+
@args[:col_id] ||= :id
|
18
|
+
raise "No table given." unless @args[:table]
|
19
|
+
|
20
|
+
if @args[:data] && (@args[:data].is_a?(Integer) || @args[:data].is_a?(Fixnum) || @args[:data].is_a?(String))
|
18
21
|
@data = {@args[:col_id].to_sym => @args[:data].to_s}
|
19
|
-
|
20
|
-
elsif @args[:data]
|
22
|
+
reload
|
23
|
+
elsif @args[:data] && @args[:data].is_a?(Hash)
|
21
24
|
@data = {}
|
22
25
|
@args[:data].each do |key, value|
|
23
26
|
@data[key.to_sym] = value
|
@@ -25,71 +28,61 @@ class Baza::Row
|
|
25
28
|
elsif @args[:id]
|
26
29
|
@data = {}
|
27
30
|
@data[@args[:col_id].to_sym] = @args[:id]
|
28
|
-
|
31
|
+
reload
|
29
32
|
else
|
30
|
-
raise ArgumentError.new("Invalid data: #{@args[:data]
|
33
|
+
raise ArgumentError.new("Invalid data: #{@args[:data]} (#{@args[:data].class})")
|
31
34
|
end
|
32
35
|
end
|
33
|
-
|
36
|
+
|
34
37
|
def db
|
35
|
-
|
36
|
-
curthread = Thread.current
|
37
|
-
if curthread.is_a?(Knj::Thread) and curthread[:knjappserver] and curthread[:knjappserver][:db]
|
38
|
-
return curthread[:knjappserver][:db]
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
return @args[:db]
|
38
|
+
@args.fetch(:db)
|
43
39
|
end
|
44
|
-
|
40
|
+
|
45
41
|
def ob
|
46
42
|
return @args[:objects] if @args.key?(:objects)
|
47
|
-
|
48
|
-
return false
|
43
|
+
false
|
49
44
|
end
|
50
|
-
|
51
|
-
|
52
|
-
|
45
|
+
|
46
|
+
alias_method :objects, :ob
|
47
|
+
|
53
48
|
def reload
|
54
|
-
last_id =
|
55
|
-
data =
|
56
|
-
|
57
|
-
raise Errno::ENOENT
|
49
|
+
last_id = id
|
50
|
+
data = db.single(@args[:table], @args[:col_id] => id)
|
51
|
+
unless data
|
52
|
+
raise Errno::ENOENT, "Could not find any data for the object with ID: '#{last_id}' in the table '#{@args[:table]}'."
|
58
53
|
end
|
59
|
-
|
54
|
+
|
60
55
|
@data = {}
|
61
56
|
data.each do |key, value|
|
62
57
|
@data[key.to_sym] = value
|
63
58
|
end
|
64
59
|
end
|
65
|
-
|
60
|
+
|
66
61
|
def update(newdata)
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
if
|
71
|
-
self.ob.call("object" => self, "signal" => "update")
|
72
|
-
end
|
62
|
+
db.update(@args[:table], newdata, @args[:col_id] => id)
|
63
|
+
reload
|
64
|
+
|
65
|
+
ob.call("object" => self, "signal" => "update") if ob
|
73
66
|
end
|
74
|
-
|
67
|
+
|
75
68
|
def delete
|
76
|
-
|
77
|
-
|
69
|
+
db.delete(@args[:table], @args[:col_id] => id)
|
70
|
+
destroy
|
78
71
|
end
|
79
|
-
|
72
|
+
|
80
73
|
def destroy
|
81
74
|
@args = nil
|
82
75
|
@data = nil
|
83
76
|
end
|
84
|
-
|
85
|
-
def
|
86
|
-
|
77
|
+
|
78
|
+
def key?(key)
|
79
|
+
@data.key?(key.to_sym)
|
87
80
|
end
|
88
|
-
|
81
|
+
|
89
82
|
def [](key)
|
90
|
-
raise "No valid key given."
|
91
|
-
raise "No data was loaded on the object? Maybe you are trying to call a deleted object?"
|
92
|
-
|
83
|
+
raise "No valid key given." unless key
|
84
|
+
raise "No data was loaded on the object? Maybe you are trying to call a deleted object?" unless @data
|
85
|
+
|
93
86
|
if @data.key?(key)
|
94
87
|
return @data[key]
|
95
88
|
elsif @data.key?(key.to_sym)
|
@@ -97,57 +90,62 @@ class Baza::Row
|
|
97
90
|
elsif @data.key?(key.to_s)
|
98
91
|
return @data[key.to_s]
|
99
92
|
end
|
100
|
-
|
101
|
-
raise "No such key: #{key
|
93
|
+
|
94
|
+
raise "No such key: #{key}."
|
102
95
|
end
|
103
|
-
|
96
|
+
|
104
97
|
def []=(key, value)
|
105
|
-
|
106
|
-
|
98
|
+
update(key.to_sym => value)
|
99
|
+
reload
|
107
100
|
end
|
108
|
-
|
101
|
+
|
109
102
|
def id
|
110
|
-
|
103
|
+
@data[@args[:col_id]]
|
111
104
|
end
|
112
|
-
|
105
|
+
|
106
|
+
def to_param
|
107
|
+
id
|
108
|
+
end
|
109
|
+
|
113
110
|
def title
|
114
|
-
if @args[:col_title]
|
115
|
-
|
116
|
-
end
|
117
|
-
|
111
|
+
return @data[@args[:col_title].to_sym] if @args[:col_title]
|
112
|
+
|
118
113
|
if @data.key?(:title)
|
119
114
|
return @data[:title]
|
120
115
|
elsif @data.key?(:name)
|
121
116
|
return @data[:name]
|
122
117
|
end
|
123
|
-
|
124
|
-
raise "'col_title' has not been set for the class: '#{self.class
|
118
|
+
|
119
|
+
raise "'col_title' has not been set for the class: '#{self.class}'."
|
120
|
+
end
|
121
|
+
|
122
|
+
alias_method :name, :title
|
123
|
+
|
124
|
+
def each(*args, &blk)
|
125
|
+
@data.each(*args, &blk)
|
125
126
|
end
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
def each(&args)
|
130
|
-
return @data.each(&args)
|
127
|
+
|
128
|
+
def each_value(*args, &blk)
|
129
|
+
@data.each_value(*args, &blk)
|
131
130
|
end
|
132
|
-
|
131
|
+
|
133
132
|
def to_hash
|
134
|
-
|
133
|
+
@data.clone
|
135
134
|
end
|
136
|
-
|
135
|
+
|
137
136
|
def esc(str)
|
138
|
-
|
137
|
+
db.escape(str)
|
139
138
|
end
|
140
|
-
|
141
|
-
def method_missing(*args)
|
142
|
-
|
143
|
-
|
144
|
-
if @data[match[1].to_sym] == "1" or @data[match[1].to_sym] == "yes"
|
139
|
+
|
140
|
+
def method_missing(func_name, *args)
|
141
|
+
if match = func_name.to_s.match(/^(\S+)\?$/) && @data.key?(match[1].to_sym)
|
142
|
+
if @data[match[1].to_sym] == "1" || @data[match[1].to_sym] == "yes"
|
145
143
|
return true
|
146
|
-
elsif @data[match[1].to_sym] == "0"
|
144
|
+
elsif @data[match[1].to_sym] == "0" || @data[match[1].to_sym] == "no"
|
147
145
|
return false
|
148
146
|
end
|
149
147
|
end
|
150
|
-
|
151
|
-
|
148
|
+
|
149
|
+
super
|
152
150
|
end
|
153
|
-
end
|
151
|
+
end
|
data/lib/baza/sqlspecs.rb
CHANGED
data/lib/baza/table.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
class Baza::Table
|
2
|
+
include Baza::DatabaseModelFunctionality
|
3
|
+
|
4
|
+
attr_reader :db
|
5
|
+
|
2
6
|
def to_s
|
3
7
|
"#<#{self.class.name} name=\"#{name}\">"
|
4
8
|
end
|
@@ -6,4 +10,31 @@ class Baza::Table
|
|
6
10
|
def inspect
|
7
11
|
to_s
|
8
12
|
end
|
13
|
+
|
14
|
+
def rows(*args)
|
15
|
+
ArrayEnumerator.new do |yielder|
|
16
|
+
db.select(name, *args) do |data|
|
17
|
+
yielder << Baza::Row.new(
|
18
|
+
db: db,
|
19
|
+
table: name,
|
20
|
+
data: data
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def row(id)
|
27
|
+
data = rows({id: id}, limit: 1).fetch
|
28
|
+
raise Baza::Errors::RowNotFound unless data
|
29
|
+
|
30
|
+
Baza::Row.new(
|
31
|
+
db: db,
|
32
|
+
table: name,
|
33
|
+
data: data
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_param
|
38
|
+
name
|
39
|
+
end
|
9
40
|
end
|
data/lib/baza.rb
CHANGED
@@ -1,31 +1,64 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "array_enumerator"
|
2
|
+
require "wref"
|
3
|
+
require "datet"
|
4
|
+
require "string-cases"
|
4
5
|
|
5
6
|
class Baza
|
6
|
-
#Autoloader for subclasses.
|
7
|
+
# Autoloader for subclasses.
|
7
8
|
def self.const_missing(name)
|
8
|
-
file_name = name.to_s.gsub(/(.)([A-Z])/,'\1_\2').downcase
|
9
|
+
file_name = name.to_s.gsub(/(.)([A-Z])/, '\1_\2').downcase
|
9
10
|
require "#{File.dirname(__FILE__)}/baza/#{file_name}.rb"
|
10
11
|
raise "Still not defined: '#{name}'." unless Baza.const_defined?(name)
|
11
|
-
|
12
|
+
Baza.const_get(name)
|
12
13
|
end
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
class << self
|
16
|
+
attr_writer :default_db
|
16
17
|
end
|
17
18
|
|
18
19
|
def self.default_db
|
19
20
|
unless @default_db
|
20
21
|
config_file = "#{Dir.pwd}/config/baza_database.rb"
|
22
|
+
init_file = "#{Dir.pwd}/config/initializers/baza_database.rb"
|
21
23
|
|
22
|
-
|
24
|
+
begin
|
25
|
+
load(config_file)
|
26
|
+
rescue LoadError
|
27
|
+
load(init_file)
|
28
|
+
end
|
23
29
|
|
24
30
|
unless @default_db.is_a?(Baza::Db)
|
25
31
|
raise "Config file didn't return a Baza::Db: #{@default_db.class.name}"
|
26
32
|
end
|
27
33
|
end
|
28
34
|
|
29
|
-
|
35
|
+
@default_db
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.drivers
|
39
|
+
Enumerator.new do |yielder|
|
40
|
+
Dir.foreach("#{File.dirname(__FILE__)}/baza/drivers") do |file|
|
41
|
+
if (match = file.match(/\A(.+?)\.rb\Z/))
|
42
|
+
load_driver(match[1])
|
43
|
+
|
44
|
+
driver_name = StringCases.snake_to_camel(match[1])
|
45
|
+
yielder << {
|
46
|
+
class: Baza::Driver.const_get(driver_name),
|
47
|
+
snake_name: match[1],
|
48
|
+
camel_name: driver_name
|
49
|
+
}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.load_driver(name)
|
56
|
+
require_relative "baza/drivers/#{name}"
|
57
|
+
|
58
|
+
loads = %w(databases database tables table columns column indexes index result)
|
59
|
+
loads.each do |load|
|
60
|
+
file_path = "#{File.dirname(__FILE__)}/baza/drivers/#{name}/#{load}"
|
61
|
+
require_relative file_path if File.exist?(file_path)
|
62
|
+
end
|
30
63
|
end
|
31
64
|
end
|
data/shippable.yml
CHANGED
data/spec/cloner_spec.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Baza::Cloner do
|
4
|
-
it
|
5
|
-
require
|
4
|
+
it "can clone drivers" do
|
5
|
+
require "info_active_record_mysql"
|
6
6
|
conn = Baza::InfoActiveRecordMysql.connection
|
7
7
|
baza_db = Baza::Cloner.from_active_record_connection(conn[:conn])
|
8
|
-
expect(baza_db.query(
|
8
|
+
expect(baza_db.query("SELECT 1 AS test").fetch[:test].to_s).to eq "1"
|
9
9
|
end
|
10
10
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
unless RUBY_PLATFORM ==
|
3
|
+
unless RUBY_PLATFORM == "java"
|
4
4
|
describe Baza::Driver::ActiveRecord do
|
5
|
-
let(:constant)
|
5
|
+
let(:constant) do
|
6
6
|
name = described_class.name.split("::").last
|
7
7
|
const_name = "InfoActiveRecordMysql2"
|
8
8
|
require "#{File.dirname(__FILE__)}/../#{StringCases.camel_to_snake(const_name)}"
|
9
9
|
raise "Constant was not defined: '#{const_name}'." unless Baza.const_defined?(const_name)
|
10
10
|
Baza.const_get(const_name)
|
11
|
-
|
11
|
+
end
|
12
12
|
|
13
13
|
it_behaves_like "a baza driver"
|
14
14
|
it_should_behave_like "a baza tables driver"
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Baza::Driver::ActiveRecord do
|
4
|
-
let(:constant)
|
4
|
+
let(:constant) do
|
5
5
|
name = described_class.name.split("::").last
|
6
6
|
const_name = "InfoActiveRecordMysql"
|
7
7
|
require "#{File.dirname(__FILE__)}/../#{StringCases.camel_to_snake(const_name)}"
|
8
8
|
raise "Constant was not defined: '#{const_name}'." unless Baza.const_defined?(const_name)
|
9
9
|
Baza.const_get(const_name)
|
10
|
-
|
10
|
+
end
|
11
11
|
|
12
12
|
it_behaves_like "a baza driver"
|
13
13
|
it_should_behave_like "a baza tables driver"
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Baza::Driver::ActiveRecord do
|
4
|
-
let(:constant)
|
4
|
+
let(:constant) do
|
5
5
|
name = described_class.name.split("::").last
|
6
6
|
const_name = "InfoActiveRecordSqlite3"
|
7
7
|
require "#{File.dirname(__FILE__)}/../#{StringCases.camel_to_snake(const_name)}"
|
8
8
|
raise "Constant was not defined: '#{const_name}'." unless Baza.const_defined?(const_name)
|
9
9
|
Baza.const_get(const_name)
|
10
|
-
|
10
|
+
end
|
11
11
|
|
12
12
|
it_behaves_like "a baza driver"
|
13
13
|
it_should_behave_like "a baza tables driver"
|
data/spec/drivers/mysql2_spec.rb
CHANGED
@@ -10,6 +10,7 @@ describe Baza::Driver::Mysql2 do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it_should_behave_like "a baza driver"
|
13
|
+
it_should_behave_like "a baza databases driver"
|
13
14
|
it_should_behave_like "a baza tables driver"
|
14
15
|
it_should_behave_like "a baza columns driver"
|
15
16
|
it_should_behave_like "a baza indexes driver"
|
data/spec/drivers/mysql_spec.rb
CHANGED
@@ -10,6 +10,7 @@ describe Baza.const_get(:Driver).const_get(:Mysql) do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it_should_behave_like "a baza driver"
|
13
|
+
it_should_behave_like "a baza databases driver"
|
13
14
|
it_should_behave_like "a baza tables driver"
|
14
15
|
it_should_behave_like "a baza columns driver"
|
15
16
|
it_should_behave_like "a baza indexes driver"
|
@@ -19,7 +19,8 @@ describe Baza::Driver::Sqlite3 do
|
|
19
19
|
db = Baza::InfoSqlite3.new.db
|
20
20
|
db2 = Baza::InfoSqlite3.new.db
|
21
21
|
|
22
|
-
db.tables.create(
|
22
|
+
db.tables.create(
|
23
|
+
:test_table,
|
23
24
|
columns: [
|
24
25
|
{name: "id", type: :int, autoincr: true, primarykey: true},
|
25
26
|
{name: "testname", type: :varchar, null: true}
|
@@ -27,7 +28,7 @@ describe Baza::Driver::Sqlite3 do
|
|
27
28
|
indexes: [
|
28
29
|
"testname"
|
29
30
|
]
|
30
|
-
|
31
|
+
)
|
31
32
|
|
32
33
|
table1 = db.tables["test_table"]
|
33
34
|
cols1 = table1.columns
|
@@ -36,9 +37,7 @@ describe Baza::Driver::Sqlite3 do
|
|
36
37
|
table1.insert(testname: "TestRow#{count}")
|
37
38
|
end
|
38
39
|
|
39
|
-
expect {
|
40
|
-
table2 = db2.tables[:test_table]
|
41
|
-
}.to raise_error(Errno::ENOENT)
|
40
|
+
expect { table2 = db2.tables[:test_table] }.to raise_error(Baza::Errors::TableNotFound)
|
42
41
|
|
43
42
|
db.copy_to(db2)
|
44
43
|
|
@@ -13,22 +13,20 @@ class Baza::InfoActiveRecord
|
|
13
13
|
)
|
14
14
|
@conn ||= @conn_pool.connection
|
15
15
|
|
16
|
-
|
16
|
+
{pool: @conn_pool, conn: @conn}
|
17
17
|
end
|
18
18
|
|
19
19
|
def initialize
|
20
20
|
data = Baza::InfoActiveRecord.connection
|
21
21
|
|
22
|
-
@db = Baza::Db.new(
|
22
|
+
@db = Baza::Db.new({
|
23
23
|
type: :active_record,
|
24
24
|
conn: data[:conn]
|
25
|
-
)
|
25
|
+
}.merge(args))
|
26
26
|
end
|
27
27
|
|
28
28
|
def before
|
29
|
-
@db.tables.list
|
30
|
-
table.drop
|
31
|
-
end
|
29
|
+
@db.tables.list(&:drop)
|
32
30
|
end
|
33
31
|
|
34
32
|
def after
|
@@ -4,31 +4,30 @@ class Baza::InfoActiveRecordMysql
|
|
4
4
|
def self.connection
|
5
5
|
require "active_record"
|
6
6
|
|
7
|
-
conn_pool
|
7
|
+
@conn_pool ||= ::ActiveRecord::Base.establish_connection(
|
8
8
|
adapter: "mysql",
|
9
9
|
host: "localhost",
|
10
10
|
database: "baza-test",
|
11
11
|
username: "baza-test",
|
12
12
|
password: "BBH7djRUKzL5nmG3"
|
13
13
|
)
|
14
|
-
conn
|
14
|
+
@conn ||= @conn_pool.connection
|
15
15
|
|
16
|
-
|
16
|
+
{pool: @conn_pool, conn: @conn}
|
17
17
|
end
|
18
18
|
|
19
19
|
def initialize(args = {})
|
20
20
|
@data = Baza::InfoActiveRecordMysql.connection
|
21
|
+
@data.fetch(:conn).reconnect!
|
21
22
|
|
22
23
|
@db = Baza::Db.new({
|
23
24
|
type: :active_record,
|
24
|
-
conn: @data
|
25
|
+
conn: @data.fetch(:conn)
|
25
26
|
}.merge(args))
|
26
27
|
end
|
27
28
|
|
28
29
|
def before
|
29
|
-
@db.tables.list
|
30
|
-
table.drop
|
31
|
-
end
|
30
|
+
@db.tables.list(&:drop)
|
32
31
|
end
|
33
32
|
|
34
33
|
def after
|
@@ -13,7 +13,7 @@ class Baza::InfoActiveRecordMysql2
|
|
13
13
|
)
|
14
14
|
@conn ||= @conn_pool.connection
|
15
15
|
|
16
|
-
|
16
|
+
{pool: @conn_pool, conn: @conn}
|
17
17
|
end
|
18
18
|
|
19
19
|
def initialize(args = {})
|
@@ -26,9 +26,7 @@ class Baza::InfoActiveRecordMysql2
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def before
|
29
|
-
@db.tables.list
|
30
|
-
table.drop
|
31
|
-
end
|
29
|
+
@db.tables.list(&:drop)
|
32
30
|
end
|
33
31
|
|
34
32
|
def after
|
@@ -12,7 +12,7 @@ class Baza::InfoActiveRecordMysql2
|
|
12
12
|
)
|
13
13
|
conn = conn_pool.connection
|
14
14
|
|
15
|
-
|
15
|
+
{pool: conn_pool, conn: conn}
|
16
16
|
end
|
17
17
|
|
18
18
|
def initialize
|
@@ -25,9 +25,7 @@ class Baza::InfoActiveRecordMysql2
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def before
|
28
|
-
@db.tables.list
|
29
|
-
table.drop
|
30
|
-
end
|
28
|
+
@db.tables.list(&:drop)
|
31
29
|
end
|
32
30
|
|
33
31
|
def after
|
@@ -12,7 +12,7 @@ class Baza::InfoActiveRecordMysql
|
|
12
12
|
)
|
13
13
|
conn = conn_pool.connection
|
14
14
|
|
15
|
-
|
15
|
+
{pool: conn_pool, conn: conn}
|
16
16
|
end
|
17
17
|
|
18
18
|
def initialize
|
@@ -25,9 +25,7 @@ class Baza::InfoActiveRecordMysql
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def before
|
28
|
-
@db.tables.list
|
29
|
-
table.drop
|
30
|
-
end
|
28
|
+
@db.tables.list(&:drop)
|
31
29
|
end
|
32
30
|
|
33
31
|
def after
|
@@ -5,7 +5,7 @@ class Baza::InfoActiveRecordSqlite3
|
|
5
5
|
require "active_record"
|
6
6
|
|
7
7
|
path = "#{Dir.tmpdir}/baza_sqlite3_test_#{Time.now.to_f.to_s.hash}_#{Random.rand}.sqlite3"
|
8
|
-
File.unlink(path) if File.
|
8
|
+
File.unlink(path) if File.exist?(path)
|
9
9
|
|
10
10
|
@conn_pool ||= ::ActiveRecord::Base.establish_connection(
|
11
11
|
adapter: "sqlite3",
|
@@ -13,7 +13,7 @@ class Baza::InfoActiveRecordSqlite3
|
|
13
13
|
)
|
14
14
|
@conn ||= @conn_pool.connection
|
15
15
|
|
16
|
-
|
16
|
+
{pool: @conn_pool, conn: @conn}
|
17
17
|
end
|
18
18
|
|
19
19
|
def initialize(args = {})
|
@@ -21,14 +21,13 @@ class Baza::InfoActiveRecordSqlite3
|
|
21
21
|
|
22
22
|
@db = Baza::Db.new({
|
23
23
|
type: :active_record,
|
24
|
-
conn: data[:conn]
|
24
|
+
conn: data[:conn],
|
25
|
+
index_append_table_name: true
|
25
26
|
}.merge(args))
|
26
27
|
end
|
27
28
|
|
28
29
|
def before
|
29
|
-
@db.tables.list
|
30
|
-
table.drop
|
31
|
-
end
|
30
|
+
@db.tables.list(&:drop)
|
32
31
|
end
|
33
32
|
|
34
33
|
def after
|
data/spec/info_mysql2_example.rb
CHANGED