rasti-db 4.0.0 → 4.1.0
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 +4 -4
 - data/lib/rasti/db/computed_attribute.rb +2 -2
 - data/lib/rasti/db/query.rb +2 -2
 - data/lib/rasti/db/version.rb +1 -1
 - data/spec/computed_attribute_spec.rb +23 -3
 - 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: c26c0f818529ec0d1a752cf310c1d23cf235d2c8c83e13a62d8d61bc90b3b400
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 57022ffbb145a76ad9532d16a1ed890f31862f7fc6ad4cea6d40aae0490908ca
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 94746821604273fdf6483d5410f8c73f4793901116478a17d3ecba6e7039705ecf8cf5b8ad0ccb30adb294d052ff144c6d0fe5ca042ca1fd558e3caf5c45de62
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: '0684ae374582f8cd633d44aacd720e80b3575e3ef8186de2252d9f73e17f03fe438a54a407127bb320f9ec8996f3f5dc71c99294b503c28797e34faf4c886f22'
         
     | 
    
        data/lib/rasti/db/query.rb
    CHANGED
    
    | 
         @@ -60,7 +60,7 @@ module Rasti 
     | 
|
| 
       60 
60 
     | 
    
         
             
                  def select_computed_attributes(*computed_attributes)
         
     | 
| 
       61 
61 
     | 
    
         
             
                    ds = computed_attributes.inject(dataset) do |ds, name|
         
     | 
| 
       62 
62 
     | 
    
         
             
                      computed_attribute = collection_class.computed_attributes[name]
         
     | 
| 
       63 
     | 
    
         
            -
                      computed_attribute.apply_join(ds).select_append(computed_attribute.identifier.as(name))
         
     | 
| 
      
 63 
     | 
    
         
            +
                      computed_attribute.apply_join(ds, environment).select_append(computed_attribute.identifier.as(name))
         
     | 
| 
       64 
64 
     | 
    
         
             
                    end
         
     | 
| 
       65 
65 
     | 
    
         
             
                    build_query dataset: ds
         
     | 
| 
       66 
66 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -138,7 +138,7 @@ module Rasti 
     | 
|
| 
       138 
138 
     | 
    
         
             
                    raise NQL::InvalidExpressionError.new(filter_expression) if sentence.nil?
         
     | 
| 
       139 
139 
     | 
    
         | 
| 
       140 
140 
     | 
    
         
             
                    ds = sentence.computed_attributes(collection_class).inject(dataset) do |ds, name|
         
     | 
| 
       141 
     | 
    
         
            -
                      collection_class.computed_attributes[name].apply_join ds
         
     | 
| 
      
 141 
     | 
    
         
            +
                      collection_class.computed_attributes[name].apply_join ds, environment
         
     | 
| 
       142 
142 
     | 
    
         
             
                    end
         
     | 
| 
       143 
143 
     | 
    
         
             
                    query = build_query dataset: ds
         
     | 
| 
       144 
144 
     | 
    
         | 
    
        data/lib/rasti/db/version.rb
    CHANGED
    
    
| 
         @@ -2,7 +2,7 @@ require 'minitest_helper' 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            describe 'ComputedAttribute' do
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
              it 'Apply Join  
     | 
| 
      
 5 
     | 
    
         
            +
              it 'Apply Join with join attribute must generate correct query' do
         
     | 
| 
       6 
6 
     | 
    
         
             
                dataset = db[:users]
         
     | 
| 
       7 
7 
     | 
    
         
             
                computed_attribute = Rasti::DB::ComputedAttribute.new(Sequel[:comments_count][:value]) do |dataset|
         
     | 
| 
       8 
8 
     | 
    
         
             
                  subquery = dataset.db.from(:comments)
         
     | 
| 
         @@ -13,7 +13,7 @@ describe 'ComputedAttribute' do 
     | 
|
| 
       13 
13 
     | 
    
         
             
                  dataset.join_table(:inner, subquery, :user_id => :id)
         
     | 
| 
       14 
14 
     | 
    
         
             
                end
         
     | 
| 
       15 
15 
     | 
    
         
             
                expected_query = "SELECT *, `comments_count`.`value` AS 'value' FROM `users` INNER JOIN (SELECT `user_id`, count(`id`) AS 'value' FROM `comments` GROUP BY `user_id`) AS 'comments_count' ON (`comments_count`.`user_id` = `users`.`id`)"
         
     | 
| 
       16 
     | 
    
         
            -
                computed_attribute.apply_join(dataset)
         
     | 
| 
      
 16 
     | 
    
         
            +
                computed_attribute.apply_join(dataset, environment)
         
     | 
| 
       17 
17 
     | 
    
         
             
                                  .select_append(computed_attribute.identifier)
         
     | 
| 
       18 
18 
     | 
    
         
             
                                  .sql
         
     | 
| 
       19 
19 
     | 
    
         
             
                                  .must_equal expected_query
         
     | 
| 
         @@ -23,10 +23,30 @@ describe 'ComputedAttribute' do 
     | 
|
| 
       23 
23 
     | 
    
         
             
                dataset = db[:people]
         
     | 
| 
       24 
24 
     | 
    
         
             
                computed_attribute = Rasti::DB::ComputedAttribute.new Sequel.join([:first_name, ' ', :last_name])
         
     | 
| 
       25 
25 
     | 
    
         
             
                expected_query = "SELECT * FROM `people` WHERE ((`first_name` || ' ' || `last_name`) = 'FULL NAME')"
         
     | 
| 
       26 
     | 
    
         
            -
                computed_attribute.apply_join(dataset)
         
     | 
| 
      
 26 
     | 
    
         
            +
                computed_attribute.apply_join(dataset, environment)
         
     | 
| 
       27 
27 
     | 
    
         
             
                                  .where(computed_attribute.identifier => 'FULL NAME')
         
     | 
| 
       28 
28 
     | 
    
         
             
                                  .sql
         
     | 
| 
       29 
29 
     | 
    
         
             
                                  .must_equal expected_query
         
     | 
| 
       30 
30 
     | 
    
         
             
              end
         
     | 
| 
       31 
31 
     | 
    
         | 
| 
      
 32 
     | 
    
         
            +
              it 'Apply join with join and environment attributes must generate correct query' do
         
     | 
| 
      
 33 
     | 
    
         
            +
                dataset = db[:users]
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                expected_query = "SELECT *, `comments_count`.`value` AS 'value' FROM `users` INNER JOIN (SELECT `user_id`, count(`id`) AS 'value' FROM `comments` GROUP BY `user_id`) AS 'comments_count' ON (`comments_count`.`user_id` = `users`.`id`)"
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                computed_attribute = Rasti::DB::ComputedAttribute.new(Sequel[:comments_count][:value]) do |dataset, environment|
         
     | 
| 
      
 38 
     | 
    
         
            +
                  subquery = dataset.db.from(environment.data_source(:custom).qualify(:comments))
         
     | 
| 
      
 39 
     | 
    
         
            +
                                       .select(Sequel[:user_id], Sequel.function('count', :id).as(:value))
         
     | 
| 
      
 40 
     | 
    
         
            +
                                       .group(:user_id)
         
     | 
| 
      
 41 
     | 
    
         
            +
                                       .as(:comments_count)
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                  dataset.join_table(:inner, subquery, :user_id => :id)
         
     | 
| 
      
 44 
     | 
    
         
            +
                end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                computed_attribute.apply_join(dataset, environment)
         
     | 
| 
      
 47 
     | 
    
         
            +
                                  .select_append(computed_attribute.identifier)
         
     | 
| 
      
 48 
     | 
    
         
            +
                                  .sql
         
     | 
| 
      
 49 
     | 
    
         
            +
                                  .must_equal expected_query
         
     | 
| 
      
 50 
     | 
    
         
            +
              end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
       32 
52 
     | 
    
         
             
            end
         
     | 
    
        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: 4. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 4.1.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: 2021- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2021-08-17 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: sequel
         
     |