rasti-db 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rasti/db/query.rb +11 -15
- data/lib/rasti/db/version.rb +1 -1
- data/spec/minitest_helper.rb +0 -2
- data/spec/query_spec.rb +6 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9da5c8d1c2a7912585a7b1f43e9f3ded9dc859e362ce071c692659e4f98b4ba
|
4
|
+
data.tar.gz: fa12eafca7db2b3b540871e8701218d3bb176a7cbd3b1c36d57b8fef4884064f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd5dbacac1bf5afe377e2c3078691e8b77afed7c1fe0fa55a25e1c446f698c91630bb07045791d1aacaad45fef2967c27b2a316368083a4e27d0fd45f36c6955
|
7
|
+
data.tar.gz: 83a7a7048def925647078c13cfe241ca3f082cb0ab41a377d9d58fef69de1ffc06fcd781f62e51b7677bf3ffb1d60889a8d88941bc3e44c3127f656e1af720d9
|
data/lib/rasti/db/query.rb
CHANGED
@@ -57,14 +57,16 @@ module Rasti
|
|
57
57
|
build_query relations_graph: relations_graph.with_all_attributes_for(relations)
|
58
58
|
end
|
59
59
|
|
60
|
-
def
|
61
|
-
|
62
|
-
|
60
|
+
def select_computed_attributes(*computed_attributes)
|
61
|
+
ds = computed_attributes.inject(dataset) do |ds, name|
|
62
|
+
computed_attribute = collection_class.computed_attributes[name]
|
63
|
+
computed_attribute.apply_join(ds).select_append(computed_attribute.identifier.as(name))
|
64
|
+
end
|
63
65
|
build_query dataset: ds
|
64
66
|
end
|
65
67
|
|
66
68
|
def all
|
67
|
-
with_graph(dataset.all).map do |row|
|
69
|
+
with_graph(dataset.all).map do |row|
|
68
70
|
collection_class.model.new row
|
69
71
|
end
|
70
72
|
end
|
@@ -74,13 +76,15 @@ module Rasti
|
|
74
76
|
if batch_size.nil?
|
75
77
|
all.each(&block)
|
76
78
|
else
|
77
|
-
|
79
|
+
each_batch(size: batch_size) do |models|
|
80
|
+
models.each { |model| block.call model }
|
81
|
+
end
|
78
82
|
end
|
79
83
|
end
|
80
84
|
|
81
85
|
def each_batch(size:, &block)
|
82
|
-
|
83
|
-
query =
|
86
|
+
primary_keys.each_slice(size) do |pks|
|
87
|
+
query = where(collection_class.primary_key => pks)
|
84
88
|
block.call query.all
|
85
89
|
end
|
86
90
|
end
|
@@ -167,14 +171,6 @@ module Rasti
|
|
167
171
|
build_query dataset: instance_eval(&block)
|
168
172
|
end
|
169
173
|
|
170
|
-
def each_model_in_batches(size:, &block)
|
171
|
-
dataset.each_page(size) do |page|
|
172
|
-
page.each do |row|
|
173
|
-
block.call build_model(row)
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
174
|
def with_related(relation_name, primary_keys)
|
179
175
|
ds = collection_class.relations[relation_name].apply_filter environment, dataset, primary_keys
|
180
176
|
build_query dataset: ds
|
data/lib/rasti/db/version.rb
CHANGED
data/spec/minitest_helper.rb
CHANGED
data/spec/query_spec.rb
CHANGED
@@ -142,13 +142,13 @@ describe 'Query' do
|
|
142
142
|
.must_equal [post]
|
143
143
|
end
|
144
144
|
|
145
|
-
describe '
|
145
|
+
describe 'Select computed attributes' do
|
146
146
|
it 'With join' do
|
147
147
|
db[:comments].insert post_id: 1, user_id: 5, text: 'Comment 4'
|
148
|
-
users_query.
|
149
|
-
|
150
|
-
|
151
|
-
|
148
|
+
users_query.select_computed_attributes(:comments_count)
|
149
|
+
.where(id: 5)
|
150
|
+
.all
|
151
|
+
.must_equal [User.new(id: 5, name: 'User 5', comments_count: 2)]
|
152
152
|
end
|
153
153
|
|
154
154
|
it 'Without join' do
|
@@ -159,7 +159,7 @@ describe 'Query' do
|
|
159
159
|
birth_date: Date.parse('2020-04-24'),
|
160
160
|
full_name: 'Name 1 Last Name 1'
|
161
161
|
|
162
|
-
people_query.
|
162
|
+
people_query.select_computed_attributes(:full_name)
|
163
163
|
.where(document_number: 'document_1')
|
164
164
|
.all
|
165
165
|
.must_equal [person_expected]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rasti-db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Naiman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-12-
|
11
|
+
date: 2020-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|