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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3166fff22e51aca6cd07d0994d1bf6170438e0bc9aed41e90370a83920a0d9ff
4
- data.tar.gz: 73e64013ec42740653058f0d9ff6c37ee45de41be0312f2296e4926fb7bff5b4
3
+ metadata.gz: d9da5c8d1c2a7912585a7b1f43e9f3ded9dc859e362ce071c692659e4f98b4ba
4
+ data.tar.gz: fa12eafca7db2b3b540871e8701218d3bb176a7cbd3b1c36d57b8fef4884064f
5
5
  SHA512:
6
- metadata.gz: 55c6fc7f5b3ef1d904f252e6d54c595b5d4cb72f1fbdf67f3e577c9cc095bd838f0963f34f611f6b7069971f7ead1d96d7dd20864dbcfea8ed542c5a3008dfdc
7
- data.tar.gz: 3b6c0136ba9823832cf329b3efe78406e69ea92d6d90f89950652628de740ea675a8b7d7152e530838f269b9b32140fa7f80750bcc2b41af70c9efc2b275cd78
6
+ metadata.gz: cd5dbacac1bf5afe377e2c3078691e8b77afed7c1fe0fa55a25e1c446f698c91630bb07045791d1aacaad45fef2967c27b2a316368083a4e27d0fd45f36c6955
7
+ data.tar.gz: 83a7a7048def925647078c13cfe241ca3f082cb0ab41a377d9d58fef69de1ffc06fcd781f62e51b7677bf3ffb1d60889a8d88941bc3e44c3127f656e1af720d9
@@ -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 append_computed_attribute(name)
61
- computed_attribute = collection_class.computed_attributes[name]
62
- ds = computed_attribute.apply_join(dataset).select_append(computed_attribute.identifier.as(name))
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
- each_model_in_batches(size: batch_size, &block)
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
- dataset.each_page(size) do |page|
83
- query = build_query dataset: page
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
@@ -1,5 +1,5 @@
1
1
  module Rasti
2
2
  module DB
3
- VERSION = '2.1.0'
3
+ VERSION = '2.2.0'
4
4
  end
5
5
  end
@@ -132,8 +132,6 @@ class Minitest::Spec
132
132
  let :db do
133
133
  Sequel.connect(driver).tap do |db|
134
134
 
135
- db.extension :pagination
136
-
137
135
  db.create_table :users do
138
136
  primary_key :id
139
137
  String :name, null: false, unique: true
@@ -142,13 +142,13 @@ describe 'Query' do
142
142
  .must_equal [post]
143
143
  end
144
144
 
145
- describe 'Append computed attribute' do
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.append_computed_attribute(:comments_count)
149
- .where(id: 5)
150
- .all
151
- .must_equal [User.new(id: 5, name: 'User 5', comments_count: 2)]
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.append_computed_attribute(:full_name)
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.1.0
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-14 00:00:00.000000000 Z
11
+ date: 2020-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel