occams-record 1.4.0.pre.beta1 → 1.4.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
  SHA256:
3
- metadata.gz: 662bd65e909a1d957ebdbbd2d3bec3fe96fb45aac2117a786c9a3ad02b03259b
4
- data.tar.gz: abeb69ff706dbb11f3fae3672ae60c407080f418fce7330779a7b550915aa886
3
+ metadata.gz: c1dc718c0f99f5ad039974f8db3bd1c5304e41a3b3275d26dd1d86235c7790fe
4
+ data.tar.gz: 8af374148ca1f1c8342b7eb8fdb30031d6c31a1d923a6e7cab55b96712ed2602
5
5
  SHA512:
6
- metadata.gz: 8981d9c820b64ebeca28dcbe3ab7ac44e35d8ec7e14df201e890ccf6cf1cf1888d6f78ba6cac001f1a9c458f604189b1aafaf7ff644288499faf5d5afeb896c3
7
- data.tar.gz: cdd61c50313a964db4ebdb271dbb875fc4ea888dd0b57df78be78d043e655e04e821e0cef8d9b60034e90866289a0d764f72a7728a18f46c778e511101b72f4a
6
+ metadata.gz: 54b539bc70b1fc92c087fbc91f7edbaa1eb4dabacfda80ca0afa4ccd4ac53e832d431f3c95e35785cfa7bd7075879c655ae54019c3f341255b4411929b5ae615
7
+ data.tar.gz: c1c9aed1007bcfeb0e577d08af6f86fa340e375fede08af03bd18fbc2538cfcbd4838fc5bd07c672fca6e02ca3c0ec9e8d442b3e3275deff58215dfba873df7a
data/README.md CHANGED
@@ -9,6 +9,7 @@ OccamsRecord is a high-efficiency, advanced query library for use alongside Acti
9
9
  * 3x-5x faster than ActiveRecord queries, *minimum*.
10
10
  * Uses 1/3 the memory of ActiveRecord query results.
11
11
  * Eliminates the N+1 query problem. (This often exceeds the baseline 3x-5x gain.)
12
+ * Support for cursors (Postgres only, new in v1.4.0-beta1)
12
13
 
13
14
  ### 2) Supercharged querying & eager loading
14
15
 
@@ -32,6 +33,16 @@ OccamsRecord
32
33
  }
33
34
  ```
34
35
 
36
+ **Use cursors**
37
+
38
+ ```ruby
39
+ OccamsRecord
40
+ .query(Order.order("created_at DESC"))
41
+ .find_each_with_cursor { |order|
42
+ ...
43
+ }
44
+ ```
45
+
35
46
  **Use `find_each`/`find_in_batches` with raw SQL**
36
47
 
37
48
  ```ruby
@@ -156,15 +167,59 @@ orders = OccamsRecord
156
167
  .run
157
168
  ```
158
169
 
159
- Occams Record also supports loading ad hoc associations using raw SQL. We'll get to that in the next section.
170
+ Occams Record also supports loading ad hoc associations using raw SQL. We'll get to that in a later section.
171
+
172
+ ## Query with cursors
173
+
174
+ `find_each_with_cursor`/`find_in_batches_with_cursor` work like `find_each`/`find_in_batches`, except they use cursors. For large data sets, cursors offer a noticible speed boost. Postgres only.
175
+
176
+ ```ruby
177
+ OccamsRecord
178
+ .query(q)
179
+ .eager_load(:customer)
180
+ .find_each_with_cursor do |order|
181
+ ...
182
+ end
183
+ ```
184
+
185
+ The `cursor.open` method allows lower level access to cursor behavior. See `OccamsRecord::Cursor` for more info.
186
+
187
+ ```ruby
188
+ orders = OccamsRecord
189
+ .query(q)
190
+ .eager_load(:customer)
191
+ .cursor
192
+ .open do |cursor|
193
+ cursor.move(:forward, 300)
194
+ cursor.fetch(:forward, 100)
195
+ end
196
+ ```
160
197
 
161
198
  ## Raw SQL queries
162
199
 
163
200
  ActiveRecord has raw SQL escape hatches like `find_by_sql` and `exec_query`, but they give up critical features like eager loading and `find_each`/`find_in_batches`. Occams Record's escape hatches don't make you give up anything.
164
201
 
165
- **Batched loading**
202
+ **Batched loading with cursors**
203
+
204
+ `find_each_with_cursor`, `find_in_batches_with_cursor`, and `cursor.open` are all available.
205
+
206
+ ```ruby
207
+ OccamsRecord
208
+ .sql("
209
+ SELECT * FROM orders
210
+ WHERE order_date > %{date}
211
+ ORDER BY order_date DESC, id
212
+ ", {
213
+ date: 10.years.ago
214
+ })
215
+ .find_each_with_cursor(batch_size: 1000) do |order|
216
+ ...
217
+ end
218
+ ```
219
+
220
+ **Batched loading without cursors**
166
221
 
167
- To use `find_each`/`find_in_batches` you must provide the limit and offset statements yourself; Occams will provide the values. Also, notice that the binding syntax is a bit different (it uses Ruby's built-in named string substitution).
222
+ If your database doesn't support cursors, you can use `find_each`/`find_in_batches`. Just provide `LIMIT` and `OFFSET` (see below), and Occams will plug in the right numbers.
168
223
 
169
224
  ```ruby
170
225
  OccamsRecord
@@ -1,6 +1,9 @@
1
1
  module OccamsRecord
2
2
  module Batches
3
3
  module OffsetLimit
4
+ #
5
+ # Implements batched loading for pure SQL.
6
+ #
4
7
  class RawQuery
5
8
  def initialize(conn, sql, binds, use: nil, query_logger: nil, eager_loaders: nil)
6
9
  @conn, @sql, @binds = conn, sql, binds
@@ -1,9 +1,9 @@
1
1
  module OccamsRecord
2
- #
3
- # Methods for building batch finding methods. It expects "model" and "scope" methods to be present.
4
- #
5
2
  module Batches
6
3
  module OffsetLimit
4
+ #
5
+ # Implements batched loading for ActiveRecord model scopes.
6
+ #
7
7
  class Scoped
8
8
  def initialize(model, scope, use: nil, query_logger: nil, eager_loaders: nil)
9
9
  @model, @scope = model, scope
@@ -1,10 +1,10 @@
1
1
  require 'securerandom'
2
2
 
3
3
  module OccamsRecord
4
- #
5
- # An interface to database cursors. Supported databases:
6
- # * PostgreSQL
7
- #
4
+ #
5
+ # An interface to database cursors. Supported databases:
6
+ # * PostgreSQL
7
+ #
8
8
  class Cursor
9
9
  # @private
10
10
  SCROLL = {
@@ -3,5 +3,5 @@
3
3
  #
4
4
  module OccamsRecord
5
5
  # @private
6
- VERSION = "1.4.0-beta1".freeze
6
+ VERSION = "1.4.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: 1.4.0.pre.beta1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Hollinger
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-22 00:00:00.000000000 Z
11
+ date: 2022-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -83,7 +83,7 @@ homepage: https://jhollinger.github.io/occams-record/
83
83
  licenses:
84
84
  - MIT
85
85
  metadata: {}
86
- post_install_message:
86
+ post_install_message:
87
87
  rdoc_options: []
88
88
  require_paths:
89
89
  - lib
@@ -94,12 +94,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
94
94
  version: 2.3.0
95
95
  required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  requirements:
97
- - - ">"
97
+ - - ">="
98
98
  - !ruby/object:Gem::Version
99
- version: 1.3.1
99
+ version: '0'
100
100
  requirements: []
101
- rubygems_version: 3.1.6
102
- signing_key:
101
+ rubygems_version: 3.0.3.1
102
+ signing_key:
103
103
  specification_version: 4
104
104
  summary: The missing high-efficiency query API for ActiveRecord
105
105
  test_files: []