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,170 @@
|
|
1
|
+
class Baza::SqlQueries::Select
|
2
|
+
def initialize(args)
|
3
|
+
@db = args.fetch(:db)
|
4
|
+
@selects = []
|
5
|
+
@froms = []
|
6
|
+
@joins = []
|
7
|
+
@wheres = []
|
8
|
+
@groups = []
|
9
|
+
@orders = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def select(arg)
|
13
|
+
@selects << arg
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def from(arg)
|
18
|
+
@froms << arg
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def join(arg)
|
23
|
+
@joins << arg
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def where(*args)
|
28
|
+
@wheres << args
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def group(arg)
|
33
|
+
@groups << arg
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
def order(arg)
|
38
|
+
@orders << arg
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
def limit(limit)
|
43
|
+
@limit = limit
|
44
|
+
self
|
45
|
+
end
|
46
|
+
|
47
|
+
def offset(offset)
|
48
|
+
@offset = offset
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_sql
|
53
|
+
"#{select_sql} #{from_sql} #{where_sql} #{group_sql} #{limit_sql}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_a
|
57
|
+
each.to_a
|
58
|
+
end
|
59
|
+
|
60
|
+
def each(&blk)
|
61
|
+
query(&blk)
|
62
|
+
end
|
63
|
+
|
64
|
+
def each_row
|
65
|
+
query do |data|
|
66
|
+
yield Baza::Row.new(
|
67
|
+
db: @db,
|
68
|
+
table: first_from,
|
69
|
+
data: data
|
70
|
+
)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def to_enum
|
75
|
+
Enumerator.new do |yielder|
|
76
|
+
query do |data|
|
77
|
+
yielder << data
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def query(&blk)
|
83
|
+
@db.query(to_sql, &blk)
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def select_sql
|
89
|
+
sql = "SELECT"
|
90
|
+
|
91
|
+
if @selects.empty?
|
92
|
+
sql << " *"
|
93
|
+
else
|
94
|
+
first = true
|
95
|
+
@selects.each do |select|
|
96
|
+
sql << "," unless first
|
97
|
+
first = false if first
|
98
|
+
|
99
|
+
if select.is_a?(Symbol)
|
100
|
+
select << " #{@db.sep_col}#{@db.escape_column(select)}#{@db.sep_col}"
|
101
|
+
else
|
102
|
+
select << @db.sqlval(select)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
sql
|
108
|
+
end
|
109
|
+
|
110
|
+
def from_sql
|
111
|
+
sql = "FROM"
|
112
|
+
|
113
|
+
first = true
|
114
|
+
@froms.each do |from|
|
115
|
+
sql << "," unless first
|
116
|
+
first = false if first
|
117
|
+
sql << " #{@db.sep_table}#{@db.escape_table(from)}#{@db.sep_table}"
|
118
|
+
end
|
119
|
+
|
120
|
+
sql
|
121
|
+
end
|
122
|
+
|
123
|
+
def first_from
|
124
|
+
@first_from ||= @froms.first
|
125
|
+
end
|
126
|
+
|
127
|
+
def where_sql
|
128
|
+
return if @wheres.empty?
|
129
|
+
|
130
|
+
sql = " WHERE"
|
131
|
+
|
132
|
+
first = true
|
133
|
+
@wheres.each do |args|
|
134
|
+
where = args.shift
|
135
|
+
|
136
|
+
sql << " AND " unless first
|
137
|
+
first = false if first
|
138
|
+
|
139
|
+
if where.is_a?(Hash)
|
140
|
+
where.each do |key, value|
|
141
|
+
sql << "#{@db.sep_col}#{@db.escape_column(key)}#{@db.sep_col} = #{@db.sqlval(value)}"
|
142
|
+
end
|
143
|
+
elsif where.is_a?(String)
|
144
|
+
sql_arg = where.clone
|
145
|
+
args.each do |arg|
|
146
|
+
sql_arg.sub!("?", @db.sqlval(arg))
|
147
|
+
end
|
148
|
+
|
149
|
+
sql << sql_arg
|
150
|
+
else
|
151
|
+
raise "Dont know what to do with that argument: #{where}"
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
sql
|
156
|
+
end
|
157
|
+
|
158
|
+
def group_sql
|
159
|
+
return if @groups.empty?
|
160
|
+
end
|
161
|
+
|
162
|
+
def limit_sql
|
163
|
+
if @limit
|
164
|
+
sql = "LIMIT #{@db.sqlval(@limit)}"
|
165
|
+
sql << ", #{@db.sqlval(@offset)}" if @offset
|
166
|
+
end
|
167
|
+
|
168
|
+
sql
|
169
|
+
end
|
170
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
class Baza::SqlQueries::SqliteUpsertDuplicateKey
|
2
|
+
def initialize(args)
|
3
|
+
@db = args.fetch(:db)
|
4
|
+
@table_name = args.fetch(:table_name)
|
5
|
+
@updates = StringCases.stringify_keys(args.fetch(:updates))
|
6
|
+
@terms = StringCases.stringify_keys(args.fetch(:terms))
|
7
|
+
@return_id = args[:return_id]
|
8
|
+
end
|
9
|
+
|
10
|
+
def execute
|
11
|
+
return insert_or_handle_duplicate if @terms.empty?
|
12
|
+
|
13
|
+
@db.transaction do
|
14
|
+
@db.query(insert_sql)
|
15
|
+
@db.query(update_sql)
|
16
|
+
|
17
|
+
if @return_id
|
18
|
+
data = @db.single(@table_name, @terms)
|
19
|
+
raise "Couldn't find the updated data" unless data
|
20
|
+
return data.fetch(primary_column).to_i
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def primary_column
|
28
|
+
@primary_column ||= @db.tables[@table_name.to_s].columns.find(&:primarykey?).name.to_sym
|
29
|
+
end
|
30
|
+
|
31
|
+
def insert_or_handle_duplicate
|
32
|
+
@db.insert(@table_name, @updates)
|
33
|
+
return @db.last_id if @return_id
|
34
|
+
rescue => e
|
35
|
+
if (match = e.message.match(/UNIQUE constraint failed: #{Regexp.escape(@table_name)}\.(.+?)(:|\Z|\))/))
|
36
|
+
column_name = match[1]
|
37
|
+
elsif (match = e.message.match(/column (.+?) is not unique/))
|
38
|
+
column_name = match[1]
|
39
|
+
else
|
40
|
+
raise e
|
41
|
+
end
|
42
|
+
|
43
|
+
conflicting_value = @updates.fetch(column_name)
|
44
|
+
@db.update(@table_name, @updates, column_name => conflicting_value)
|
45
|
+
|
46
|
+
if @return_id
|
47
|
+
data = @db.single(@table_name, column_name => conflicting_value)
|
48
|
+
raise "Couldn't find the updated data" unless data
|
49
|
+
return data.fetch(primary_column).to_i
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def insert_sql
|
54
|
+
sql = "INSERT OR IGNORE INTO #{@db.sep_table}#{@db.escape_table(@table_name)}#{@db.sep_table} ("
|
55
|
+
|
56
|
+
combined_data = @updates.merge(@terms)
|
57
|
+
|
58
|
+
first = true
|
59
|
+
combined_data.each_key do |column_name|
|
60
|
+
sql << ", " unless first
|
61
|
+
first = false if first
|
62
|
+
sql << "#{@db.sep_col}#{@db.escape_column(column_name)}#{@db.sep_col}"
|
63
|
+
end
|
64
|
+
|
65
|
+
sql << ") VALUES ("
|
66
|
+
|
67
|
+
first = true
|
68
|
+
combined_data.each_value do |value|
|
69
|
+
sql << ", " unless first
|
70
|
+
first = false if first
|
71
|
+
sql << @db.sqlval(value).to_s
|
72
|
+
end
|
73
|
+
|
74
|
+
sql << ")"
|
75
|
+
sql
|
76
|
+
end
|
77
|
+
|
78
|
+
def update_sql
|
79
|
+
sql = "UPDATE OR IGNORE #{@db.sep_table}#{@db.escape_table(@table_name)}#{@db.sep_table} SET "
|
80
|
+
|
81
|
+
first = true
|
82
|
+
@updates.each do |key, value|
|
83
|
+
sql << ", " unless first
|
84
|
+
first = false if first
|
85
|
+
sql << "#{@db.sep_col}#{@db.escape_column(key)}#{@db.sep_col} = #{@db.sqlval(value)}"
|
86
|
+
end
|
87
|
+
|
88
|
+
sql << " WHERE "
|
89
|
+
|
90
|
+
first = true
|
91
|
+
@terms.each do |key, value|
|
92
|
+
sql << " AND " unless first
|
93
|
+
first = false if first
|
94
|
+
sql << "#{@db.sep_col}#{@db.escape_column(key)}#{@db.sep_col} = #{@db.sqlval(value)}"
|
95
|
+
end
|
96
|
+
|
97
|
+
sql
|
98
|
+
end
|
99
|
+
end
|
data/lib/baza/table.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
class Baza::Table
|
2
|
+
include Comparable
|
2
3
|
include Baza::DatabaseModelFunctionality
|
3
4
|
|
4
5
|
attr_reader :db
|
@@ -24,17 +25,43 @@ class Baza::Table
|
|
24
25
|
end
|
25
26
|
|
26
27
|
def row(id)
|
27
|
-
|
28
|
-
raise Baza::Errors::RowNotFound unless
|
29
|
-
|
30
|
-
Baza::Row.new(
|
31
|
-
db: db,
|
32
|
-
table: name,
|
33
|
-
data: data
|
34
|
-
)
|
28
|
+
row = rows({id: id}, limit: 1).first
|
29
|
+
raise Baza::Errors::RowNotFound unless row
|
30
|
+
row
|
35
31
|
end
|
36
32
|
|
37
33
|
def to_param
|
38
34
|
name
|
39
35
|
end
|
36
|
+
|
37
|
+
def insert(data, args = {})
|
38
|
+
@db.insert(name, data, args)
|
39
|
+
end
|
40
|
+
|
41
|
+
def upsert_duplicate_key(data, terms = {}, args = {})
|
42
|
+
@db.upsert_duplicate_key(name, data, terms, args)
|
43
|
+
end
|
44
|
+
|
45
|
+
def rows_count
|
46
|
+
sql = "SELECT COUNT(*) AS count FROM #{@db.sep_table}#{@db.escape_table(name)}#{@db.sep_table}"
|
47
|
+
@db.query(sql).fetch.fetch(:count).to_i
|
48
|
+
end
|
49
|
+
|
50
|
+
def truncate
|
51
|
+
@db.query("TRUNCATE #{@db.sep_table}#{@db.escape_table(name)}#{@db.sep_table}")
|
52
|
+
self
|
53
|
+
end
|
54
|
+
|
55
|
+
def <=>(other)
|
56
|
+
return false unless other.is_a?(Baza::Table)
|
57
|
+
return false unless other.db.opts.fetch(:db) == db.opts.fetch(:db)
|
58
|
+
other.name <=> name
|
59
|
+
end
|
60
|
+
|
61
|
+
def create_columns(col_arr)
|
62
|
+
col_arr.each do |col_data|
|
63
|
+
sql = "ALTER TABLE #{db.sep_col}#{name}#{db.sep_col} ADD COLUMN #{@db.columns.data_sql(col_data)};"
|
64
|
+
@db.query(sql)
|
65
|
+
end
|
66
|
+
end
|
40
67
|
end
|
File without changes
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
1
|
unless RUBY_PLATFORM == "java"
|
2
|
+
require "spec_helper"
|
3
|
+
Baza.load_driver("active_record")
|
4
|
+
|
4
5
|
describe Baza::Driver::ActiveRecord do
|
5
6
|
let(:constant) do
|
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)
|
@@ -14,5 +14,7 @@ unless RUBY_PLATFORM == "java"
|
|
14
14
|
it_should_behave_like "a baza tables driver"
|
15
15
|
it_should_behave_like "a baza columns driver"
|
16
16
|
it_should_behave_like "a baza indexes driver"
|
17
|
+
it_should_behave_like "a baza users driver"
|
18
|
+
it_should_behave_like "an active record driver"
|
17
19
|
end
|
18
20
|
end
|
@@ -2,7 +2,6 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Baza::Driver::ActiveRecord do
|
4
4
|
let(:constant) do
|
5
|
-
name = described_class.name.split("::").last
|
6
5
|
const_name = "InfoActiveRecordMysql"
|
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)
|
@@ -13,4 +12,6 @@ describe Baza::Driver::ActiveRecord do
|
|
13
12
|
it_should_behave_like "a baza tables driver"
|
14
13
|
it_should_behave_like "a baza columns driver"
|
15
14
|
it_should_behave_like "a baza indexes driver"
|
15
|
+
it_should_behave_like "a baza users driver"
|
16
|
+
it_should_behave_like "an active record driver"
|
16
17
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
unless RUBY_PLATFORM == "java"
|
4
|
+
Baza.load_driver("active_record")
|
5
|
+
|
6
|
+
describe Baza::Driver::ActiveRecord do
|
7
|
+
let(:constant) do
|
8
|
+
const_name = "InfoActiveRecordPg"
|
9
|
+
require "#{File.dirname(__FILE__)}/../#{StringCases.camel_to_snake(const_name)}"
|
10
|
+
raise "Constant was not defined: '#{const_name}'." unless Baza.const_defined?(const_name)
|
11
|
+
Baza.const_get(const_name)
|
12
|
+
end
|
13
|
+
|
14
|
+
it_behaves_like "a baza driver"
|
15
|
+
it_should_behave_like "a baza tables driver"
|
16
|
+
it_should_behave_like "a baza columns driver"
|
17
|
+
it_should_behave_like "a baza indexes driver"
|
18
|
+
it_should_behave_like "an active record driver"
|
19
|
+
end
|
20
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require "spec_helper"
|
2
|
+
require_relative "../../lib/baza/driver/active_record"
|
2
3
|
|
3
4
|
describe Baza::Driver::ActiveRecord do
|
4
5
|
let(:constant) do
|
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)
|
@@ -13,4 +13,5 @@ describe Baza::Driver::ActiveRecord do
|
|
13
13
|
it_should_behave_like "a baza tables driver"
|
14
14
|
it_should_behave_like "a baza columns driver"
|
15
15
|
it_should_behave_like "a baza indexes driver"
|
16
|
+
it_should_behave_like "an active record driver"
|
16
17
|
end
|
data/spec/drivers/mysql2_spec.rb
CHANGED
@@ -2,7 +2,6 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Baza::Driver::Mysql2 do
|
4
4
|
let(:constant) do
|
5
|
-
name = described_class.name.split("::").last
|
6
5
|
const_name = "InfoMysql2"
|
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)
|
@@ -14,4 +13,5 @@ describe Baza::Driver::Mysql2 do
|
|
14
13
|
it_should_behave_like "a baza tables driver"
|
15
14
|
it_should_behave_like "a baza columns driver"
|
16
15
|
it_should_behave_like "a baza indexes driver"
|
16
|
+
it_should_behave_like "a baza users driver"
|
17
17
|
end
|
data/spec/drivers/mysql_spec.rb
CHANGED
@@ -2,7 +2,6 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Baza.const_get(:Driver).const_get(:Mysql) do
|
4
4
|
let(:constant) do
|
5
|
-
name = described_class.name.split("::").last
|
6
5
|
const_name = "InfoMysql"
|
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)
|
@@ -14,6 +13,7 @@ describe Baza.const_get(:Driver).const_get(:Mysql) do
|
|
14
13
|
it_should_behave_like "a baza tables driver"
|
15
14
|
it_should_behave_like "a baza columns driver"
|
16
15
|
it_should_behave_like "a baza indexes driver"
|
16
|
+
it_should_behave_like "a baza users driver"
|
17
17
|
|
18
18
|
it "should dump to sqlite3" do
|
19
19
|
require "info_sqlite3"
|
@@ -29,25 +29,25 @@ describe Baza.const_get(:Driver).const_get(:Mysql) do
|
|
29
29
|
|
30
30
|
begin
|
31
31
|
db1.tables.create(:test_table, columns: [
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
{name: :id, type: :int, autoincr: true, primarykey: true},
|
33
|
+
{name: :name, type: :varchar, maxlength: 100}
|
34
|
+
])
|
35
35
|
test_table = db1.tables[:test_table]
|
36
36
|
|
37
37
|
|
38
38
|
db1.copy_to(db2)
|
39
39
|
|
40
40
|
table_sqlite = db2.tables[:test_table]
|
41
|
-
table_sqlite.columns.length.
|
41
|
+
expect(table_sqlite.columns.length).to eq test_table.columns.length
|
42
42
|
|
43
43
|
col_id_sqlite = table_sqlite.column(:id)
|
44
|
-
col_id_sqlite.type.
|
45
|
-
col_id_sqlite.autoincr
|
46
|
-
col_id_sqlite.primarykey
|
44
|
+
expect(col_id_sqlite.type).to eq :int
|
45
|
+
expect(col_id_sqlite.autoincr?).to eq true
|
46
|
+
expect(col_id_sqlite.primarykey?).to eq true
|
47
47
|
|
48
48
|
col_name_sqlite = table_sqlite.column(:name)
|
49
|
-
col_name_sqlite.type.
|
50
|
-
col_name_sqlite.maxlength.to_i.
|
49
|
+
expect(col_name_sqlite.type).to eq :varchar
|
50
|
+
expect(col_name_sqlite.maxlength.to_i).to eq 100
|
51
51
|
ensure
|
52
52
|
driver1.after
|
53
53
|
driver2.after
|