yaml_db 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/yaml_db/serialization_helper.rb +16 -3
- data/lib/yaml_db/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a4e39c17d583195897d45248f0aca67b9cbdb31
|
4
|
+
data.tar.gz: fdcf74702568fb3fafe04cd4956a0c25cf9f4c48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 228b520f88360a5fc698f5809bc0b917c6669d74156c7d0f174631c59c76d8bcb3b09e9eaa982cff136f5bf8a1e9ea59cc99391a6bc570d3548c2f39c998ea8b
|
7
|
+
data.tar.gz: 0e329ffcd25e425cd75da70cc8ebc51299c14308d3614169b6692f186c876c725ce3b6da9e63657a698655e5d3acfd0b649d029d0d677dc477f6dbea2e053f05
|
@@ -141,6 +141,9 @@ module YamlDb
|
|
141
141
|
ActiveRecord::Base.connection.quote_table_name(table)
|
142
142
|
end
|
143
143
|
|
144
|
+
def self.quote_column(column)
|
145
|
+
ActiveRecord::Base.connection.quote_column_name(column)
|
146
|
+
end
|
144
147
|
end
|
145
148
|
|
146
149
|
class Dump
|
@@ -179,12 +182,12 @@ module YamlDb
|
|
179
182
|
def self.each_table_page(table, records_per_page=1000)
|
180
183
|
total_count = table_record_count(table)
|
181
184
|
pages = (total_count.to_f / records_per_page).ceil - 1
|
182
|
-
|
185
|
+
key = sort_key(table)
|
183
186
|
boolean_columns = Utils.boolean_columns(table)
|
184
187
|
quoted_table_name = Utils.quote_table(table)
|
185
188
|
|
186
189
|
(0..pages).to_a.each do |page|
|
187
|
-
query = Arel::Table.new(table).order(
|
190
|
+
query = Arel::Table.new(table).order(key).skip(records_per_page*page).take(records_per_page).project(Arel.sql('*'))
|
188
191
|
records = ActiveRecord::Base.connection.select_all(query.to_sql)
|
189
192
|
records = Utils.convert_booleans(records, boolean_columns)
|
190
193
|
yield records
|
@@ -195,7 +198,17 @@ module YamlDb
|
|
195
198
|
ActiveRecord::Base.connection.select_one("SELECT COUNT(*) FROM #{Utils.quote_table(table)}").values.first.to_i
|
196
199
|
end
|
197
200
|
|
198
|
-
|
201
|
+
# Just return the first column as sort key unless the table looks like a
|
202
|
+
# standard HABTM join table, in which case add the second "id column"
|
203
|
+
def self.sort_key(table)
|
204
|
+
first_column, second_column = table_column_names(table)
|
199
205
|
|
206
|
+
if [first_column, second_column].all? { |name| name =~ /_id$/ }
|
207
|
+
[Utils.quote_column(first_column), Utils.quote_column(second_column)]
|
208
|
+
else
|
209
|
+
Utils.quote_column(first_column)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
200
213
|
end
|
201
214
|
end
|
data/lib/yaml_db/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaml_db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Wiggins
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-03-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
125
|
version: '0'
|
126
126
|
requirements: []
|
127
127
|
rubyforge_project:
|
128
|
-
rubygems_version: 2.
|
128
|
+
rubygems_version: 2.6.8
|
129
129
|
signing_key:
|
130
130
|
specification_version: 4
|
131
131
|
summary: yaml_db allows export/import of database into/from yaml files
|