occams-record 1.7.0 → 1.7.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: 5f2590ba264934763d86310d4cd9b92459cb053589afa23fb4ea4c4b423f2eb7
4
- data.tar.gz: abb8aad716399e6b87d351e33a8f9ff629256964aed2f131795255cec3353b2a
3
+ metadata.gz: 0dc125a06b3fa732e1064483f13e5abbe2a7c64b4e6ac7f1b2d37337d8e233cb
4
+ data.tar.gz: 5c47a9a644b757463d5dd1961c1b86ed1de50cf247a286e8d1d0c3dd5daa99b8
5
5
  SHA512:
6
- metadata.gz: 2aa46cce2b26cd5a6e0219651dcdace5391a7a1b67ae5d4e6c3a9a849c6b12a63a2c913208af0ae58d5e7c7ce6880fdc2c1081a3a4b7582b2a8300f76548c0e3
7
- data.tar.gz: c3cdc38d42b7c97894bbe34215e9a8143209732c78fd8b5d8351932d5e7290783ec8239c8f5c21e6fa4f2f36325b97a76088953a9b0a28a7fd71c697aaa91993
6
+ metadata.gz: 7fb55ec18a98e4d2bb4b3fab8d3f609a378bee578d1b405d56a43b1f035f40d53149fc8dabc321bbaf17b180eb9e3b1dda282cc2fd8675a3e10c8bc59a9f7a59
7
+ data.tar.gz: f9f28ad1537cc297a0b5b1fe8a5209d4f4dfa4529148a603f715da884fa9d9f8188836aca84c8e5dcc36f674bb6abe7211de57c014e90a4539d892da0192c28d
data/README.md CHANGED
@@ -11,120 +11,33 @@ OccamsRecord is a high-efficiency, advanced query library for use alongside Acti
11
11
  * 3x-5x faster than ActiveRecord queries, *minimum*.
12
12
  * Uses 1/3 the memory of ActiveRecord query results.
13
13
  * Eliminates the N+1 query problem. (This often exceeds the baseline 3x-5x gain.)
14
- * Support for cursors (Postgres only, new in v1.4.0)
15
14
 
16
15
  ### 2) Supercharged querying & eager loading
17
16
 
18
- Continue using ActiveRecord's query builder, but let Occams take over running them, eager loading, and raw SQL calls. None of the examples below are possible with ActiveRecord, but OccamsRecord makes them trivial. (More complete examples are shown later, but these should whet your appetite.)
19
-
20
- **Customize the SQL used to eager load associations**
21
-
22
- ```ruby
23
- OccamsRecord
24
- .query(User.active)
25
- .eager_load(:orders) { |l|
26
- l.scope { |q| q.where("created_at >= ?", date).order("created_at DESC") }
27
- }
28
- ```
29
-
30
- **Use `ORDER BY` with `find_each`/`find_in_batches`**
31
-
32
- ```ruby
33
- OccamsRecord
34
- .query(Order.order("created_at DESC"))
35
- .find_each { |order|
36
- ...
37
- }
38
- ```
39
-
40
- **Use cursors**
41
-
42
- ```ruby
43
- OccamsRecord
44
- .query(Order.order("created_at DESC"))
45
- .find_each_with_cursor { |order|
46
- ...
47
- }
48
- ```
49
-
50
- **Use `find_each`/`find_in_batches` with raw SQL**
51
-
52
- ```ruby
53
- OccamsRecord
54
- .sql("
55
- SELECT * FROM orders
56
- WHERE created_at >= %{date}
57
- LIMIT %{batch_limit}
58
- OFFSET %{batch_offset}",
59
- {date: 10.years.ago}
60
- )
61
- .find_each { |order|
62
- ...
63
- }
64
- ```
65
-
66
- **Eager load associations when you're writing raw SQL**
67
-
68
- ```ruby
69
- OccamsRecord
70
- .sql("
71
- SELECT * FROM users
72
- LEFT OUTER JOIN ...
73
- ")
74
- .model(User)
75
- .eager_load(:orders)
76
- ```
77
-
78
- **Use `pluck` with raw SQL**
79
-
80
- ```ruby
81
- OccamsRecord
82
- .sql("
83
- SELECT some_col FROM users
84
- INNER JOIN ...
85
- ")
86
- .pluck(:some_col)
87
- ```
88
-
89
- **Eager load "ad hoc associations" using raw SQL**
90
-
91
- Relationships are complicated, and sometimes they can't be expressed in ActiveRecord models. Define your relationship on the fly!
92
- (Don't worry, there's a full explanation later on.)
93
-
94
- ```ruby
95
- OccamsRecord
96
- .query(User.all)
97
- .eager_load_many(:orders, {:id => :user_id}, "
98
- SELECT user_id, orders.*
99
- FROM orders INNER JOIN ...
100
- WHERE user_id IN (%{ids})
101
- ")
102
- ```
17
+ * Customize the SQL used to eager load associations (order them, apply filters, etc)
18
+ * Use cursors (Postgres only)
19
+ * Use `ORDER BY` with `find_each`/`find_in_batches`
20
+ * Use `find_each`/`find_in_batches` with raw SQL
21
+ * Eager load associations off of raw SQL queries
22
+ * Use `pluck` with raw SQL queries
103
23
 
24
+ ### How does OccamsRecord do all this?
104
25
  [Look over the speed and memory measurements yourself!](https://github.com/jhollinger/occams-record/wiki/Measurements) OccamsRecord achieves all of this by making some **very specific trade-offs:**
105
26
 
106
27
  * OccamsRecord results are *read-only*.
107
28
  * OccamsRecord results are *purely database rows* - they don't have any instance methods from your Rails models.
108
- * You *must eager load* each assocation you intend to use. If you forget one, an exception will be raised.
29
+ * You *must eager load* each assocation you intend to use. If you try to use one you didn't eager load, an exception will be raised.
109
30
 
110
- ---
31
+ # Overview
111
32
 
112
- # Installation
33
+ Full documentation is available at [rubydoc.info/gems/occams-record](http://www.rubydoc.info/gems/occams-record). Code lives at at [github.com/jhollinger/occams-record](https://github.com/jhollinger/occams-record). Contributions welcome!
113
34
 
114
- Simply add it to your `Gemfile`:
35
+ Simply add `occams-record` to your `Gemfile`:
115
36
 
116
37
  ```ruby
117
38
  gem 'occams-record'
118
39
  ```
119
40
 
120
- ---
121
-
122
- # Overview
123
-
124
- Full documentation is available at [rubydoc.info/gems/occams-record](http://www.rubydoc.info/gems/occams-record).
125
-
126
- Code lives at at [github.com/jhollinger/occams-record](https://github.com/jhollinger/occams-record). Contributions welcome!
127
-
128
41
  Build your queries like normal, using ActiveRecord's excellent query builder. Then pass them off to Occams Record.
129
42
 
130
43
  ```ruby
@@ -96,6 +96,8 @@ module OccamsRecord
96
96
  #
97
97
  def run
98
98
  sql = block_given? ? yield(scope).to_sql : scope.to_sql
99
+ return [] if sql.blank? # return early in case ActiveRecord::QueryMethods#none was used
100
+
99
101
  @query_logger << "#{@eager_loaders.tracer}: #{sql}" if @query_logger
100
102
  result = if measure?
101
103
  record_start_time!
@@ -237,6 +239,8 @@ module OccamsRecord
237
239
  #
238
240
  def pluck(*cols)
239
241
  sql = (block_given? ? yield(scope).to_sql : scope).select(*cols).to_sql
242
+ return [] if sql.blank? # return early in case ActiveRecord::QueryMethods#none was used
243
+
240
244
  @query_logger << "#{@eager_loaders.tracer}: #{sql}" if @query_logger
241
245
  result = if measure?
242
246
  record_start_time!
@@ -3,5 +3,5 @@
3
3
  #
4
4
  module OccamsRecord
5
5
  # @private
6
- VERSION = "1.7.0".freeze
6
+ VERSION = "1.7.1".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: 1.7.0
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Hollinger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-28 00:00:00.000000000 Z
11
+ date: 2023-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord