rasti-db 4.1.0 → 4.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c26c0f818529ec0d1a752cf310c1d23cf235d2c8c83e13a62d8d61bc90b3b400
4
- data.tar.gz: 57022ffbb145a76ad9532d16a1ed890f31862f7fc6ad4cea6d40aae0490908ca
3
+ metadata.gz: 331138443b43eefbd6f4e9008755646f790a7a12329d5fb342936b97de8d9bfe
4
+ data.tar.gz: 9723170bbbf65352a112312a6b72953a69055ceca9d115763705d6363b00e669
5
5
  SHA512:
6
- metadata.gz: 94746821604273fdf6483d5410f8c73f4793901116478a17d3ecba6e7039705ecf8cf5b8ad0ccb30adb294d052ff144c6d0fe5ca042ca1fd558e3caf5c45de62
7
- data.tar.gz: '0684ae374582f8cd633d44aacd720e80b3575e3ef8186de2252d9f73e17f03fe438a54a407127bb320f9ec8996f3f5dc71c99294b503c28797e34faf4c886f22'
6
+ metadata.gz: '00777167854dfaa0f0e133b157ac97e56a8a94c840b79a024a2f0af507a995a77f72372b263ee4a00770970d0f6646f0c034ee5cee733dae892bb85cae78f756'
7
+ data.tar.gz: 66f2f804441640d2cfe7ed3694000092e9d8f7541e6478c4be98b475b7e3d70de7d8a7c78c63b19a8542c89cf1ff7311291f6c09f8d339ba8a2d257a2a671efe
@@ -0,0 +1,26 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ '**' ]
6
+ pull_request:
7
+ branches: [ '**' ]
8
+
9
+ jobs:
10
+ test:
11
+
12
+ name: Tests
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ matrix:
16
+ ruby-version: ['2.1', '2.2', '2.3', '2.4', '2.5', '2.6', '2.7', '3.0', 'jruby-9.2.9.0']
17
+
18
+ steps:
19
+ - uses: actions/checkout@v3
20
+ - name: Set up Ruby
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby-version }}
24
+ bundler-cache: true
25
+ - name: Run tests
26
+ run: bundle exec rake
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Rasti::DB
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/rasti-db.svg)](https://rubygems.org/gems/rasti-db)
4
- [![Build Status](https://travis-ci.org/gabynaiman/rasti-db.svg?branch=master)](https://travis-ci.org/gabynaiman/rasti-db)
4
+ [![CI](https://github.com/gabynaiman/rasti-db/actions/workflows/ci.yml/badge.svg)](https://github.com/gabynaiman/rasti-db/actions/workflows/ci.yml)
5
5
  [![Coverage Status](https://coveralls.io/repos/github/gabynaiman/rasti-db/badge.svg?branch=master)](https://coveralls.io/github/gabynaiman/rasti-db?branch=master)
6
6
  [![Code Climate](https://codeclimate.com/github/gabynaiman/rasti-db.svg)](https://codeclimate.com/github/gabynaiman/rasti-db)
7
7
 
@@ -58,17 +58,15 @@ module Rasti
58
58
  end
59
59
 
60
60
  def select_computed_attributes(*computed_attributes)
61
- ds = computed_attributes.inject(dataset) do |ds, name|
61
+ ds = computed_attributes.inject(dataset) do |inner_ds, name|
62
62
  computed_attribute = collection_class.computed_attributes[name]
63
- computed_attribute.apply_join(ds, environment).select_append(computed_attribute.identifier.as(name))
63
+ computed_attribute.apply_join(inner_ds, environment).select_append(computed_attribute.identifier.as(name))
64
64
  end
65
65
  build_query dataset: ds
66
66
  end
67
67
 
68
68
  def all
69
- with_graph(dataset.all).map do |row|
70
- collection_class.model.new row
71
- end
69
+ build_models dataset.all
72
70
  end
73
71
  alias_method :to_a, :all
74
72
 
@@ -114,13 +112,11 @@ module Rasti
114
112
  end
115
113
 
116
114
  def first
117
- row = dataset.first
118
- row ? build_model(row) : nil
115
+ build_model dataset.first
119
116
  end
120
117
 
121
118
  def last
122
- row = dataset.last
123
- row ? build_model(row) : nil
119
+ build_model dataset.last
124
120
  end
125
121
 
126
122
  def detect(*args, &block)
@@ -137,8 +133,8 @@ module Rasti
137
133
 
138
134
  raise NQL::InvalidExpressionError.new(filter_expression) if sentence.nil?
139
135
 
140
- ds = sentence.computed_attributes(collection_class).inject(dataset) do |ds, name|
141
- collection_class.computed_attributes[name].apply_join ds, environment
136
+ ds = sentence.computed_attributes(collection_class).inject(dataset) do |inner_ds, name|
137
+ collection_class.computed_attributes[name].apply_join inner_ds, environment
142
138
  end
143
139
  query = build_query dataset: ds
144
140
 
@@ -164,7 +160,21 @@ module Rasti
164
160
  end
165
161
 
166
162
  def build_model(row)
167
- collection_class.model.new with_graph(row)
163
+ row ? build_models([row]).first : nil
164
+ end
165
+
166
+ def build_models(rows)
167
+ with_graph(rows).map do |row|
168
+ collection_class.model.new slice_defined_attributes(row)
169
+ end
170
+ end
171
+
172
+ def slice_defined_attributes(row)
173
+ row.select { |k,_| defined_attributes.include? k }
174
+ end
175
+
176
+ def defined_attributes
177
+ @defined_attributes ||= collection_class.model.attribute_names.to_set
168
178
  end
169
179
 
170
180
  def chainable(&block)
@@ -1,5 +1,5 @@
1
1
  module Rasti
2
2
  module DB
3
- VERSION = '4.1.0'
3
+ VERSION = '4.1.1'
4
4
  end
5
5
  end
@@ -19,7 +19,8 @@ Post = Rasti::DB::Model[:id, :title, :body, :user_id, :user, :comments, :cat
19
19
  Comment = Rasti::DB::Model[:id, :text, :user_id, :user, :post_id, :post, :tags]
20
20
  Category = Rasti::DB::Model[:id, :name, :posts]
21
21
  Person = Rasti::DB::Model[:document_number, :first_name, :last_name, :birth_date, :user_id, :user, :languages, :full_name]
22
- Language = Rasti::DB::Model[:id, :name, :people]
22
+ Language = Rasti::DB::Model[:id, :name, :people, :countries]
23
+ Country = Rasti::DB::Model[:id, :name, :language_id]
23
24
 
24
25
 
25
26
  class Users < Rasti::DB::Collection
@@ -47,8 +48,8 @@ class Posts < Rasti::DB::Collection
47
48
  one_to_many :comments
48
49
 
49
50
  query :created_by, ->(user_id) { where user_id: user_id }
50
-
51
- query :entitled do |title|
51
+
52
+ query :entitled do |title|
52
53
  where title: title
53
54
  end
54
55
 
@@ -106,6 +107,11 @@ class Languages < Rasti::DB::Collection
106
107
 
107
108
  many_to_many :people, collection: People, relation_data_source_name: :default
108
109
  one_to_many :posts
110
+ one_to_many :countries
111
+ end
112
+
113
+ class Countries < Rasti::DB::Collection
114
+ many_to_one :language
109
115
  end
110
116
 
111
117
 
@@ -114,7 +120,7 @@ class Minitest::Spec
114
120
  let(:users) { Users.new environment }
115
121
 
116
122
  let(:posts) { Posts.new environment }
117
-
123
+
118
124
  let(:comments) { Comments.new environment }
119
125
 
120
126
  let(:categories) { Categories.new environment }
@@ -123,9 +129,11 @@ class Minitest::Spec
123
129
 
124
130
  let(:languages) { Languages.new environment }
125
131
 
132
+ let(:countries) { Countries.new environment }
133
+
126
134
  let(:driver) { (RUBY_ENGINE == 'jruby') ? 'jdbc:sqlite::memory:' : {adapter: :sqlite} }
127
135
 
128
- let :environment do
136
+ let :environment do
129
137
  Rasti::DB::Environment.new default: Rasti::DB::DataSource.new(db),
130
138
  custom: Rasti::DB::DataSource.new(custom_db)
131
139
  end
@@ -179,6 +187,13 @@ class Minitest::Spec
179
187
  primary_key [:language_id, :document_number]
180
188
  end
181
189
 
190
+ db.create_table :countries do
191
+ primary_key :id
192
+ String :name, null: false, unique: true
193
+ Integer :population, null: false
194
+ Integer :language_id, null: false, index: true
195
+ end
196
+
182
197
  end
183
198
  end
184
199
 
data/spec/query_spec.rb CHANGED
@@ -32,6 +32,8 @@ describe 'Query' do
32
32
  db[:categories_posts].insert post_id: 2, category_id: 2
33
33
  db[:categories_posts].insert post_id: 2, category_id: 3
34
34
  db[:categories_posts].insert post_id: 3, category_id: 3
35
+
36
+ db[:countries].insert name: 'Argentina', population: 40000000, language_id: 1
35
37
  end
36
38
 
37
39
  let(:users_query) { Rasti::DB::Query.new collection_class: Users, dataset: db[:users], environment: environment }
@@ -44,6 +46,8 @@ describe 'Query' do
44
46
 
45
47
  let(:languages_query) { Rasti::DB::Query.new collection_class: Languages, dataset: custom_db[:languages], environment: environment }
46
48
 
49
+ let(:countries_query) { Rasti::DB::Query.new collection_class: Countries, dataset: db[:countries], environment: environment }
50
+
47
51
  it 'Count' do
48
52
  users_query.count.must_equal 10
49
53
  end
@@ -166,6 +170,25 @@ describe 'Query' do
166
170
  end
167
171
  end
168
172
 
173
+ describe 'Ignore undefined attributes' do
174
+
175
+ it 'First level' do
176
+ countries_query.raw.first.must_equal id: 1,
177
+ name: 'Argentina',
178
+ population: 40000000,
179
+ language_id: 1
180
+
181
+ [countries_query.detect(id: 1), countries_query.where(id: 1).order(:name).last, countries_query.all.first].each do |country|
182
+ country.must_equal Country.new(language_id: 1, id: 1, name: 'Argentina')
183
+ end
184
+ end
185
+
186
+ it 'Graph nested' do
187
+ languages_query.graph(:countries).first.countries.must_equal [Country.new(language_id: 1, id: 1, name: 'Argentina')]
188
+ end
189
+
190
+ end
191
+
169
192
  it 'Map' do
170
193
  users_query.map(&:name).must_equal db[:users].map(:name)
171
194
  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.1.0
4
+ version: 4.1.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: 2021-08-17 00:00:00.000000000 Z
11
+ date: 2022-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -294,10 +294,10 @@ extensions: []
294
294
  extra_rdoc_files: []
295
295
  files:
296
296
  - ".coveralls.yml"
297
+ - ".github/workflows/ci.yml"
297
298
  - ".gitignore"
298
299
  - ".ruby-gemset"
299
300
  - ".ruby-version"
300
- - ".travis.yml"
301
301
  - Gemfile
302
302
  - LICENSE.txt
303
303
  - README.md
data/.travis.yml DELETED
@@ -1,23 +0,0 @@
1
- language: ruby
2
-
3
- rvm:
4
- - 2.1
5
- - 2.2
6
- - 2.3
7
- - 2.4
8
- - 2.5
9
- - 2.6
10
- - 2.7
11
- - 3.0
12
- - jruby-9.2.9.0
13
- - ruby-head
14
- - jruby-head
15
-
16
- matrix:
17
- fast_finish: true
18
- allow_failures:
19
- - rvm: ruby-head
20
- - rvm: jruby-head
21
-
22
- jdk:
23
- - openjdk8