baza 0.0.17 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +9 -11
- data/Gemfile.lock +76 -50
- data/README.md +3 -2
- data/VERSION +1 -1
- data/baza.gemspec +107 -54
- data/lib/baza.rb +1 -1
- data/lib/baza/base_sql_driver.rb +64 -0
- data/lib/baza/cloner.rb +31 -0
- data/{include → lib/baza}/column.rb +0 -0
- data/{include → lib/baza}/db.rb +61 -49
- data/{include → lib/baza}/dbtime.rb +0 -0
- data/{include → lib/baza}/driver.rb +1 -1
- data/lib/baza/drivers/active_record.rb +107 -0
- data/lib/baza/drivers/active_record/columns.rb +10 -0
- data/lib/baza/drivers/active_record/indexes.rb +10 -0
- data/lib/baza/drivers/active_record/result.rb +23 -0
- data/lib/baza/drivers/active_record/tables.rb +12 -0
- data/lib/baza/drivers/mysql.rb +220 -0
- data/{include/drivers/mysql/mysql_column.rb → lib/baza/drivers/mysql/column.rb} +0 -0
- data/{include/drivers/mysql/mysql_columns.rb → lib/baza/drivers/mysql/columns.rb} +0 -0
- data/{include/drivers/mysql/mysql_index.rb → lib/baza/drivers/mysql/index.rb} +0 -0
- data/{include/drivers/mysql/mysql_indexes.rb → lib/baza/drivers/mysql/indexes.rb} +0 -0
- data/lib/baza/drivers/mysql/result.rb +81 -0
- data/{include/drivers/mysql/mysql_sqlspecs.rb → lib/baza/drivers/mysql/sqlspecs.rb} +0 -0
- data/{include/drivers/mysql/mysql_table.rb → lib/baza/drivers/mysql/table.rb} +2 -2
- data/{include/drivers/mysql/mysql_tables.rb → lib/baza/drivers/mysql/tables.rb} +0 -1
- data/{include/drivers/mysql/mysql_result_unbuffered.rb → lib/baza/drivers/mysql/unbuffered_result.rb} +19 -23
- data/lib/baza/drivers/mysql2.rb +259 -0
- data/lib/baza/drivers/mysql2/column.rb +2 -0
- data/lib/baza/drivers/mysql2/columns.rb +2 -0
- data/lib/baza/drivers/mysql2/index.rb +2 -0
- data/lib/baza/drivers/mysql2/indexes.rb +2 -0
- data/lib/baza/drivers/mysql2/result.rb +26 -0
- data/lib/baza/drivers/mysql2/table.rb +2 -0
- data/lib/baza/drivers/mysql2/tables.rb +2 -0
- data/lib/baza/drivers/mysql_java.rb +178 -0
- data/lib/baza/drivers/mysql_java/column.rb +2 -0
- data/lib/baza/drivers/mysql_java/columns.rb +2 -0
- data/lib/baza/drivers/mysql_java/index.rb +2 -0
- data/lib/baza/drivers/mysql_java/indexes.rb +2 -0
- data/lib/baza/drivers/mysql_java/table.rb +2 -0
- data/lib/baza/drivers/mysql_java/tables.rb +2 -0
- data/lib/baza/drivers/sqlite3.rb +81 -0
- data/{include/drivers/sqlite3/sqlite3_column.rb → lib/baza/drivers/sqlite3/column.rb} +0 -0
- data/{include/drivers/sqlite3/sqlite3_columns.rb → lib/baza/drivers/sqlite3/columns.rb} +0 -0
- data/{include/drivers/sqlite3/sqlite3_index.rb → lib/baza/drivers/sqlite3/index.rb} +0 -0
- data/{include/drivers/sqlite3/sqlite3_indexes.rb → lib/baza/drivers/sqlite3/indexes.rb} +0 -0
- data/lib/baza/drivers/sqlite3/result.rb +64 -0
- data/{include/drivers/sqlite3/sqlite3_sqlspecs.rb → lib/baza/drivers/sqlite3/sqlspecs.rb} +1 -1
- data/{include/drivers/sqlite3/sqlite3_table.rb → lib/baza/drivers/sqlite3/table.rb} +0 -0
- data/{include/drivers/sqlite3/sqlite3_tables.rb → lib/baza/drivers/sqlite3/tables.rb} +0 -0
- data/lib/baza/drivers/sqlite3/unbuffered_result.rb +33 -0
- data/lib/baza/drivers/sqlite3_java.rb +75 -0
- data/lib/baza/drivers/sqlite3_java/column.rb +2 -0
- data/lib/baza/drivers/sqlite3_java/columns.rb +2 -0
- data/lib/baza/drivers/sqlite3_java/index.rb +2 -0
- data/lib/baza/drivers/sqlite3_java/indexes.rb +2 -0
- data/lib/baza/drivers/sqlite3_java/table.rb +2 -0
- data/lib/baza/drivers/sqlite3_java/tables.rb +2 -0
- data/lib/baza/drivers/sqlite3_java/unbuffered_result.rb +33 -0
- data/lib/baza/drivers/sqlite3_rhodes.rb +78 -0
- data/{include → lib/baza}/dump.rb +0 -0
- data/{include → lib/baza}/errors.rb +0 -0
- data/{include → lib/baza}/idquery.rb +0 -0
- data/{include → lib/baza}/index.rb +0 -0
- data/lib/baza/jdbc_driver.rb +102 -0
- data/lib/baza/jdbc_result.rb +125 -0
- data/{include → lib/baza}/model.rb +2 -2
- data/{include → lib/baza}/model_custom.rb +0 -0
- data/{include → lib/baza}/model_handler.rb +1 -1
- data/{include → lib/baza}/model_handler_sqlhelper.rb +0 -0
- data/{include → lib/baza}/query_buffer.rb +2 -2
- data/lib/baza/result_base.rb +25 -0
- data/{include → lib/baza}/revision.rb +1 -1
- data/{include → lib/baza}/row.rb +0 -0
- data/{include → lib/baza}/sqlspecs.rb +0 -0
- data/{include → lib/baza}/table.rb +0 -0
- data/shippable.yml +3 -1
- data/spec/cloner_spec.rb +10 -0
- data/spec/drivers/active_record_mysql2_spec.rb +18 -0
- data/spec/drivers/active_record_mysql_spec.rb +16 -0
- data/spec/drivers/active_record_sqlite3_spec.rb +16 -0
- data/spec/drivers/mysql2_spec.rb +16 -0
- data/spec/{include/drivers → drivers}/mysql_spec.rb +9 -1
- data/spec/{include/drivers → drivers}/sqlite3_spec.rb +8 -0
- data/spec/info_active_record_mysql.rb +37 -0
- data/spec/info_active_record_mysql2.rb +37 -0
- data/spec/info_active_record_mysql2_shippable.rb +36 -0
- data/spec/info_active_record_mysql_shippable.rb +36 -0
- data/spec/info_active_record_sqlite3.rb +37 -0
- data/spec/info_mysql2_example.rb +23 -0
- data/spec/info_mysql2_shippable.rb +22 -0
- data/spec/info_mysql_example.rb +3 -4
- data/spec/info_mysql_shippable.rb +7 -17
- data/spec/info_sqlite3.rb +5 -4
- data/spec/model_handler_spec.rb +137 -105
- data/spec/spec_helper.rb +8 -0
- data/spec/support/driver_collection.rb +124 -34
- data/spec/support/driver_columns_collection.rb +0 -7
- data/spec/support/driver_indexes_collection.rb +4 -11
- data/spec/support/driver_tables_collection.rb +0 -7
- metadata +160 -52
- data/include/cloner.rb +0 -18
- data/include/drivers/active_record/active_record.rb +0 -159
- data/include/drivers/mysql/mysql.rb +0 -443
- data/include/drivers/mysql/mysql_result.rb +0 -42
- data/include/drivers/mysql/mysql_result_java.rb +0 -61
- data/include/drivers/mysql/mysql_result_mysql2.rb +0 -26
- data/include/drivers/sqlite3/sqlite3.rb +0 -159
- data/include/drivers/sqlite3/sqlite3_result.rb +0 -35
- data/include/drivers/sqlite3/sqlite3_result_java.rb +0 -39
- data/spec/include/cloner_spec.rb +0 -10
- data/spec/include/drivers/active_record_spec.rb +0 -8
- data/spec/info_active_record.rb +0 -49
- data/spec/info_active_record_shippable.rb +0 -47
@@ -0,0 +1,102 @@
|
|
1
|
+
class Baza::JdbcDriver < Baza::BaseSqlDriver
|
2
|
+
path = "#{File.dirname(__FILE__)}/mysql_java"
|
3
|
+
|
4
|
+
autoload :Table, "#{path}/table"
|
5
|
+
autoload :Tables, "#{path}/tables"
|
6
|
+
autoload :Column, "#{path}/column"
|
7
|
+
autoload :Columns, "#{path}/columns"
|
8
|
+
autoload :Index, "#{path}/index"
|
9
|
+
autoload :Indexes, "#{path}/indexes"
|
10
|
+
autoload :Result, "#{path}/result"
|
11
|
+
autoload :UnbufferedResult, "#{path}/unbuffered_result"
|
12
|
+
autoload :Sqlspecs, "#{path}/sqlspecs"
|
13
|
+
|
14
|
+
attr_reader :conn, :conns
|
15
|
+
|
16
|
+
def initialize(baza)
|
17
|
+
@java_rs_data = {}
|
18
|
+
@mutex = ::Mutex.new
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
# This method handels the closing of statements and results for the Java MySQL-mode.
|
23
|
+
def result_set_killer(id)
|
24
|
+
data = @java_rs_data[id]
|
25
|
+
return nil unless data
|
26
|
+
|
27
|
+
data[:res].close
|
28
|
+
data[:stmt].close
|
29
|
+
@java_rs_data.delete(id)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Executes a query and returns the result.
|
33
|
+
def query(str)
|
34
|
+
query_with_statement(str, @preload_results) do
|
35
|
+
@conn.create_statement
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Executes an unbuffered query and returns the result that can be used to access the data.
|
40
|
+
def query_ubuf(str)
|
41
|
+
query_with_statement(str, false) do
|
42
|
+
stmt = @conn.create_statement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY)
|
43
|
+
|
44
|
+
if @baza.opts[:type] == :sqlite3_java
|
45
|
+
stmt.fetch_size = 1
|
46
|
+
else
|
47
|
+
stmt.fetch_size = java.lang.Integer::MIN_VALUE
|
48
|
+
end
|
49
|
+
|
50
|
+
stmt
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Closes the connection threadsafe.
|
55
|
+
def close
|
56
|
+
@mutex.synchronize { @conn.close }
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def query_with_statement(sql, preload_results)
|
62
|
+
@mutex.synchronize do
|
63
|
+
begin
|
64
|
+
if sql.match(/^\s*(delete|update|create|drop|insert\s+into|alter|truncate)\s+/i)
|
65
|
+
return query_no_result_set(sql)
|
66
|
+
else
|
67
|
+
stmt = yield stmt
|
68
|
+
|
69
|
+
result_set = stmt.execute_query(sql)
|
70
|
+
result = Baza::JdbcResult.new(self, stmt, result_set, preload_results)
|
71
|
+
|
72
|
+
id = result.__id__
|
73
|
+
result_set_killer(id) if @java_rs_data.key?(id)
|
74
|
+
@java_rs_data[id] = {res: result_set, stmt: stmt}
|
75
|
+
ObjectSpace.define_finalizer(result, method(:result_set_killer))
|
76
|
+
|
77
|
+
return result
|
78
|
+
end
|
79
|
+
rescue java.sql.SQLException => e
|
80
|
+
result_set.close if result_set
|
81
|
+
stmt.close if stmt
|
82
|
+
@java_rs_data.delete(id) if result && id
|
83
|
+
|
84
|
+
if e.message == 'query does not return ResultSet'
|
85
|
+
return query_no_result_set(sql)
|
86
|
+
else
|
87
|
+
raise e
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def query_no_result_set(sql)
|
94
|
+
begin
|
95
|
+
stmt = @conn.create_statement
|
96
|
+
stmt.execute(sql)
|
97
|
+
return nil
|
98
|
+
ensure
|
99
|
+
stmt.close if stmt
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# This class controls the result for the Java-MySQL-driver.
|
2
|
+
class Baza::JdbcResult < Baza::ResultBase
|
3
|
+
INT_TYPES = {-6 => true, -5 => true, 4 => true, 5 => true}
|
4
|
+
FLOAT_TYPES = {2 => true, 3 => true, 7 => true, 8 => true}
|
5
|
+
TIME_TYPES = {93 => true}
|
6
|
+
DATE_TYPES = {91 => true}
|
7
|
+
STRING_TYPES = {-1 => true, 1 => true, 12 => true}
|
8
|
+
NIL_TYPES = {0 => true}
|
9
|
+
|
10
|
+
# Constructor. This should not be called manually.
|
11
|
+
def initialize(driver, stmt, result_set, preload_results)
|
12
|
+
@result_set = result_set
|
13
|
+
@stmt = stmt
|
14
|
+
@type_translation = driver.baza.opts[:type_translation]
|
15
|
+
@rows = []
|
16
|
+
@index = -1
|
17
|
+
read_results if preload_results
|
18
|
+
end
|
19
|
+
|
20
|
+
def fetch
|
21
|
+
if @read_results
|
22
|
+
return false if @rows.empty?
|
23
|
+
row = @rows.shift
|
24
|
+
else
|
25
|
+
return read_row
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def each
|
30
|
+
while data = fetch
|
31
|
+
yield data
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
# Reads meta-data about the query like keys and count.
|
38
|
+
def read_meta
|
39
|
+
@result_set.before_first
|
40
|
+
meta = @result_set.meta_data
|
41
|
+
@count = meta.column_count
|
42
|
+
|
43
|
+
@keys = []
|
44
|
+
|
45
|
+
if @type_translation == true
|
46
|
+
@types = []
|
47
|
+
@type_names = []
|
48
|
+
end
|
49
|
+
|
50
|
+
1.upto(@count) do |count|
|
51
|
+
@keys << meta.column_label(count).to_sym
|
52
|
+
|
53
|
+
if @type_translation == true
|
54
|
+
@types << meta.column_type(count)
|
55
|
+
@type_names << meta.column_type_name(count).downcase.to_sym
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def read_results
|
61
|
+
@read_results = true
|
62
|
+
|
63
|
+
loop do
|
64
|
+
if row = read_row
|
65
|
+
@rows << row
|
66
|
+
else
|
67
|
+
break
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def destroy
|
73
|
+
@stmt.close
|
74
|
+
@result_set.close
|
75
|
+
end
|
76
|
+
|
77
|
+
def read_row
|
78
|
+
return false unless @result_set
|
79
|
+
|
80
|
+
unless @result_set.next
|
81
|
+
destroy
|
82
|
+
@result_set = nil
|
83
|
+
return false
|
84
|
+
end
|
85
|
+
|
86
|
+
read_meta unless @keys
|
87
|
+
|
88
|
+
hash = {}
|
89
|
+
@count.times do |count|
|
90
|
+
if @type_translation
|
91
|
+
value = translate_type(@result_set, count)
|
92
|
+
else
|
93
|
+
value = @result_set.object(count + 1)
|
94
|
+
end
|
95
|
+
|
96
|
+
hash[@keys[count]] = value
|
97
|
+
end
|
98
|
+
|
99
|
+
return hash
|
100
|
+
end
|
101
|
+
|
102
|
+
def translate_type(result, count)
|
103
|
+
java_count = count + 1
|
104
|
+
|
105
|
+
return result.string(java_count) if @type_translation == :string
|
106
|
+
|
107
|
+
type = @types[count]
|
108
|
+
|
109
|
+
if INT_TYPES[type]
|
110
|
+
return result.int(java_count)
|
111
|
+
elsif STRING_TYPES[type]
|
112
|
+
return result.string(java_count)
|
113
|
+
elsif FLOAT_TYPES[type]
|
114
|
+
return result.float(java_count)
|
115
|
+
elsif TIME_TYPES[type] || @type_names[count] == :datetime # Important to do both in SQLite...
|
116
|
+
return Time.parse(result.string(java_count))
|
117
|
+
elsif DATE_TYPES[type]
|
118
|
+
return Date.parse(result.string(java_count))
|
119
|
+
elsif NIL_TYPES[type]
|
120
|
+
return nil
|
121
|
+
else
|
122
|
+
return result.object(java_count)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#This class helps create models in a framework with Baza::Db and Baza::ModelHandler.
|
2
2
|
#===Examples
|
3
|
-
# db = Baza::Db.new(:
|
4
|
-
# ob = Baza::ModelHandler.new(:
|
3
|
+
# db = Baza::Db.new(type: :sqlite3, path: "somepath.sqlite3")
|
4
|
+
# ob = Baza::ModelHandler.new(db: db, datarow: true, path: "path_of_model_class_files")
|
5
5
|
# user = ob.get(:User, 1) #=> <Models::User> that extends <Baza::Datarow>
|
6
6
|
class Baza::Model
|
7
7
|
@@refs = {}
|
File without changes
|
@@ -470,7 +470,7 @@ class Baza::ModelHandler
|
|
470
470
|
|
471
471
|
if required_data and !required_data.empty?
|
472
472
|
required_data.each do |req_data|
|
473
|
-
self.list(args[:class]
|
473
|
+
self.list(args[:class]) do |obj|
|
474
474
|
puts "Checking #{obj.classname}(#{obj.id}) for required #{req_data[:class]}." if args[:debug]
|
475
475
|
id = obj[req_data[:col]]
|
476
476
|
|
File without changes
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Baza::ResultBase
|
2
|
+
include Enumerable
|
3
|
+
|
4
|
+
def to_enum
|
5
|
+
@enum ||= Enumerator.new do |y|
|
6
|
+
each do |data|
|
7
|
+
y << data
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_a_enum
|
13
|
+
require 'array_enumerator'
|
14
|
+
@a_enum ||= ArrayEnumerator.new(to_enum)
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_a
|
18
|
+
array = []
|
19
|
+
each do |row_data|
|
20
|
+
array << row_data
|
21
|
+
end
|
22
|
+
|
23
|
+
return array
|
24
|
+
end
|
25
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#This class takes a database-schema from a hash and runs it against the database. It then checks that the database matches the given schema.
|
2
2
|
#
|
3
3
|
#===Examples
|
4
|
-
# db = Baza::Db.new(:
|
4
|
+
# db = Baza::Db.new(type: :sqlite3, path: "test_db.sqlite3")
|
5
5
|
# schema = {
|
6
6
|
# "tables" => {
|
7
7
|
# "User" => {
|
data/{include → lib/baza}/row.rb
RENAMED
File without changes
|
File without changes
|
File without changes
|
data/shippable.yml
CHANGED
@@ -6,7 +6,9 @@ rvm:
|
|
6
6
|
before_script:
|
7
7
|
- sudo apt-get -f install libmysql-java
|
8
8
|
- cp spec/info_mysql_shippable.rb spec/info_mysql.rb
|
9
|
-
- cp spec/
|
9
|
+
- cp spec/info_mysql2_shippable.rb spec/info_mysql2.rb
|
10
|
+
- cp spec/info_active_record_shippable_mysql.rb spec/info_active_record_mysql.rb
|
11
|
+
- cp spec/info_active_record_shippable_mysql2.rb spec/info_active_record_mysql2.rb
|
10
12
|
- mysql -e 'CREATE DATABASE baza;'
|
11
13
|
script:
|
12
14
|
- CODECLIMATE_REPO_TOKEN=98c06de7271764c9cd7bbde7cee4ddfa0d3e7db4bd9933f17779100276672e5f bundle exec rspec
|
data/spec/cloner_spec.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Baza::Cloner do
|
4
|
+
it 'can clone drivers' do
|
5
|
+
require 'info_active_record_mysql'
|
6
|
+
conn = Baza::InfoActiveRecordMysql.connection
|
7
|
+
baza_db = Baza::Cloner.from_active_record_connection(conn[:conn])
|
8
|
+
expect(baza_db.query('SELECT 1 AS test').fetch[:test].to_s).to eq '1'
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
unless RUBY_PLATFORM == 'java'
|
4
|
+
describe Baza::Driver::ActiveRecord do
|
5
|
+
let(:constant) {
|
6
|
+
name = described_class.name.split("::").last
|
7
|
+
const_name = "InfoActiveRecordMysql2"
|
8
|
+
require "#{File.dirname(__FILE__)}/../#{StringCases.camel_to_snake(const_name)}"
|
9
|
+
raise "Constant was not defined: '#{const_name}'." unless Baza.const_defined?(const_name)
|
10
|
+
Baza.const_get(const_name)
|
11
|
+
}
|
12
|
+
|
13
|
+
it_behaves_like "a baza driver"
|
14
|
+
it_should_behave_like "a baza tables driver"
|
15
|
+
it_should_behave_like "a baza columns driver"
|
16
|
+
it_should_behave_like "a baza indexes driver"
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Baza::Driver::ActiveRecord do
|
4
|
+
let(:constant) {
|
5
|
+
name = described_class.name.split("::").last
|
6
|
+
const_name = "InfoActiveRecordMysql"
|
7
|
+
require "#{File.dirname(__FILE__)}/../#{StringCases.camel_to_snake(const_name)}"
|
8
|
+
raise "Constant was not defined: '#{const_name}'." unless Baza.const_defined?(const_name)
|
9
|
+
Baza.const_get(const_name)
|
10
|
+
}
|
11
|
+
|
12
|
+
it_behaves_like "a baza driver"
|
13
|
+
it_should_behave_like "a baza tables driver"
|
14
|
+
it_should_behave_like "a baza columns driver"
|
15
|
+
it_should_behave_like "a baza indexes driver"
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Baza::Driver::ActiveRecord do
|
4
|
+
let(:constant) {
|
5
|
+
name = described_class.name.split("::").last
|
6
|
+
const_name = "InfoActiveRecordSqlite3"
|
7
|
+
require "#{File.dirname(__FILE__)}/../#{StringCases.camel_to_snake(const_name)}"
|
8
|
+
raise "Constant was not defined: '#{const_name}'." unless Baza.const_defined?(const_name)
|
9
|
+
Baza.const_get(const_name)
|
10
|
+
}
|
11
|
+
|
12
|
+
it_behaves_like "a baza driver"
|
13
|
+
it_should_behave_like "a baza tables driver"
|
14
|
+
it_should_behave_like "a baza columns driver"
|
15
|
+
it_should_behave_like "a baza indexes driver"
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Baza::Driver::Mysql2 do
|
4
|
+
let(:constant) do
|
5
|
+
name = described_class.name.split("::").last
|
6
|
+
const_name = "InfoMysql2"
|
7
|
+
require "#{File.dirname(__FILE__)}/../#{StringCases.camel_to_snake(const_name)}"
|
8
|
+
raise "Constant was not defined: '#{const_name}'." unless Baza.const_defined?(const_name)
|
9
|
+
Baza.const_get(const_name)
|
10
|
+
end
|
11
|
+
|
12
|
+
it_should_behave_like "a baza driver"
|
13
|
+
it_should_behave_like "a baza tables driver"
|
14
|
+
it_should_behave_like "a baza columns driver"
|
15
|
+
it_should_behave_like "a baza indexes driver"
|
16
|
+
end
|
@@ -1,6 +1,14 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe Baza
|
3
|
+
describe Baza.const_get(:Driver).const_get(:Mysql) do
|
4
|
+
let(:constant) do
|
5
|
+
name = described_class.name.split("::").last
|
6
|
+
const_name = "InfoMysql"
|
7
|
+
require "#{File.dirname(__FILE__)}/../#{StringCases.camel_to_snake(const_name)}"
|
8
|
+
raise "Constant was not defined: '#{const_name}'." unless Baza.const_defined?(const_name)
|
9
|
+
Baza.const_get(const_name)
|
10
|
+
end
|
11
|
+
|
4
12
|
it_should_behave_like "a baza driver"
|
5
13
|
it_should_behave_like "a baza tables driver"
|
6
14
|
it_should_behave_like "a baza columns driver"
|
@@ -1,6 +1,14 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Baza::Driver::Sqlite3 do
|
4
|
+
let(:constant) do
|
5
|
+
name = described_class.name.split("::").last
|
6
|
+
const_name = "InfoSqlite3"
|
7
|
+
require "#{File.dirname(__FILE__)}/../#{StringCases.camel_to_snake(const_name)}"
|
8
|
+
raise "Constant was not defined: '#{const_name}'." unless Baza.const_defined?(const_name)
|
9
|
+
Baza.const_get(const_name)
|
10
|
+
end
|
11
|
+
|
4
12
|
it_behaves_like "a baza driver"
|
5
13
|
it_should_behave_like "a baza tables driver"
|
6
14
|
it_should_behave_like "a baza columns driver"
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class Baza::InfoActiveRecordMysql
|
2
|
+
attr_reader :db
|
3
|
+
|
4
|
+
def self.connection
|
5
|
+
require "active_record"
|
6
|
+
|
7
|
+
conn_pool = ::ActiveRecord::Base.establish_connection(
|
8
|
+
adapter: "mysql",
|
9
|
+
host: "localhost",
|
10
|
+
database: "baza-test",
|
11
|
+
username: "baza-test",
|
12
|
+
password: "BBH7djRUKzL5nmG3"
|
13
|
+
)
|
14
|
+
conn = conn_pool.connection
|
15
|
+
|
16
|
+
return {pool: conn_pool, conn: conn}
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(args = {})
|
20
|
+
@data = Baza::InfoActiveRecordMysql.connection
|
21
|
+
|
22
|
+
@db = Baza::Db.new({
|
23
|
+
type: :active_record,
|
24
|
+
conn: @data[:conn]
|
25
|
+
}.merge(args))
|
26
|
+
end
|
27
|
+
|
28
|
+
def before
|
29
|
+
@db.tables.list.each do |name, table|
|
30
|
+
table.drop
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def after
|
35
|
+
@db.close
|
36
|
+
end
|
37
|
+
end
|