rotulus 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +3 -3
- data/lib/rotulus/order.rb +15 -2
- data/lib/rotulus/version.rb +1 -1
- metadata +2 -3
- data/Gemfile +0 -46
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bc659ce794517af485f9c65dc18467b4278c21e8813e612a0b4dcdabde0b10f
|
4
|
+
data.tar.gz: 2dc66e54844499214cc07ae49d8ca0ad33586ba28a11d4e2a3a4366d4633525a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f60f971213d39e4baa5d6fd53227971df6e09fb87f1824487e17a2972e80803db29e2b5894cc7b0be659d73ad3bf959a5944c5ed0235b754f19a80afe0cd69e1
|
7
|
+
data.tar.gz: f0b072563fe10c626772f2879d9533263b393452022a5e4547ea6e5413a5bfab92ef629dd3aa787328b3bda14ae89ae04e1d5c345073fe3ae2e2afc2092dae86
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Rotulus
|
2
2
|
|
3
|
-
[![CI](https://github.com/jsonb-uy/rotulus/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/jsonb-uy/rotulus/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/jsonb-uy/rotulus/branch/main/graph/badge.svg?token=OKGOWP4SH9)](https://codecov.io/gh/jsonb-uy/rotulus)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/rotulus.svg)](https://badge.fury.io/rb/rotulus) [![CI](https://github.com/jsonb-uy/rotulus/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/jsonb-uy/rotulus/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/jsonb-uy/rotulus/branch/main/graph/badge.svg?token=OKGOWP4SH9)](https://codecov.io/gh/jsonb-uy/rotulus)
|
4
4
|
|
5
5
|
### Cursor-based pagination for apps built on Rails/ActiveRecord
|
6
6
|
|
@@ -352,13 +352,13 @@ page = Rotulus::Page.new(User.all, order: { first_name: { direction: :asc, nulls
|
|
352
352
|
|
353
353
|
###### SQL:
|
354
354
|
```sql
|
355
|
-
-- if
|
355
|
+
-- if last_name value of the current page's last record is not null:
|
356
356
|
WHERE ((users.last_name >= ? OR users.last_name IS NULL) AND
|
357
357
|
((users.last_name > ? OR users.last_name IS NULL)
|
358
358
|
OR (users.last_name = ? AND users.id > ?)))
|
359
359
|
ORDER BY users.last_name asc nulls last, users.id asc LIMIT 3
|
360
360
|
|
361
|
-
-- if
|
361
|
+
-- if last_name value of the current page's last record is null:
|
362
362
|
WHERE users.last_name IS NULL AND users.id > ?
|
363
363
|
ORDER BY users.last_name asc nulls last, users.id asc LIMIT 3
|
364
364
|
```
|
data/lib/rotulus/order.rb
CHANGED
@@ -62,14 +62,14 @@ module Rotulus
|
|
62
62
|
#
|
63
63
|
# @return [String] the ORDER BY clause
|
64
64
|
def reversed_sql
|
65
|
-
Arel.sql(
|
65
|
+
Arel.sql(columns_for_order.map(&:reversed_order_sql).join(', '))
|
66
66
|
end
|
67
67
|
|
68
68
|
# Returns the ORDER BY sort expression(s) to sort the records
|
69
69
|
#
|
70
70
|
# @return [String] the ORDER BY clause
|
71
71
|
def sql
|
72
|
-
Arel.sql(
|
72
|
+
Arel.sql(columns_for_order.map(&:order_sql).join(', '))
|
73
73
|
end
|
74
74
|
|
75
75
|
# Generate a 'state' so we can detect whether the order definition has changed.
|
@@ -92,6 +92,19 @@ module Rotulus
|
|
92
92
|
|
93
93
|
attr_reader :ar_model, :definition, :raw_hash
|
94
94
|
|
95
|
+
def columns_for_order
|
96
|
+
return @columns_for_order if instance_variable_defined?(:@columns_for_order)
|
97
|
+
|
98
|
+
@columns_for_order = []
|
99
|
+
columns.each do |col|
|
100
|
+
@columns_for_order << col
|
101
|
+
|
102
|
+
break if col.distinct? && !col.nullable?
|
103
|
+
end
|
104
|
+
|
105
|
+
@columns_for_order
|
106
|
+
end
|
107
|
+
|
95
108
|
def ar_model_primary_key
|
96
109
|
ar_model.primary_key
|
97
110
|
end
|
data/lib/rotulus/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rotulus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Uy Jayson B
|
@@ -73,7 +73,6 @@ extensions: []
|
|
73
73
|
extra_rdoc_files: []
|
74
74
|
files:
|
75
75
|
- CHANGELOG.md
|
76
|
-
- Gemfile
|
77
76
|
- LICENSE
|
78
77
|
- README.md
|
79
78
|
- lib/rotulus.rb
|
@@ -97,7 +96,7 @@ metadata:
|
|
97
96
|
homepage_uri: https://github.com/jsonb-uy/rotulus
|
98
97
|
source_code_uri: https://github.com/jsonb-uy/rotulus
|
99
98
|
changelog_uri: https://github.com/jsonb-uy/rotulus/blob/main/CHANGELOG.md
|
100
|
-
documentation_uri: https://rubydoc.info/github/jsonb-uy/rotulus
|
99
|
+
documentation_uri: https://rubydoc.info/github/jsonb-uy/rotulus/main
|
101
100
|
bug_tracker_uri: https://github.com/jsonb-uy/rotulus/issues
|
102
101
|
post_install_message:
|
103
102
|
rdoc_options: []
|
data/Gemfile
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
gemspec
|
3
|
-
|
4
|
-
rails_version = ENV['RAILS_VERSION'] || '7-0-stable'
|
5
|
-
|
6
|
-
gem 'rake'
|
7
|
-
gem 'rspec'
|
8
|
-
|
9
|
-
if ENV.fetch('COVERAGE', nil) == 'true'
|
10
|
-
gem 'simplecov'
|
11
|
-
gem 'simplecov-cobertura'
|
12
|
-
end
|
13
|
-
|
14
|
-
case rails_version
|
15
|
-
when '4-2-stable'
|
16
|
-
# Ruby 2.2 or newer.
|
17
|
-
gem 'pg', '~> 0.15'
|
18
|
-
gem 'sqlite3', '~> 1.3.6'
|
19
|
-
gem 'mysql2', '~> 0.4.4'
|
20
|
-
when '5-0-stable', '5-1-stable', '5-2-stable'
|
21
|
-
# Ruby 2.2.2 or newer.
|
22
|
-
gem 'pg', '~> 0.18'
|
23
|
-
gem 'sqlite3', '~> 1.3.6'
|
24
|
-
gem 'mysql2', '~> 0.4.4'
|
25
|
-
when '6-0-stable'
|
26
|
-
# Ruby 2.5.0 or newer.
|
27
|
-
gem 'pg', '~> 0.18'
|
28
|
-
gem 'sqlite3', '~> 1.4'
|
29
|
-
gem 'mysql2', '>= 0.4.4'
|
30
|
-
when '6-1-stable'
|
31
|
-
# Ruby 2.5.0 or newer.
|
32
|
-
gem 'pg', '~> 1.1'
|
33
|
-
gem 'sqlite3', '~> 1.4'
|
34
|
-
gem 'mysql2', '~> 0.5'
|
35
|
-
when '7-0-stable'
|
36
|
-
# Ruby 2.7.0 or newer.
|
37
|
-
gem 'pg', '~> 1.1'
|
38
|
-
gem 'sqlite3', '~> 1.4'
|
39
|
-
gem 'mysql2', '~> 0.5'
|
40
|
-
else
|
41
|
-
gem 'pg'
|
42
|
-
gem 'sqlite3'
|
43
|
-
gem 'mysql2'
|
44
|
-
end
|
45
|
-
|
46
|
-
gem 'rails', git: 'https://github.com/rails/rails', branch: rails_version
|