baza 0.0.13 → 0.0.14
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 +7 -0
- data/Gemfile +7 -4
- data/Gemfile.lock +84 -48
- data/README.md +186 -0
- data/VERSION +1 -1
- data/baza.gemspec +37 -22
- data/include/db.rb +153 -166
- data/include/dbtime.rb +2 -2
- data/include/driver.rb +9 -0
- data/include/drivers/active_record/active_record.rb +64 -27
- data/include/drivers/mysql/mysql_columns.rb +33 -33
- data/include/drivers/mysql/mysql_indexes.rb +26 -17
- data/include/drivers/mysql/mysql_tables.rb +140 -132
- data/include/drivers/sqlite3/sqlite3_indexes.rb +37 -9
- data/include/drivers/sqlite3/sqlite3_tables.rb +181 -152
- data/include/query_buffer.rb +22 -22
- data/include/revision.rb +70 -70
- data/lib/baza.rb +3 -1
- data/shippable.yml +11 -0
- data/spec/include/drivers/active_record_spec.rb +8 -0
- data/spec/include/drivers/mysql_spec.rb +47 -0
- data/spec/include/drivers/sqlite3_spec.rb +60 -0
- data/spec/info_active_record.rb +37 -0
- data/spec/info_active_record_example.rb +37 -0
- data/spec/info_active_record_shippable.rb +36 -0
- data/spec/info_mysql_example.rb +24 -6
- data/spec/info_mysql_shippable.rb +23 -0
- data/spec/info_sqlite3.rb +23 -15
- data/spec/model_handler_spec.rb +84 -84
- data/spec/spec_helper.rb +6 -6
- data/spec/support/driver_collection.rb +288 -0
- data/spec/support/driver_columns_collection.rb +49 -0
- data/spec/support/driver_indexes_collection.rb +49 -0
- data/spec/support/driver_tables_collection.rb +73 -0
- metadata +100 -102
- data/README.rdoc +0 -136
- data/spec/baza_spec.rb +0 -410
- data/spec/db_spec_encoding_test_file.txt +0 -1
@@ -0,0 +1,60 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Baza::Driver::Sqlite3 do
|
4
|
+
it_behaves_like "a baza driver"
|
5
|
+
it_should_behave_like "a baza tables driver"
|
6
|
+
it_should_behave_like "a baza columns driver"
|
7
|
+
it_should_behave_like "a baza indexes driver"
|
8
|
+
|
9
|
+
it "should copy database structure and data" do
|
10
|
+
require "info_sqlite3"
|
11
|
+
db = Baza::InfoSqlite3.new.db
|
12
|
+
db2 = Baza::InfoSqlite3.new.db
|
13
|
+
|
14
|
+
db.tables.create(:test_table, {
|
15
|
+
columns: [
|
16
|
+
{name: "id", type: :int, autoincr: true, primarykey: true},
|
17
|
+
{name: "testname", type: :varchar, null: true}
|
18
|
+
],
|
19
|
+
indexes: [
|
20
|
+
"testname"
|
21
|
+
]
|
22
|
+
})
|
23
|
+
|
24
|
+
table1 = db.tables["test_table"]
|
25
|
+
cols1 = table1.columns
|
26
|
+
|
27
|
+
100.times do |count|
|
28
|
+
table1.insert(testname: "TestRow#{count}")
|
29
|
+
end
|
30
|
+
|
31
|
+
expect {
|
32
|
+
table2 = db2.tables[:test_table]
|
33
|
+
}.to raise_error(Errno::ENOENT)
|
34
|
+
|
35
|
+
db.copy_to(db2)
|
36
|
+
|
37
|
+
table2 = db2.tables[:test_table]
|
38
|
+
|
39
|
+
cols2 = table2.columns
|
40
|
+
cols2.length.should eql(cols1.length)
|
41
|
+
|
42
|
+
table2.rows_count.should eql(table1.rows_count)
|
43
|
+
|
44
|
+
db.select(:test_table) do |row1|
|
45
|
+
found = 0
|
46
|
+
db2.select(:test_table, row1) do |row2|
|
47
|
+
found += 1
|
48
|
+
|
49
|
+
row1.each do |key, val|
|
50
|
+
row2[key].should eql(val)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
found.should eq 1
|
55
|
+
end
|
56
|
+
|
57
|
+
table1.indexes.length.should eq 1
|
58
|
+
table2.indexes.length.should eq table1.indexes.length
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class Baza::InfoActiveRecord
|
2
|
+
attr_reader :db
|
3
|
+
|
4
|
+
def self.connection
|
5
|
+
require "active_record"
|
6
|
+
|
7
|
+
@conn_pool ||= ::ActiveRecord::Base.establish_connection(
|
8
|
+
adapter: "mysql2",
|
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
|
20
|
+
data = Baza::InfoActiveRecord.connection
|
21
|
+
|
22
|
+
@db = Baza::Db.new(
|
23
|
+
type: :active_record,
|
24
|
+
conn: data[:conn]
|
25
|
+
)
|
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
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class Baza::InfoActiveRecord
|
2
|
+
attr_reader :db
|
3
|
+
|
4
|
+
def self.connection
|
5
|
+
require "active_record"
|
6
|
+
|
7
|
+
@conn_pool ||= ::ActiveRecord::Base.establish_connection(
|
8
|
+
adapter: "mysql2",
|
9
|
+
host: "localhost",
|
10
|
+
database: "baza-test",
|
11
|
+
username: "baza-test",
|
12
|
+
password: "password"
|
13
|
+
)
|
14
|
+
@conn ||= @conn_pool.connection
|
15
|
+
|
16
|
+
return {pool: @conn_pool, conn: @conn}
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
data = Baza::InfoActiveRecord.connection
|
21
|
+
|
22
|
+
@db = Baza::Db.new(
|
23
|
+
type: :active_record,
|
24
|
+
conn: data[:conn]
|
25
|
+
)
|
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
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class Baza::InfoActiveRecord
|
2
|
+
attr_reader :db
|
3
|
+
|
4
|
+
def self.connection
|
5
|
+
require "active_record"
|
6
|
+
|
7
|
+
@conn_pool ||= ::ActiveRecord::Base.establish_connection(
|
8
|
+
adapter: "mysql2",
|
9
|
+
host: "localhost",
|
10
|
+
database: "baza",
|
11
|
+
username: "shippa"
|
12
|
+
)
|
13
|
+
@conn ||= @conn_pool.connection
|
14
|
+
|
15
|
+
return {pool: @conn_pool, conn: @conn}
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
data = Baza::InfoActiveRecord.connection
|
20
|
+
|
21
|
+
@db = Baza::Db.new(
|
22
|
+
type: :active_record,
|
23
|
+
conn: data[:conn]
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def before
|
28
|
+
@db.tables.list.each do |name, table|
|
29
|
+
table.drop
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def after
|
34
|
+
@db.close
|
35
|
+
end
|
36
|
+
end
|
data/spec/info_mysql_example.rb
CHANGED
@@ -1,6 +1,24 @@
|
|
1
|
-
|
2
|
-
:
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
class Baza::InfoMysql
|
2
|
+
attr_reader :db
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@db = Baza::Db.new(
|
6
|
+
type: :mysql,
|
7
|
+
subtype: :mysql2,
|
8
|
+
host: "localhost",
|
9
|
+
user: "baza-test",
|
10
|
+
pass: "password",
|
11
|
+
db: "baza-test"
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
def before
|
16
|
+
@db.tables.list.each do |name, table|
|
17
|
+
table.drop
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def after
|
22
|
+
@db.close
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Baza::InfoMysql
|
2
|
+
attr_reader :db
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@db = Baza::Db.new(
|
6
|
+
type: :mysql,
|
7
|
+
subtype: :mysql2,
|
8
|
+
host: "localhost",
|
9
|
+
user: "shippa",
|
10
|
+
db: "baza"
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
def before
|
15
|
+
@db.tables.list.each do |name, table|
|
16
|
+
table.drop
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def after
|
21
|
+
@db.close
|
22
|
+
end
|
23
|
+
end
|
data/spec/info_sqlite3.rb
CHANGED
@@ -1,20 +1,28 @@
|
|
1
1
|
class Baza::InfoSqlite3
|
2
|
-
|
2
|
+
attr_reader :db
|
3
|
+
|
4
|
+
def initialize
|
3
5
|
require "sqlite3"
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
:
|
10
|
-
:
|
6
|
+
require "tmpdir"
|
7
|
+
|
8
|
+
@path = "#{Dir.tmpdir}/baza_sqlite3_test_#{Time.now.to_f.to_s.hash}.sqlite3"
|
9
|
+
File.unlink(path) if File.exists?(@path)
|
10
|
+
@db = Baza::Db.new(
|
11
|
+
type: :sqlite3,
|
12
|
+
path: @path,
|
13
|
+
index_append_table_name: true,
|
14
|
+
sql_to_error: true
|
11
15
|
)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
File.unlink(path)
|
16
|
+
end
|
17
|
+
|
18
|
+
def before
|
19
|
+
@db.tables.list.each do |name, table|
|
20
|
+
table.drop
|
18
21
|
end
|
19
22
|
end
|
20
|
-
|
23
|
+
|
24
|
+
def after
|
25
|
+
@db.close
|
26
|
+
File.unlink(@path)
|
27
|
+
end
|
28
|
+
end
|