vorpal 0.0.6.rc3 → 0.0.6.rc4
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 +8 -8
- data/lib/vorpal/aggregate_repository.rb +6 -6
- data/lib/vorpal/db_driver.rb +24 -16
- data/lib/vorpal/db_loader.rb +10 -13
- data/lib/vorpal/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OGZhMWQ2MGM3ZWZlZTJhZjkxOGVlMmZiYTkzODk4NTljNzk5NjU0MA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZDMxYTEyMzI5OTQ0YmJkNDJmNjg3OGZjNzc5NDE2ZGUyNjc0M2Y4ZA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
M2QxM2JlYWQ0NGE5Njg3YWZhYmI4MjdmNmVlZjVhZGIzOTA1YTZjMDYzYzVj
|
10
|
+
ZGViNjM3ZDI2YTY5MGNkZGRhZmNkMmI2YjUxZDYwYTVjYmI1ZjA5ZmVmNTgx
|
11
|
+
ZGIxZTZjZTQzYTQ2NzQ4ZWMxNWM2OThmYzIzNjAzMjYxNTVkMTE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZmExNTU3NGNiYmM1YjIxZjg3M2VlNjU0ODJmY2NjNmZlYTRkMDcyZTYzZTNm
|
14
|
+
YTkyZDUxMTI2NGI4MzhjYzg5NjBiMWNmNGUwOTI1ZWIzZDc5MDRiM2RmMmQx
|
15
|
+
MzEzYmI0ZWRmYzYyZjgyYjFmOTI5NDA3YTYzMzJlYmZkMzc1YzU=
|
@@ -102,7 +102,7 @@ class AggregateRepository
|
|
102
102
|
return roots if roots.empty?
|
103
103
|
loaded_db_objects = load_owned_from_db(roots.map(&:id), roots.first.class)
|
104
104
|
loaded_db_objects.each do |config, db_objects|
|
105
|
-
@db_driver.destroy(config
|
105
|
+
@db_driver.destroy(config, db_objects)
|
106
106
|
end
|
107
107
|
roots
|
108
108
|
end
|
@@ -114,7 +114,7 @@ class AggregateRepository
|
|
114
114
|
end
|
115
115
|
|
116
116
|
def load_from_db(ids, domain_class, only_owned=false)
|
117
|
-
DbLoader.new(
|
117
|
+
DbLoader.new(only_owned, @db_driver).load_from_db(ids, @configs.config_for(domain_class))
|
118
118
|
end
|
119
119
|
|
120
120
|
def load_owned_from_db(ids, domain_class)
|
@@ -171,7 +171,7 @@ class AggregateRepository
|
|
171
171
|
def set_primary_keys(owned_objects, mapping)
|
172
172
|
owned_objects.each do |config, objects|
|
173
173
|
in_need_of_primary_keys = objects.find_all { |obj| obj.id.nil? }
|
174
|
-
primary_keys = @db_driver.get_primary_keys(config
|
174
|
+
primary_keys = @db_driver.get_primary_keys(config, in_need_of_primary_keys.length)
|
175
175
|
in_need_of_primary_keys.zip(primary_keys).each do |object, primary_key|
|
176
176
|
mapping[object].id = primary_key
|
177
177
|
object.id = primary_key
|
@@ -212,11 +212,11 @@ class AggregateRepository
|
|
212
212
|
owned_objects.each do |config, objects|
|
213
213
|
objects_to_insert = grouped_new_objects[config] || []
|
214
214
|
db_objects_to_insert = objects_to_insert.map { |obj| mapping[obj] }
|
215
|
-
@db_driver.insert(config
|
215
|
+
@db_driver.insert(config, db_objects_to_insert)
|
216
216
|
|
217
217
|
objects_to_update = objects - objects_to_insert
|
218
218
|
db_objects_to_update = objects_to_update.map { |obj| mapping[obj] }
|
219
|
-
@db_driver.update(config
|
219
|
+
@db_driver.update(config, db_objects_to_update)
|
220
220
|
end
|
221
221
|
end
|
222
222
|
|
@@ -226,7 +226,7 @@ class AggregateRepository
|
|
226
226
|
all_orphans = db_objects_in_db - db_objects_in_aggregate
|
227
227
|
grouped_orphans = all_orphans.group_by { |o| @configs.config_for_db_object(o) }
|
228
228
|
grouped_orphans.each do |config, orphans|
|
229
|
-
@db_driver.destroy(config
|
229
|
+
@db_driver.destroy(config, orphans)
|
230
230
|
end
|
231
231
|
end
|
232
232
|
|
data/lib/vorpal/db_driver.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
module Vorpal
|
2
2
|
class DbDriver
|
3
|
-
def
|
3
|
+
def initialize
|
4
|
+
@sequence_names = {}
|
5
|
+
end
|
6
|
+
|
7
|
+
def insert(class_config, db_objects)
|
4
8
|
if defined? ActiveRecord::Import
|
5
|
-
db_class.import(db_objects, validate: false)
|
9
|
+
class_config.db_class.import(db_objects, validate: false)
|
6
10
|
else
|
7
11
|
db_objects.each do |db_object|
|
8
12
|
db_object.save!(validate: false)
|
@@ -10,39 +14,43 @@ module Vorpal
|
|
10
14
|
end
|
11
15
|
end
|
12
16
|
|
13
|
-
def update(
|
17
|
+
def update(class_config, db_objects)
|
14
18
|
db_objects.each do |db_object|
|
15
19
|
db_object.save!(validate: false)
|
16
20
|
end
|
17
21
|
end
|
18
22
|
|
19
|
-
def destroy(
|
20
|
-
db_class.delete_all(id: db_objects.map(&:id))
|
23
|
+
def destroy(class_config, db_objects)
|
24
|
+
class_config.db_class.delete_all(id: db_objects.map(&:id))
|
21
25
|
end
|
22
26
|
|
23
|
-
def load_by_id(
|
24
|
-
db_class.where(id: ids)
|
27
|
+
def load_by_id(class_config, ids)
|
28
|
+
class_config.db_class.where(id: ids)
|
25
29
|
end
|
26
30
|
|
27
|
-
def load_by_foreign_key(
|
28
|
-
arel = db_class.where(foreign_key_info.fk_column => id)
|
31
|
+
def load_by_foreign_key(class_config, id, foreign_key_info)
|
32
|
+
arel = class_config.db_class.where(foreign_key_info.fk_column => id)
|
29
33
|
arel = arel.where(foreign_key_info.fk_type_column => foreign_key_info.fk_type) if foreign_key_info.polymorphic?
|
30
34
|
arel.order(:id).all
|
31
35
|
end
|
32
36
|
|
33
|
-
def get_primary_keys(
|
34
|
-
result = execute("select nextval(
|
35
|
-
result.
|
37
|
+
def get_primary_keys(class_config, count)
|
38
|
+
result = execute("select nextval($1) from generate_series(1,$2);", [sequence_name(class_config), count])
|
39
|
+
result.rows.map(&:first).map(&:to_i)
|
36
40
|
end
|
37
41
|
|
38
42
|
private
|
39
43
|
|
40
|
-
def
|
41
|
-
|
44
|
+
def sequence_name(class_config)
|
45
|
+
@sequence_names[class_config] ||= execute(
|
46
|
+
"SELECT substring(column_default from '''(.*)''') FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = $1 AND column_name = 'id' LIMIT 1",
|
47
|
+
[class_config.db_class.table_name]
|
48
|
+
).rows.first.first
|
42
49
|
end
|
43
50
|
|
44
|
-
def
|
45
|
-
|
51
|
+
def execute(sql, binds)
|
52
|
+
binds = binds.map { |row| [nil, row] }
|
53
|
+
ActiveRecord::Base.connection.exec_query(sql, 'SQL', binds)
|
46
54
|
end
|
47
55
|
end
|
48
56
|
end
|
data/lib/vorpal/db_loader.rb
CHANGED
@@ -8,23 +8,21 @@ module Vorpal
|
|
8
8
|
#
|
9
9
|
# @private
|
10
10
|
class DbLoader
|
11
|
-
def initialize(
|
12
|
-
@configs = configs
|
11
|
+
def initialize(only_owned, db_driver)
|
13
12
|
@only_owned = only_owned
|
14
|
-
@
|
13
|
+
@db_driver = db_driver
|
15
14
|
end
|
16
15
|
|
17
|
-
def load_from_db(ids,
|
18
|
-
config = @configs.config_for(domain_class)
|
16
|
+
def load_from_db(ids, config)
|
19
17
|
@loaded_objects = LoadedObjects.new
|
20
18
|
@lookup_instructions = LookupInstructions.new
|
21
19
|
@lookup_instructions.lookup_by_id(config, ids)
|
22
20
|
|
23
21
|
until @lookup_instructions.empty?
|
24
22
|
lookup = @lookup_instructions.next_lookup
|
25
|
-
new_objects = lookup.load_all(@
|
23
|
+
new_objects = lookup.load_all(@db_driver)
|
26
24
|
@loaded_objects.add(lookup.config, new_objects)
|
27
|
-
explore_objects(new_objects)
|
25
|
+
explore_objects(lookup.config, new_objects)
|
28
26
|
end
|
29
27
|
|
30
28
|
@loaded_objects
|
@@ -32,9 +30,8 @@ class DbLoader
|
|
32
30
|
|
33
31
|
private
|
34
32
|
|
35
|
-
def explore_objects(objects_to_explore)
|
33
|
+
def explore_objects(config, objects_to_explore)
|
36
34
|
objects_to_explore.each do |db_object|
|
37
|
-
config = @configs.config_for_db_object(db_object)
|
38
35
|
config.has_manys.each do |has_many_config|
|
39
36
|
lookup_by_fk(db_object, has_many_config) if explore_association?(has_many_config)
|
40
37
|
end
|
@@ -119,9 +116,9 @@ class LookupById
|
|
119
116
|
@ids = ids
|
120
117
|
end
|
121
118
|
|
122
|
-
def load_all(
|
119
|
+
def load_all(db_driver)
|
123
120
|
return [] if @ids.empty?
|
124
|
-
|
121
|
+
db_driver.load_by_id(@config, @ids)
|
125
122
|
end
|
126
123
|
end
|
127
124
|
|
@@ -134,9 +131,9 @@ class LookupByFk
|
|
134
131
|
@fk_values = fk_values
|
135
132
|
end
|
136
133
|
|
137
|
-
def load_all(
|
134
|
+
def load_all(db_driver)
|
138
135
|
return [] if @fk_values.empty?
|
139
|
-
|
136
|
+
db_driver.load_by_foreign_key(@config, @fk_values, @fk_info)
|
140
137
|
end
|
141
138
|
end
|
142
139
|
|
data/lib/vorpal/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vorpal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.6.
|
4
|
+
version: 0.0.6.rc4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Kirby
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simple_serializer
|