rotulus 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +18 -17
  3. data/lib/rotulus/version.rb +1 -1
  4. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 07fe3f3acca52daa7170d766b516bbb39b8ad133abee1a60d635ea0c1c3521c3
4
- data.tar.gz: b31d8781affc551740fe13878e8f269e73802c1b111bf5c29d94a4629850a9e7
3
+ metadata.gz: 7504d29a1bd4aac2f21ffb981abd98b544b8b50f80fa7f875cc73286e967e9a2
4
+ data.tar.gz: afbd5665291c310b0fd03e87cebd0b100da71dcfdedae7953b4844c767859ce3
5
5
  SHA512:
6
- metadata.gz: 0dc571a3bcde992068a7739c3ec482b44b5af9cbe269d33266177e30ae9c89219df5caea3b34cbe371880349148979fc6e322c23fbed01730e9ce1f391c532d0
7
- data.tar.gz: 0a1fe9c87952093123df6687b9a7bb73c1f372b8d380d9d2d79be6fee2012fed0eb10f58f012242ce6a7c0e1947c76e6abfc4900fa47a021ddf3ecc579c39c7a
6
+ metadata.gz: 19d4f2b1e1a734c78b8d63954ef66ba443591a7fc2c04364eccc6e1a0780b4f3e6346af327e53f3ba773bafca9a39b3abd5ef7efc8937b71a8fc534d7d16dc84
7
+ data.tar.gz: 0a739f5977b51127934658605a304f78a6be0ffe8d4e3e0ddce8fe4abc1223e6bf0c7ef1dfd39afd6b675f7006b9b3f4074fd11cf5329d9433886dd06dc18bd8
data/README.md CHANGED
@@ -8,9 +8,10 @@ Cursor-based pagination is an alternative to OFFSET-based pagination that provid
8
8
 
9
9
  Some advantages of this approach are:
10
10
 
11
- * Reduces inaccuracies such as duplicate/skipped records due to records being actively manipulated in the DB.
11
+ * Reduces inaccuracies such as duplicate or skipped records as records are being manipulated.
12
12
  * Can significantly improve performance(with proper DB indexing on ordered columns) especially as you move forward on large datasets.
13
13
 
14
+
14
15
  **TL;DR** See [ sample usage for Rails here ](#rails-usage).
15
16
 
16
17
  ## Features
@@ -98,7 +99,7 @@ page = Rotulus::Page.new(users)
98
99
 
99
100
  page = Rotulus::Page.new(users, order: { first_name: :asc, last_name: :desc }, limit: 3)
100
101
  ```
101
- With the example above, the gem will automatically add the table's PK(`users.id`) in the generated SQL query as the tie-breaker column to ensure stable sorting and pagination.
102
+ The gem will automatically add the table's PK(`users.id`) in the `ORDER BY` as the tie-breaker column to ensure stable sorting and pagination.
102
103
 
103
104
 
104
105
  #### Access the page records
@@ -204,7 +205,7 @@ puts page.as_table
204
205
 
205
206
  ### Advanced Usage
206
207
  #### Expanded order definition
207
- Instead of just specifying the column sorting such as ```{ first_name: :asc }``` in the :order param, one can use the expanded order config in `Hash` format for more sorting options:
208
+ Instead of just specifying the column sorting such as ```{ first_name: :asc }``` in the :order param, one can use the expanded order config in `Hash` format for more sorting options that would help the library to generate the optimal query:
208
209
 
209
210
  | Column Configuration | Description |
210
211
  | ----------- | ----------- |
@@ -339,14 +340,14 @@ private
339
340
 
340
341
  # Allow clients to sort by first_name, last_name, and/or email.
341
342
  # example sort values:
342
- # a. params[:sort] = +users.last_name,-users.email
343
+ # a. params[:sort] = +last_name,-email
343
344
  # b. params[:sort] = -first_name
344
345
  def index_order
345
346
  SortParam.define do
346
- field 'users.first_name'
347
- field 'users.last_name', nulls: :last, nullable: true
348
- field 'users.email', distinct: true
349
- end.load!(params[:sort].presence || '+users.first_name')
347
+ field 'first_name'
348
+ field 'last_name', nulls: :last, nullable: true
349
+ field 'email', distinct: true
350
+ end.load!(params[:sort].presence || 'first_name')
350
351
  end
351
352
  ```
352
353
 
@@ -360,19 +361,19 @@ end
360
361
  | `Rotulus::CursorError` | Generic error for cursor related validations |
361
362
  | `Rotulus::InvalidColumn` | Column provided in the :order param can't be found. |
362
363
  | `Rotulus::MissingTiebreaker` | There is no non-nullable and distinct column in the configured order definition. |
363
- | `Rotulus::ConfigurationError` | Generic error for missing/invalid configurations. |
364
- | `Rotulus::OrderChanged` | Error raised paginating with a token(i.e. calling `Page#at` or `Page#at!`) that was generated from a previous page instance with a different `:order` definition. Can be enabled by setting the `restrict_order_change` to true. |
365
- | `Rotulus::QueryChanged` | Error raised paginating with a token(i.e. calling `Page#at` or `Page#at!`) that was generated from a previous page instance with a different `:ar_relation` filter/query. Can be enabled by setting the `restrict_query_change` to true. |
364
+ | `Rotulus::ConfigurationError` | Generic error for missing/invalid configuration. |
365
+ | `Rotulus::OrderChanged` | Raised when passing a token to `Page#at` or `Page#at!` methods of a page instance, and the token was generated from a page instance with a different `:order` definition. Can be enabled by setting the `restrict_order_change` to true. |
366
+ | `Rotulus::QueryChanged` | Raised when passing a token to `Page#at` or `Page#at!` methods of a page instance, and the token was generated from a page instance with a different `:ar_relation` filter/query. Can be enabled by setting the `restrict_query_change` to true. |
366
367
 
367
368
  ## How it works
368
- Cursor-based pagination uses a reference point/record to fetch the previous or next set of records. This gem takes care of the SQL query and cursor generation needed for the pagination. To ensure that the pagination results are stable, it requires that:
369
+ Cursor-based pagination uses a reference record to fetch the relative set of previous or next records. This gem takes care of the SQL query and cursor generation needed for the pagination. To ensure that the pagination results are stable, it requires that:
369
370
 
370
- * Records are sorted (`ORDER BY`).
371
+ * Records are sorted (`ORDER BY`) by columns.
371
372
  * In case multiple records with the same column value(s) exists in the result, a unique non-nullable column is needed as tie-breaker. Usually, the table PK suffices for this but for complex queries(e.g. with table joins and with nullable columns, etc.), combining and using multiple columns that would uniquely identify the row in the result is needed.
372
373
  * Columns used in `ORDER BY` would need to be indexed as they will be used in filtering.
373
374
 
374
375
 
375
- #### Sample SQL-generated snippets
376
+ #### Sample SQL-generated snippets to fetch the next set of records
376
377
 
377
378
  ##### Example 1: With order by `id` only
378
379
  ###### Ruby
@@ -459,10 +460,10 @@ WHERE users.first_name >= 'Jane' AND (
459
460
  ```
460
461
 
461
462
  #### Custom Token Format
462
- By default, the cursor is encoded as a Base64 token. To customize how the cursor is encoded and decoded, you may just create a subclass of `Rotulus::Cursor` with `.decode` and `.encode` methods implemented.
463
+ By default, the cursor is encoded as a Base64 token. To customize how the cursor is encoded and decoded, you may just need to subclass `Rotulus::Cursor` with the `.decode` and `.encode` methods implemented.
463
464
 
464
465
  ##### Example:
465
- The implementation below would generate tokens in UUID format where the actual cursor data is stored in memory:
466
+ The implementation below would generate tokens in UUID format where the actual cursor data is stored in memory(in production, you would use a distributed data store such as Redis):
466
467
 
467
468
  ```ruby
468
469
  class MyCustomCursor < Rotulus::Cursor
@@ -526,7 +527,7 @@ end
526
527
  | Environment Variable | Values | Example |
527
528
  | ----------- | ----------- |----------- |
528
529
  | `DB_ADAPTER` | **Default: :sqlite**. `sqlite`,`mysql2`, or `postgresql` | ```DB_ADAPTER=postgresql bundle exec rspec```<br/><br/> ```DB_ADAPTER=postgresql ./bin/console``` |
529
- | `RAILS_VERSION` | **Default: 7-0** <br/><br/> `4-2`,`5-0`,`5-1`,`5-2`,`6-0`,`6-1`,`7-0` |```RAILS_VERSION=5-2 ./bin/setup```<br/><br/>```RAILS_VERSION=5-2 bundle exec rspec```<br/><br/> ```RAILS_VERSION=5-2 ./bin/console```|
530
+ | `RAILS_VERSION` | **Default: 7-1** <br/><br/> `4-2`,`5-0`,`5-1`,`5-2`,`6-0`,`6-1`,`7-0`, `7-1` |```RAILS_VERSION=5-2 ./bin/setup```<br/><br/>```RAILS_VERSION=5-2 bundle exec rspec```<br/><br/> ```RAILS_VERSION=5-2 ./bin/console```|
530
531
 
531
532
 
532
533
  <br/><br/>
@@ -1,3 +1,3 @@
1
1
  module Rotulus
2
- VERSION = '2.0.0'.freeze
2
+ VERSION = '2.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rotulus
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Uy Jayson B
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-10 00:00:00.000000000 Z
11
+ date: 2024-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '4.2'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '7.1'
22
+ version: '7.2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '4.2'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '7.1'
32
+ version: '7.2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: activesupport
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +39,7 @@ dependencies:
39
39
  version: '4.2'
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
- version: '7.1'
42
+ version: '7.2'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -49,7 +49,7 @@ dependencies:
49
49
  version: '4.2'
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
- version: '7.1'
52
+ version: '7.2'
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: multi_json
55
55
  requirement: !ruby/object:Gem::Requirement