occams-record 0.26.0 → 0.27.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2d1c4320c6ac238acbb8329b672c5bc487fa14e5
4
- data.tar.gz: 38f86e3f7467fa1134b62e6500c25278a7d1be80
2
+ SHA256:
3
+ metadata.gz: 9c718e8ed411d6d2a139dcc27c2c0f7fa788fc6dafb8c534d3332682c85502f6
4
+ data.tar.gz: 464d6e322e1a478f861cb576b4e506589da318485c29fe5ec852726fcba2a692
5
5
  SHA512:
6
- metadata.gz: 3be346b9c94d373cec5955b8c0577edbc62b80b74d958b95e3ff4dcf5a768a59192a4fd9938933b50c06185d568a3467428c92fbf5921838ed6ce17a0c183918
7
- data.tar.gz: f56c580afb05217f7ce219d53de678dbb8f7e098cdd62ba01557e4ebd42adc8c4dd45817a8d437f9610e840834988becd69f1071add021a727fd67ef8e79752e
6
+ metadata.gz: ed85408318c87e662a14cc863fe43cb2b2e1f1a5aae739ff1a1b22968957a455e771e3ac6fcb3b902b0febe9585bddad6b4c02640bfaa077a6e6a98f3a3c148d
7
+ data.tar.gz: 78f981128bd9fad0d6a670ed21426366cf3ac1b74169f3571a6335ae9cf1d5a5c2c790fa7f4bc1c09d4b5756a0a7850998467a779c7bef4db2dc50b1553fb330
data/README.md CHANGED
@@ -7,7 +7,7 @@ Occam's Record is a high-efficiency, advanced query library for ActiveRecord app
7
7
  * 3x-5x faster than ActiveRecord queries.
8
8
  * Uses 1/3 the memory of ActiveRecord query results.
9
9
  * Eliminates the N+1 query problem.
10
- * Allows custom SQL when eager loading associations (use `select`, `where`, `order`, etc).
10
+ * Customize the SQL when eager loading associations.
11
11
  * `find_each`/`find_in_batches` respects `order` and `limit`.
12
12
  * Allows eager loading of associations when querying with raw SQL.
13
13
  * Allows `find_each`/`find_in_batches` when querying with raw SQL.
@@ -34,9 +34,13 @@ module OccamsRecord
34
34
  #
35
35
  def run(rows, query_logger: nil)
36
36
  calc_ids(rows) { |ids|
37
- binds = @binds.merge({:ids => ids})
38
- assoc_rows = RawQuery.new(@sql, binds, use: @use, query_logger: query_logger, &@eval_block).model(@model).run
39
- merge! assoc_rows, rows
37
+ assoc = if ids.any?
38
+ binds = @binds.merge({:ids => ids})
39
+ RawQuery.new(@sql, binds, use: @use, query_logger: query_logger, &@eval_block).model(@model).run
40
+ else
41
+ []
42
+ end
43
+ merge! assoc, rows
40
44
  }
41
45
  end
42
46
 
@@ -56,7 +60,7 @@ module OccamsRecord
56
60
  raise MissingColumnError.new(row, e.name)
57
61
  end
58
62
  }.compact.uniq
59
- yield ids if ids.any?
63
+ yield ids
60
64
  end
61
65
 
62
66
  def merge!(assoc_rows, rows)
@@ -29,8 +29,7 @@ module OccamsRecord
29
29
  #
30
30
  def run(rows, query_logger: nil)
31
31
  query(rows) { |*args|
32
- scope = args[0]
33
- assoc_rows = Query.new(scope, use: @use, query_logger: query_logger, &@eval_block).run
32
+ assoc_rows = args[0] ? Query.new(args[0], use: @use, query_logger: query_logger, &@eval_block).run : []
34
33
  merge! assoc_rows, rows, *args[1..-1]
35
34
  }
36
35
  end
@@ -13,7 +13,7 @@ module OccamsRecord
13
13
  def query(rows)
14
14
  join_rows = fetch_join_rows(rows)
15
15
  assoc_ids = join_rows.map { |row| row[1] }.compact.uniq
16
- yield base_scope.where(@ref.association_primary_key => assoc_ids), join_rows if assoc_ids.any?
16
+ yield assoc_ids.any? ? base_scope.where(@ref.association_primary_key => assoc_ids) : nil, join_rows
17
17
  end
18
18
 
19
19
  #
@@ -21,7 +21,7 @@ module OccamsRecord
21
21
  }.compact.uniq
22
22
  q = base_scope.where(@ref.foreign_key => ids)
23
23
  q.where!(@ref.type => rows[0].class&.model_name) if @ref.options[:as]
24
- yield q if ids.any?
24
+ yield ids.any? ? q : nil
25
25
  end
26
26
 
27
27
  #
@@ -53,6 +53,9 @@ module OccamsRecord
53
53
  #
54
54
  # Abstract class for result rows.
55
55
  #
56
+ # Like ActiveRecord, Boolean columns have #field? methods. However, unlike ActiveRecord,
57
+ # other column types do NOT.
58
+ #
56
59
  class Row
57
60
  class << self
58
61
  # Array of column names
@@ -3,5 +3,5 @@
3
3
  #
4
4
  module OccamsRecord
5
5
  # Library version
6
- VERSION = '0.26.0'.freeze
6
+ VERSION = '0.27.0'.freeze
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: occams-record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.26.0
4
+ version: 0.27.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Hollinger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-27 00:00:00.000000000 Z
11
+ date: 2018-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  version: '0'
77
77
  requirements: []
78
78
  rubyforge_project:
79
- rubygems_version: 2.5.2.2
79
+ rubygems_version: 2.7.3
80
80
  signing_key:
81
81
  specification_version: 4
82
82
  summary: The missing high-efficiency query API for ActiveRecord