rasti-db 2.0.0 → 2.0.1

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: 210581882359ef05a1b09c69b172f259b0b5010b61a254442e9844158a4f9456
4
- data.tar.gz: 1dd3f0fcc8399e0145abc50166495a87826bb1b32e52de4acb45ea114f7650d5
3
+ metadata.gz: 8b41f6198798c9bee6da1f94742378639bb3b900f3bda6471f791b42a71a24c7
4
+ data.tar.gz: f470e1f1ef5673546e54e6c144e16ebba577b0f848b8fd59c8822489808a7cbf
5
5
  SHA512:
6
- metadata.gz: 2c209c735eb50327d4bb7b54754530cd155dec884e32661f046de73dfb53fb036877e1e25f1ade565ef51a0517254096d24934f3d6e47393febc99318ea71118
7
- data.tar.gz: a5a8326418216e1558ffea4b93e52a2369420fed2c8d9633dda5ffd8ee34b457e06aaaea2018001ba8725e51c1ef44386a78e2abaa51819628eba93cec38da99
6
+ metadata.gz: f5e836d580a42656efe1d78ee2e193449edd1adf45dbccd0a4b4c9c4d6f263a0d92e844a142abb908a683a8dcad4865d5926aec10b5a0260c0240425dcd063dd
7
+ data.tar.gz: 71148abafe56a6fe60613f2ebfa38138df2aaa656bdbe7116a834d41f3920fb49b97bfffac3235a520a6ffbb293184310d2d7fcefa552178d1cb767b94ce8e4d
@@ -9,7 +9,7 @@ module Rasti
9
9
  def initialize(environment:, collection_class:, dataset:, relations_graph:nil)
10
10
  @environment = environment
11
11
  @collection_class = collection_class
12
- @dataset = dataset
12
+ @dataset = dataset.qualify collection_class.collection_name
13
13
  @relations_graph = relations_graph || Relations::Graph.new(environment, collection_class)
14
14
  end
15
15
 
@@ -74,11 +74,9 @@ module Rasti
74
74
 
75
75
  def join(*relations)
76
76
  graph = Relations::Graph.new environment, collection_class, relations
77
-
78
- ds = graph.add_joins(dataset)
79
- .distinct
80
- .select_all(collection_class.collection_name)
81
-
77
+
78
+ ds = graph.add_joins(dataset).distinct
79
+
82
80
  build_query dataset: ds
83
81
  end
84
82
 
@@ -1,5 +1,5 @@
1
1
  module Rasti
2
2
  module DB
3
- VERSION = '2.0.0'
3
+ VERSION = '2.0.1'
4
4
  end
5
5
  end
@@ -537,20 +537,20 @@ describe 'Collection' do
537
537
  case sql
538
538
 
539
539
  when 'SELECT users.* FROM schema_1.users',
540
- 'SELECT users.* FROM schema_1.users WHERE (id IN (2, 1))'
540
+ 'SELECT users.* FROM schema_1.users WHERE (users.id IN (2, 1))'
541
541
  [
542
542
  {id: 1},
543
543
  {id: 2}
544
544
  ]
545
545
 
546
546
  when 'SELECT posts.* FROM schema_1.posts',
547
- 'SELECT posts.* FROM schema_1.posts WHERE (user_id IN (1, 2))'
547
+ 'SELECT posts.* FROM schema_1.posts WHERE (posts.user_id IN (1, 2))'
548
548
  [
549
549
  {id: 3, user_id: 1, language_id: 1},
550
550
  {id: 4, user_id: 2, language_id: 2}
551
551
  ]
552
552
 
553
- when 'SELECT comments.* FROM schema_1.comments WHERE (post_id IN (3, 4))'
553
+ when 'SELECT comments.* FROM schema_1.comments WHERE (comments.post_id IN (3, 4))'
554
554
  [
555
555
  {id: 5, user_id: 2, post_id: 3},
556
556
  {id: 6, user_id: 1, post_id: 3},
@@ -558,7 +558,7 @@ describe 'Collection' do
558
558
  {id: 8, user_id: 2, post_id: 4}
559
559
  ]
560
560
 
561
- when 'SELECT languages.* FROM schema_2.languages WHERE (id IN (1, 2))'
561
+ when 'SELECT languages.* FROM schema_2.languages WHERE (languages.id IN (1, 2))'
562
562
  [
563
563
  {id: 1},
564
564
  {id: 2}
@@ -663,7 +663,7 @@ describe 'Collection' do
663
663
  stub_users.where(id: [1,2]).limit(1).order(:name).all
664
664
 
665
665
  stub_db.sqls.must_equal [
666
- 'SELECT users.* FROM schema_1.users WHERE (id IN (1, 2)) ORDER BY name LIMIT 1'
666
+ 'SELECT users.* FROM schema_1.users WHERE (users.id IN (1, 2)) ORDER BY users.name LIMIT 1'
667
667
  ]
668
668
  end
669
669
 
@@ -673,13 +673,13 @@ describe 'Collection' do
673
673
  stub_db.sqls.must_equal [
674
674
  'SELECT posts.* FROM schema_1.posts',
675
675
  'SELECT categories.*, categories_posts.post_id AS source_foreign_key FROM schema_1.categories INNER JOIN schema_1.categories_posts ON (schema_1.categories_posts.category_id = schema_1.categories.id) WHERE (categories_posts.post_id IN (3, 4))',
676
- 'SELECT comments.* FROM schema_1.comments WHERE (post_id IN (3, 4))',
677
- 'SELECT users.* FROM schema_1.users WHERE (id IN (2, 1))',
678
- 'SELECT posts.* FROM schema_1.posts WHERE (user_id IN (1, 2))',
676
+ 'SELECT comments.* FROM schema_1.comments WHERE (comments.post_id IN (3, 4))',
677
+ 'SELECT users.* FROM schema_1.users WHERE (users.id IN (2, 1))',
678
+ 'SELECT posts.* FROM schema_1.posts WHERE (posts.user_id IN (1, 2))',
679
679
  'SELECT categories.*, categories_posts.post_id AS source_foreign_key FROM schema_1.categories INNER JOIN schema_1.categories_posts ON (schema_1.categories_posts.category_id = schema_1.categories.id) WHERE (categories_posts.post_id IN (3, 4))',
680
- 'SELECT languages.* FROM schema_2.languages WHERE (id IN (1, 2))',
680
+ 'SELECT languages.* FROM schema_2.languages WHERE (languages.id IN (1, 2))',
681
681
  'SELECT people.*, languages_people.language_id AS source_foreign_key FROM schema_1.people INNER JOIN schema_1.languages_people ON (schema_1.languages_people.document_number = schema_1.people.document_number) WHERE (languages_people.language_id IN (1, 2))',
682
- 'SELECT users.* FROM schema_1.users WHERE (id IN (1, 2))'
682
+ 'SELECT users.* FROM schema_1.users WHERE (users.id IN (1, 2))'
683
683
  ]
684
684
  end
685
685
 
@@ -687,7 +687,7 @@ describe 'Collection' do
687
687
  stub_posts.join('user.person').where(document_number: 'document_1').all
688
688
 
689
689
  stub_db.sqls.must_equal [
690
- "SELECT DISTINCT posts.* FROM schema_1.posts INNER JOIN schema_1.users AS user ON (user.id = posts.user_id) INNER JOIN schema_1.people AS user__person ON (user__person.user_id = user.id) WHERE (document_number = 'document_1')"
690
+ "SELECT DISTINCT posts.* FROM schema_1.posts INNER JOIN schema_1.users AS user ON (user.id = posts.user_id) INNER JOIN schema_1.people AS user__person ON (user__person.user_id = user.id) WHERE (posts.document_number = 'document_1')"
691
691
  ]
692
692
  end
693
693
 
@@ -237,7 +237,7 @@ describe 'Query' do
237
237
  end
238
238
 
239
239
  it 'To String' do
240
- users_query.where(id: [1,2,3]).order(:name).to_s.must_equal '#<Rasti::DB::Query: "SELECT * FROM `users` WHERE (`id` IN (1, 2, 3)) ORDER BY `name`">'
240
+ users_query.where(id: [1,2,3]).order(:name).to_s.must_equal '#<Rasti::DB::Query: "SELECT `users`.* FROM `users` WHERE (`users`.`id` IN (1, 2, 3)) ORDER BY `users`.`name`">'
241
241
  end
242
242
 
243
243
  describe 'Named queries' do
@@ -257,19 +257,19 @@ describe 'Query' do
257
257
  describe 'Join' do
258
258
 
259
259
  it 'One to Many' do
260
- users_query.join(:posts).where(title: 'Sample post').all.must_equal [User.new(id: 2, name: 'User 2')]
260
+ users_query.join(:posts).where(Sequel[:posts][:title] => 'Sample post').all.must_equal [User.new(id: 2, name: 'User 2')]
261
261
  end
262
262
 
263
263
  it 'Many to One' do
264
- posts_query.join(:user).where(name: 'User 4').all.must_equal [Post.new(id: 3, user_id: 4, title: 'Best post', body: '...', language_id: 1)]
264
+ posts_query.join(:user).where(Sequel[:user][:name] => 'User 4').all.must_equal [Post.new(id: 3, user_id: 4, title: 'Best post', body: '...', language_id: 1)]
265
265
  end
266
266
 
267
267
  it 'One to One' do
268
- users_query.join(:person).where(document_number: 'document_1').all.must_equal [User.new(id: 1, name: 'User 1')]
268
+ users_query.join(:person).where(Sequel[:person][:document_number] => 'document_1').all.must_equal [User.new(id: 1, name: 'User 1')]
269
269
  end
270
270
 
271
271
  it 'Many to Many' do
272
- posts_query.join(:categories).where(name: 'Category 3').order(:id).all.must_equal [
272
+ posts_query.join(:categories).where(Sequel[:categories][:name] => 'Category 3').order(:id).all.must_equal [
273
273
  Post.new(id: 2, user_id: 1, title: 'Another post', body: '...', language_id: 1),
274
274
  Post.new(id: 3, user_id: 4, title: 'Best post', body: '...', language_id: 1),
275
275
  ]
@@ -283,6 +283,20 @@ describe 'Query' do
283
283
  .must_equal [Post.new(id: 1, user_id: 2, title: 'Sample post', body: '...', language_id: 1)]
284
284
  end
285
285
 
286
+ it 'Excluded attributes permanents excluded when join' do
287
+ posts_query.join(:user)
288
+ .exclude_attributes(:body)
289
+ .where(Sequel[:user][:name] => 'User 4')
290
+ .all
291
+ .must_equal [Post.new(id: 3, title: 'Best post', user_id: 4, language_id: 1)]
292
+
293
+ posts_query.exclude_attributes(:body)
294
+ .join(:user)
295
+ .where(Sequel[:user][:name] => 'User 4')
296
+ .all
297
+ .must_equal [Post.new(id: 3, title: 'Best post', user_id: 4, language_id: 1)]
298
+ end
299
+
286
300
  describe 'Multiple data sources' do
287
301
 
288
302
  it 'One to Many' do
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.0.0
4
+ version: 2.0.1
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-04-30 00:00:00.000000000 Z
11
+ date: 2020-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel