baza 0.0.20 → 0.0.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +84 -0
- data/.rubocop_todo.yml +17 -135
- data/.travis.yml +21 -0
- data/Gemfile +10 -7
- data/Gemfile.lock +39 -44
- data/README.md +61 -3
- data/VERSION +1 -1
- data/baza.gemspec +146 -98
- data/config/best_project_practice_rubocop.yml +8 -0
- data/config/best_project_practice_rubocop_todo.yml +6 -0
- data/lib/baza.rb +8 -12
- data/lib/baza/base_sql_driver.rb +198 -52
- data/lib/baza/cloner.rb +1 -0
- data/lib/baza/column.rb +26 -0
- data/lib/baza/database.rb +19 -3
- data/lib/baza/db.rb +69 -271
- data/lib/baza/driver.rb +1 -6
- data/lib/baza/{drivers → driver}/active_record.rb +65 -21
- data/lib/baza/{drivers → driver}/active_record/columns.rb +0 -0
- data/lib/baza/driver/active_record/commands.rb +10 -0
- data/lib/baza/driver/active_record/databases.rb +10 -0
- data/lib/baza/{drivers → driver}/active_record/indexes.rb +0 -0
- data/lib/baza/{drivers → driver}/active_record/result.rb +3 -1
- data/lib/baza/{drivers → driver}/active_record/tables.rb +0 -0
- data/lib/baza/driver/active_record/users.rb +12 -0
- data/lib/baza/{drivers → driver}/mysql.rb +9 -26
- data/lib/baza/{drivers → driver}/mysql/column.rb +14 -35
- data/lib/baza/{drivers → driver}/mysql/columns.rb +9 -12
- data/lib/baza/driver/mysql/commands.rb +39 -0
- data/lib/baza/driver/mysql/database.rb +64 -0
- data/lib/baza/driver/mysql/databases.rb +63 -0
- data/lib/baza/{drivers → driver}/mysql/index.rb +0 -0
- data/lib/baza/{drivers → driver}/mysql/indexes.rb +0 -0
- data/lib/baza/{drivers → driver}/mysql/result.rb +15 -7
- data/lib/baza/{drivers → driver}/mysql/sqlspecs.rb +0 -0
- data/lib/baza/{drivers → driver}/mysql/table.rb +27 -43
- data/lib/baza/{drivers → driver}/mysql/tables.rb +5 -34
- data/lib/baza/{drivers → driver}/mysql/unbuffered_result.rb +8 -2
- data/lib/baza/driver/mysql/user.rb +22 -0
- data/lib/baza/driver/mysql/users.rb +39 -0
- data/lib/baza/{drivers → driver}/mysql2.rb +19 -49
- data/lib/baza/{drivers → driver}/mysql2/column.rb +0 -0
- data/lib/baza/{drivers → driver}/mysql2/columns.rb +0 -0
- data/lib/baza/driver/mysql2/commands.rb +2 -0
- data/lib/baza/{drivers → driver}/mysql2/database.rb +0 -0
- data/lib/baza/{drivers → driver}/mysql2/databases.rb +0 -0
- data/lib/baza/{drivers → driver}/mysql2/index.rb +0 -0
- data/lib/baza/{drivers → driver}/mysql2/indexes.rb +0 -0
- data/lib/baza/{drivers → driver}/mysql2/result.rb +3 -1
- data/lib/baza/{drivers → driver}/mysql2/table.rb +0 -0
- data/lib/baza/{drivers → driver}/mysql2/tables.rb +0 -0
- data/lib/baza/driver/mysql2/user.rb +2 -0
- data/lib/baza/driver/mysql2/users.rb +2 -0
- data/lib/baza/{drivers → driver}/mysql_java.rb +60 -38
- data/lib/baza/{drivers → driver}/mysql_java/column.rb +0 -0
- data/lib/baza/{drivers → driver}/mysql_java/columns.rb +0 -0
- data/lib/baza/driver/mysql_java/commands.rb +2 -0
- data/lib/baza/driver/mysql_java/database.rb +2 -0
- data/lib/baza/driver/mysql_java/databases.rb +2 -0
- data/lib/baza/{drivers → driver}/mysql_java/index.rb +0 -0
- data/lib/baza/{drivers → driver}/mysql_java/indexes.rb +0 -0
- data/lib/baza/{drivers → driver}/mysql_java/table.rb +0 -0
- data/lib/baza/{drivers → driver}/mysql_java/tables.rb +0 -0
- data/lib/baza/driver/mysql_java/user.rb +2 -0
- data/lib/baza/driver/mysql_java/users.rb +2 -0
- data/lib/baza/driver/pg.rb +80 -0
- data/lib/baza/driver/pg/column.rb +125 -0
- data/lib/baza/driver/pg/columns.rb +37 -0
- data/lib/baza/driver/pg/commands.rb +35 -0
- data/lib/baza/driver/pg/create_index_sql_creator.rb +51 -0
- data/lib/baza/driver/pg/database.rb +89 -0
- data/lib/baza/driver/pg/databases.rb +79 -0
- data/lib/baza/driver/pg/index.rb +35 -0
- data/lib/baza/driver/pg/indexes.rb +5 -0
- data/lib/baza/driver/pg/result.rb +139 -0
- data/lib/baza/driver/pg/table.rb +184 -0
- data/lib/baza/driver/pg/tables.rb +45 -0
- data/lib/baza/{drivers → driver}/sqlite3.rb +6 -24
- data/lib/baza/{drivers → driver}/sqlite3/column.rb +22 -24
- data/lib/baza/{drivers → driver}/sqlite3/columns.rb +6 -6
- data/lib/baza/driver/sqlite3/commands.rb +28 -0
- data/lib/baza/{drivers → driver}/sqlite3/database.rb +0 -0
- data/lib/baza/{drivers → driver}/sqlite3/databases.rb +0 -1
- data/lib/baza/{drivers → driver}/sqlite3/index.rb +0 -0
- data/lib/baza/{drivers → driver}/sqlite3/indexes.rb +0 -0
- data/lib/baza/{drivers → driver}/sqlite3/result.rb +14 -6
- data/lib/baza/{drivers → driver}/sqlite3/sqlspecs.rb +0 -0
- data/lib/baza/{drivers → driver}/sqlite3/table.rb +25 -16
- data/lib/baza/{drivers → driver}/sqlite3/tables.rb +5 -6
- data/lib/baza/{drivers → driver}/sqlite3/unbuffered_result.rb +8 -2
- data/lib/baza/{drivers → driver}/sqlite3_java.rb +13 -23
- data/lib/baza/{drivers → driver}/sqlite3_java/column.rb +0 -0
- data/lib/baza/{drivers → driver}/sqlite3_java/columns.rb +0 -0
- data/lib/baza/driver/sqlite3_java/commands.rb +2 -0
- data/lib/baza/{drivers → driver}/sqlite3_java/database.rb +0 -0
- data/lib/baza/{drivers → driver}/sqlite3_java/index.rb +0 -0
- data/lib/baza/{drivers → driver}/sqlite3_java/indexes.rb +0 -0
- data/lib/baza/{drivers → driver}/sqlite3_java/table.rb +0 -0
- data/lib/baza/{drivers → driver}/sqlite3_java/tables.rb +0 -0
- data/lib/baza/{drivers → driver}/sqlite3_java/unbuffered_result.rb +14 -9
- data/lib/baza/{drivers → driver}/sqlite3_rhodes.rb +6 -24
- data/lib/baza/errors.rb +2 -0
- data/lib/baza/idquery.rb +15 -8
- data/lib/baza/index.rb +7 -0
- data/lib/baza/jdbc_driver.rb +4 -16
- data/lib/baza/jdbc_result.rb +20 -12
- data/lib/baza/mysql_base_driver.rb +7 -7
- data/lib/baza/query_buffer.rb +20 -19
- data/lib/baza/row.rb +16 -16
- data/lib/baza/sql_queries.rb +3 -0
- data/lib/baza/sql_queries/generic_insert.rb +81 -0
- data/lib/baza/sql_queries/generic_update.rb +31 -0
- data/lib/baza/sql_queries/mysql_upsert.rb +52 -0
- data/lib/baza/sql_queries/mysql_upsert_duplicate_key.rb +57 -0
- data/lib/baza/sql_queries/non_atomic_upsert.rb +25 -0
- data/lib/baza/sql_queries/postgres_upsert_duplicate_key.rb +118 -0
- data/lib/baza/sql_queries/select.rb +170 -0
- data/lib/baza/sql_queries/sqlite_upsert_duplicate_key.rb +99 -0
- data/lib/baza/table.rb +35 -8
- data/spec/active_record/models/user.rb +3 -0
- data/spec/{cloner_spec.rb → baza/cloner_spec.rb} +0 -0
- data/spec/drivers/active_record_mysql2_spec.rb +5 -3
- data/spec/drivers/active_record_mysql_spec.rb +2 -1
- data/spec/drivers/active_record_pg_spec.rb +20 -0
- data/spec/drivers/active_record_sqlite3_spec.rb +2 -1
- data/spec/drivers/mysql2_spec.rb +1 -1
- data/spec/drivers/mysql_spec.rb +10 -10
- data/spec/drivers/pg_spec.rb +18 -0
- data/spec/drivers/sqlite3_spec.rb +7 -8
- data/spec/info_active_record_example.rb +1 -1
- data/spec/{info_active_record_mysql2.rb → info_active_record_mysql2_example.rb} +3 -2
- data/spec/info_active_record_mysql2_travis.rb +35 -0
- data/spec/{info_active_record_mysql.rb → info_active_record_mysql_example.rb} +5 -4
- data/spec/info_active_record_mysql_travis.rb +36 -0
- data/spec/info_active_record_pg_example.rb +36 -0
- data/spec/info_active_record_pg_travis.rb +34 -0
- data/spec/info_active_record_sqlite3.rb +1 -1
- data/spec/info_mysql2_example.rb +1 -3
- data/spec/{info_mysql2_shippable.rb → info_mysql2_travis.rb} +2 -4
- data/spec/info_mysql_example.rb +1 -3
- data/spec/{info_mysql_shippable.rb → info_mysql_travis.rb} +2 -4
- data/spec/info_pg_example.rb +22 -0
- data/spec/info_pg_travis.rb +20 -0
- data/spec/info_sqlite3.rb +1 -3
- data/spec/spec_helper.rb +1 -1
- data/spec/support/driver_active_record_collection.rb +62 -0
- data/spec/support/driver_collection.rb +136 -121
- data/spec/support/driver_columns_collection.rb +19 -10
- data/spec/support/driver_databases_collection.rb +23 -1
- data/spec/support/driver_indexes_collection.rb +2 -2
- data/spec/support/driver_tables_collection.rb +24 -4
- data/spec/support/driver_users_collection.rb +53 -0
- metadata +185 -104
- data/lib/baza/drivers/mysql/database.rb +0 -28
- data/lib/baza/drivers/mysql/databases.rb +0 -35
- data/lib/baza/drivers/mysql_java/database.rb +0 -2
- data/lib/baza/drivers/mysql_java/databases.rb +0 -2
- data/lib/baza/model.rb +0 -875
- data/lib/baza/model_custom.rb +0 -155
- data/lib/baza/model_handler.rb +0 -910
- data/lib/baza/model_handler_sqlhelper.rb +0 -484
- data/lib/baza/revision.rb +0 -383
- data/shippable.yml +0 -17
- data/spec/info_active_record_mysql2_shippable.rb +0 -34
- data/spec/info_active_record_mysql_shippable.rb +0 -34
- data/spec/model_handler_spec.rb +0 -431
@@ -0,0 +1,18 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
unless RUBY_PLATFORM == "java"
|
4
|
+
describe Baza.const_get(:Driver).const_get(:Pg) do
|
5
|
+
let(:constant) do
|
6
|
+
const_name = "InfoPg"
|
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 databases 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
|
@@ -2,7 +2,6 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Baza::Driver::Sqlite3 do
|
4
4
|
let(:constant) do
|
5
|
-
name = described_class.name.split("::").last
|
6
5
|
const_name = "InfoSqlite3"
|
7
6
|
require "#{File.dirname(__FILE__)}/../#{StringCases.camel_to_snake(const_name)}"
|
8
7
|
raise "Constant was not defined: '#{const_name}'." unless Baza.const_defined?(const_name)
|
@@ -37,16 +36,16 @@ describe Baza::Driver::Sqlite3 do
|
|
37
36
|
table1.insert(testname: "TestRow#{count}")
|
38
37
|
end
|
39
38
|
|
40
|
-
expect {
|
39
|
+
expect { db2.tables[:test_table] }.to raise_error(Baza::Errors::TableNotFound)
|
41
40
|
|
42
41
|
db.copy_to(db2)
|
43
42
|
|
44
43
|
table2 = db2.tables[:test_table]
|
45
44
|
|
46
45
|
cols2 = table2.columns
|
47
|
-
cols2.length.
|
46
|
+
expect(cols2.length).to eql(cols1.length)
|
48
47
|
|
49
|
-
table2.rows_count.
|
48
|
+
expect(table2.rows_count).to eq table1.rows_count
|
50
49
|
|
51
50
|
db.select(:test_table) do |row1|
|
52
51
|
found = 0
|
@@ -54,14 +53,14 @@ describe Baza::Driver::Sqlite3 do
|
|
54
53
|
found += 1
|
55
54
|
|
56
55
|
row1.each do |key, val|
|
57
|
-
row2[key].
|
56
|
+
expect(row2[key]).to eql(val)
|
58
57
|
end
|
59
58
|
end
|
60
59
|
|
61
|
-
found.
|
60
|
+
expect(found).to eq 1
|
62
61
|
end
|
63
62
|
|
64
|
-
table1.indexes.length.
|
65
|
-
table2.indexes.length.
|
63
|
+
expect(table1.indexes.length).to eq 1
|
64
|
+
expect(table2.indexes.length).to eq table1.indexes.length
|
66
65
|
end
|
67
66
|
end
|
@@ -3,13 +3,14 @@ class Baza::InfoActiveRecordMysql2
|
|
3
3
|
|
4
4
|
def self.connection
|
5
5
|
require "active_record"
|
6
|
+
require "activerecord-jdbc-adapter" if RUBY_PLATFORM == "java"
|
6
7
|
|
7
8
|
@conn_pool ||= ::ActiveRecord::Base.establish_connection(
|
8
9
|
adapter: "mysql2",
|
9
10
|
host: "localhost",
|
10
11
|
database: "baza-test",
|
11
12
|
username: "baza-test",
|
12
|
-
password: "
|
13
|
+
password: "password"
|
13
14
|
)
|
14
15
|
@conn ||= @conn_pool.connection
|
15
16
|
|
@@ -21,7 +22,7 @@ class Baza::InfoActiveRecordMysql2
|
|
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
|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class Baza::InfoActiveRecordMysql2
|
2
|
+
attr_reader :db
|
3
|
+
|
4
|
+
def self.connection
|
5
|
+
require "active_record"
|
6
|
+
require "activerecord-jdbc-adapter" if RUBY_PLATFORM == "java"
|
7
|
+
|
8
|
+
@conn_pool ||= ::ActiveRecord::Base.establish_connection(
|
9
|
+
adapter: "mysql2",
|
10
|
+
host: "localhost",
|
11
|
+
database: "baza",
|
12
|
+
username: "travis"
|
13
|
+
)
|
14
|
+
@conn = @conn_pool.connection
|
15
|
+
|
16
|
+
{pool: @conn_pool, conn: @conn}
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(args = {})
|
20
|
+
data = Baza::InfoActiveRecordMysql2.connection
|
21
|
+
|
22
|
+
@db = Baza::Db.new({
|
23
|
+
type: :active_record,
|
24
|
+
conn: data.fetch(:conn)
|
25
|
+
}.merge(args))
|
26
|
+
end
|
27
|
+
|
28
|
+
def before
|
29
|
+
@db.tables.list(&:drop)
|
30
|
+
end
|
31
|
+
|
32
|
+
def after
|
33
|
+
@db.close
|
34
|
+
end
|
35
|
+
end
|
@@ -3,13 +3,14 @@ class Baza::InfoActiveRecordMysql
|
|
3
3
|
|
4
4
|
def self.connection
|
5
5
|
require "active_record"
|
6
|
+
require "activerecord-jdbc-adapter" if RUBY_PLATFORM == "java"
|
6
7
|
|
7
8
|
@conn_pool ||= ::ActiveRecord::Base.establish_connection(
|
8
9
|
adapter: "mysql",
|
9
10
|
host: "localhost",
|
10
11
|
database: "baza-test",
|
11
12
|
username: "baza-test",
|
12
|
-
password: "
|
13
|
+
password: "password"
|
13
14
|
)
|
14
15
|
@conn ||= @conn_pool.connection
|
15
16
|
|
@@ -17,12 +18,12 @@ class Baza::InfoActiveRecordMysql
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def initialize(args = {})
|
20
|
-
|
21
|
-
|
21
|
+
data = Baza::InfoActiveRecordMysql.connection
|
22
|
+
data.fetch(:conn).reconnect!
|
22
23
|
|
23
24
|
@db = Baza::Db.new({
|
24
25
|
type: :active_record,
|
25
|
-
conn:
|
26
|
+
conn: data.fetch(:conn)
|
26
27
|
}.merge(args))
|
27
28
|
end
|
28
29
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class Baza::InfoActiveRecordMysql
|
2
|
+
attr_reader :db
|
3
|
+
|
4
|
+
def self.connection
|
5
|
+
require "active_record"
|
6
|
+
require "activerecord-jdbc-adapter" if RUBY_PLATFORM == "java"
|
7
|
+
|
8
|
+
@conn_pool ||= ::ActiveRecord::Base.establish_connection(
|
9
|
+
adapter: "mysql",
|
10
|
+
host: "localhost",
|
11
|
+
database: "baza",
|
12
|
+
username: "travis"
|
13
|
+
)
|
14
|
+
@conn ||= @conn_pool.connection
|
15
|
+
|
16
|
+
{pool: @conn_pool, conn: @conn}
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(args = {})
|
20
|
+
data = Baza::InfoActiveRecordMysql.connection
|
21
|
+
data.fetch(:conn).reconnect!
|
22
|
+
|
23
|
+
@db = Baza::Db.new({
|
24
|
+
type: :active_record,
|
25
|
+
conn: data.fetch(:conn)
|
26
|
+
}.merge(args))
|
27
|
+
end
|
28
|
+
|
29
|
+
def before
|
30
|
+
@db.tables.list(&:drop)
|
31
|
+
end
|
32
|
+
|
33
|
+
def after
|
34
|
+
@db.close
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class Baza::InfoActiveRecordPg
|
2
|
+
attr_reader :db
|
3
|
+
|
4
|
+
def self.connection
|
5
|
+
require "active_record"
|
6
|
+
require "pg"
|
7
|
+
|
8
|
+
@conn_pool ||= ::ActiveRecord::Base.establish_connection(
|
9
|
+
adapter: "postgresql",
|
10
|
+
host: "localhost",
|
11
|
+
database: "baza-test",
|
12
|
+
username: "baza-test",
|
13
|
+
password: "password"
|
14
|
+
)
|
15
|
+
@conn ||= @conn_pool.connection
|
16
|
+
|
17
|
+
{pool: @conn_pool, conn: @conn}
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(args = {})
|
21
|
+
data = Baza::InfoActiveRecordPg.connection
|
22
|
+
|
23
|
+
@db = Baza::Db.new({
|
24
|
+
type: :active_record,
|
25
|
+
conn: data.fetch(:conn)
|
26
|
+
}.merge(args))
|
27
|
+
end
|
28
|
+
|
29
|
+
def before
|
30
|
+
@db.tables.list(&:drop)
|
31
|
+
end
|
32
|
+
|
33
|
+
def after
|
34
|
+
@db.close
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class Baza::InfoActiveRecordPg
|
2
|
+
attr_reader :db
|
3
|
+
|
4
|
+
def self.connection
|
5
|
+
require "active_record"
|
6
|
+
require "pg"
|
7
|
+
|
8
|
+
@conn_pool ||= ::ActiveRecord::Base.establish_connection(
|
9
|
+
adapter: "postgresql",
|
10
|
+
database: "baza",
|
11
|
+
username: "postgres"
|
12
|
+
)
|
13
|
+
@conn ||= @conn_pool.connection
|
14
|
+
|
15
|
+
{pool: @conn_pool, conn: @conn}
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(args = {})
|
19
|
+
data = Baza::InfoActiveRecordPg.connection
|
20
|
+
|
21
|
+
@db = Baza::Db.new({
|
22
|
+
type: :active_record,
|
23
|
+
conn: data.fetch(:conn)
|
24
|
+
}.merge(args))
|
25
|
+
end
|
26
|
+
|
27
|
+
def before
|
28
|
+
@db.tables.list(&:drop)
|
29
|
+
end
|
30
|
+
|
31
|
+
def after
|
32
|
+
@db.close
|
33
|
+
end
|
34
|
+
end
|
data/spec/info_mysql2_example.rb
CHANGED
@@ -5,15 +5,13 @@ class Baza::InfoMysql2
|
|
5
5
|
@db = Baza::Db.new({
|
6
6
|
type: :mysql2,
|
7
7
|
host: "localhost",
|
8
|
-
user: "
|
8
|
+
user: "travis",
|
9
9
|
db: "baza"
|
10
10
|
}.merge(args))
|
11
11
|
end
|
12
12
|
|
13
13
|
def before
|
14
|
-
@db.tables.list
|
15
|
-
table.drop
|
16
|
-
end
|
14
|
+
@db.tables.list(&:drop)
|
17
15
|
end
|
18
16
|
|
19
17
|
def after
|
data/spec/info_mysql_example.rb
CHANGED
@@ -5,15 +5,13 @@ class Baza::InfoMysql
|
|
5
5
|
@db = Baza::Db.new({
|
6
6
|
type: :mysql,
|
7
7
|
host: "localhost",
|
8
|
-
user: "
|
8
|
+
user: "travis",
|
9
9
|
db: "baza"
|
10
10
|
}.merge(args))
|
11
11
|
end
|
12
12
|
|
13
13
|
def before
|
14
|
-
@db.tables.list
|
15
|
-
table.drop
|
16
|
-
end
|
14
|
+
@db.tables.list(&:drop)
|
17
15
|
end
|
18
16
|
|
19
17
|
def after
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class Baza::InfoPg
|
2
|
+
attr_reader :db
|
3
|
+
|
4
|
+
def initialize(args = {})
|
5
|
+
@db = Baza::Db.new({
|
6
|
+
type: :pg,
|
7
|
+
host: "127.0.0.1",
|
8
|
+
user: "baza-test",
|
9
|
+
pass: "password",
|
10
|
+
db: "baza-test",
|
11
|
+
debug: false
|
12
|
+
}.merge(args))
|
13
|
+
end
|
14
|
+
|
15
|
+
def before
|
16
|
+
@db.tables.list(&:drop)
|
17
|
+
end
|
18
|
+
|
19
|
+
def after
|
20
|
+
@db.close
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Baza::InfoPg
|
2
|
+
attr_reader :db
|
3
|
+
|
4
|
+
def initialize(args = {})
|
5
|
+
@db = Baza::Db.new({
|
6
|
+
type: :pg,
|
7
|
+
user: "postgres",
|
8
|
+
db: "baza",
|
9
|
+
debug: false
|
10
|
+
}.merge(args))
|
11
|
+
end
|
12
|
+
|
13
|
+
def before
|
14
|
+
@db.tables.list(&:drop)
|
15
|
+
end
|
16
|
+
|
17
|
+
def after
|
18
|
+
@db.close
|
19
|
+
end
|
20
|
+
end
|
data/spec/info_sqlite3.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,62 @@
|
|
1
|
+
require "active_record"
|
2
|
+
require_relative "../active_record/models/user"
|
3
|
+
|
4
|
+
shared_examples_for "an active record driver" do
|
5
|
+
let(:driver) { constant.new(type_translation: true) }
|
6
|
+
let(:db) { driver.db }
|
7
|
+
let(:db_with_type_translation) { constant.new(type_translation: true, debug: false).db }
|
8
|
+
let(:row) do
|
9
|
+
test_table.insert(text: "Kasper", number: 30, float: 4.5)
|
10
|
+
db.select(:test, text: "Kasper").fetch
|
11
|
+
end
|
12
|
+
let(:test_table) do
|
13
|
+
db.tables.create(
|
14
|
+
"test",
|
15
|
+
columns: [
|
16
|
+
{name: "id", type: :int, autoincr: true, primarykey: true},
|
17
|
+
{name: "text", type: :varchar},
|
18
|
+
{name: "number", type: :int, default: 0},
|
19
|
+
{name: "float", type: :float, default: 0.0}
|
20
|
+
]
|
21
|
+
)
|
22
|
+
db.tables[:test]
|
23
|
+
end
|
24
|
+
|
25
|
+
before do
|
26
|
+
driver.before
|
27
|
+
|
28
|
+
db.tables.create(
|
29
|
+
"users",
|
30
|
+
columns: [
|
31
|
+
{name: "id", type: :int, autoincr: true, primarykey: true},
|
32
|
+
{name: "email", type: :varchar}
|
33
|
+
],
|
34
|
+
indexes: [
|
35
|
+
{name: "index_on_email", columns: ["email"], unique: true}
|
36
|
+
]
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
after do
|
41
|
+
driver.after
|
42
|
+
end
|
43
|
+
|
44
|
+
it "saves models through baza" do
|
45
|
+
user = User.new(email: "test@example.com")
|
46
|
+
expect(user.valid?).to eq true
|
47
|
+
db.driver.save_model!(user, update_on_duplicate_key: true)
|
48
|
+
expect(user.persisted?).to eq true
|
49
|
+
expect(user.id).to eq 1
|
50
|
+
expect(user.email).to eq "test@example.com"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "upserts" do
|
54
|
+
user1 = User.new(email: "test@example.com")
|
55
|
+
db.driver.save_model!(user1)
|
56
|
+
|
57
|
+
user2 = User.new(email: "test@example.com")
|
58
|
+
db.driver.save_model!(user2, update_on_duplicate_key: true)
|
59
|
+
|
60
|
+
expect(user2.id).to eq user1.id
|
61
|
+
end
|
62
|
+
end
|