occams-record 0.6.0 → 0.7.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
  SHA1:
3
- metadata.gz: f60c7e2adfe9a547efe1d4c9eccd25b8baa7c733
4
- data.tar.gz: 7955381fac5f5792b7e9a537dd5962199dff7116
3
+ metadata.gz: 22118121c55c3eeb9cc211b6871f34d6ad9d94a5
4
+ data.tar.gz: bad217602878815157dba40a38cfd52ac58fdd6d
5
5
  SHA512:
6
- metadata.gz: 2e47c6911ac5648a01c9feeadcee5c1dd1e0a3d5dc9b475108bbbb86a6e06a87f31863521862ee6c807c33e85b34b793a9469188c1d72789d2cb389d088cdaf7
7
- data.tar.gz: 0a35392419e4527552da87d433754d0a2998d016d5a27f332f78d6932605cdb856e256175d06cfbd9f8c214bd4908b5ed6d8455c38169f0568c3ad4ac5442ce0
6
+ metadata.gz: 1da29e4dad1adabf559e808b691c9281d299abde694999ae4de00a8502ebfe61b9dcde370d84ddea754744fcc32580b644759a48a37b9de3ca521bca4a9d6836
7
+ data.tar.gz: 8daa621bd1b62c34750afb1075f9f868bd030b313b8deb947011527464e97941a50b83b64a1d0e1ac46225b34dc8a6eabae2ed719f976db249697efb32f14986
data/README.md CHANGED
@@ -17,7 +17,7 @@ For those stuck with ActiveRecord, OccamsRecord seeks to solve these issues by m
17
17
  * When eager loading associations you may specify which columns to `SELECT`. (This can be a significant performance boost to both your database and Rails app, on top of the above numbers.)
18
18
  * When eager loading associations you may completely customize the query (`WHERE`, `ORDER BY`, `LIMIT`, etc.)
19
19
  * By forcing eager loading of associations, OccamsRecord bypasses the primary cause of performance problems in Rails: N+1 queries.
20
- * The forced eager loading helps the developer visualize the "shape" of the query/result, which can make obvious certain insights that would otherwise require lots of digging. For example, if you're eager loading 15 associations, maybe you need to add some redundant foreign keys or denormalize some fields.
20
+ * Forced eager loading also makes you consider the "shape" of your data, which can help you identify areas that need refactored (e.g. redundant foreign keys, more denormalization, etc.)
21
21
 
22
22
  **What don't you give up?**
23
23
 
@@ -31,7 +31,7 @@ Glad you asked. [Look over the results yourself.](https://github.com/jhollinger/
31
31
 
32
32
  **Why not use a different ORM?**
33
33
 
34
- That's a great idea; check out [sequel](https://rubygems.org/gems/sequel) or [rom](https://rubygems.org/gems/rom)! But for large, legacy codebases heavily invested in ActiveRecord, switching ORMs often isn't practical. OccamsRecord can help you get some of those wins without throwing everything out.
34
+ That's a great idea; check out [sequel](https://rubygems.org/gems/sequel) or [rom](https://rubygems.org/gems/rom)! But for large, legacy codebases heavily invested in ActiveRecord, switching ORMs often isn't practical. OccamsRecord can help you get some of those wins without a rewrite.
35
35
 
36
36
  ## Usage
37
37
 
@@ -122,7 +122,7 @@ end
122
122
 
123
123
  widgets = OccamsRecord.
124
124
  query(Widget.order("name"), use: MyWidgetMethods).
125
- eager_load(:orders, use: MyOrderMethods).
125
+ eager_load(:orders, use: [MyOrderMethods, SomeAdditionalMethods]).
126
126
  run
127
127
 
128
128
  widgets[0].to_s
@@ -88,7 +88,7 @@ module OccamsRecord
88
88
  sql = scope.to_sql
89
89
  @query_logger << sql if @query_logger
90
90
  result = conn.exec_query sql
91
- row_class = OccamsRecord.build_result_row_class(model, result.columns, @eager_loaders.map(&:name), @use)
91
+ row_class = OccamsRecord.build_result_row_class(model, result.columns, result.column_types, @eager_loaders.map(&:name), modules: @use)
92
92
  rows = result.rows.map { |row| row_class.new row }
93
93
 
94
94
  @eager_loaders.each { |loader|
@@ -11,13 +11,14 @@ module OccamsRecord
11
11
  #
12
12
  # @param model [ActiveRecord::Base] the AR model representing the table (it holds column & type info).
13
13
  # @param column_names [Array<String>] the column names in the result set. The order MUST match the order returned by the query.
14
+ # @param column_types [Hash] Column name => type from an ActiveRecord::Result
14
15
  # @param association_names [Array<String>] names of associations that will be eager loaded into the results.
15
- # @param included_modules [Array<Module>] (optional)
16
+ # @param modules [Array<Module>] (optional)
16
17
  # @return [OccamsRecord::ResultRow] a class customized for this result set
17
18
  #
18
- def self.build_result_row_class(model, column_names, association_names, included_modules = nil)
19
+ def self.build_result_row_class(model, column_names, column_types, association_names, modules: nil)
19
20
  Class.new(ResultRow) do
20
- Array(included_modules).each { |mod| include mod } if included_modules
21
+ Array(modules).each { |mod| include mod } if modules
21
22
 
22
23
  self.columns = column_names.map(&:to_s)
23
24
  self.associations = association_names.map(&:to_s)
@@ -27,8 +28,11 @@ module OccamsRecord
27
28
  attr_accessor(*association_names)
28
29
 
29
30
  # Build a getter for each attribute returned by the query. The values will be type converted on demand.
30
- column_names.each_with_index do |col, idx|
31
- type = model.attributes_builder.types[col.to_s] || raise("OccamsRecord: Column `#{col}` does not exist on model `#{model.name}`")
31
+ self.columns.each_with_index do |col, idx|
32
+ type =
33
+ column_types[col] ||
34
+ model.attributes_builder.types[col] ||
35
+ raise("OccamsRecord: Column `#{col}` does not exist on model `#{self.model_name}`")
32
36
  define_method col do
33
37
  @cast_values_cache[idx] ||= type.send(TYPE_CAST_METHOD, @raw_values[idx])
34
38
  end
@@ -3,5 +3,5 @@
3
3
  #
4
4
  module OccamsRecord
5
5
  # Library version
6
- VERSION = '0.6.0'.freeze
6
+ VERSION = '0.7.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.6.0
4
+ version: 0.7.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: 2017-09-11 00:00:00.000000000 Z
11
+ date: 2017-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord