active_record-cursor_paginator 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/.ruby-version +1 -1
- data/CHANGELOG.md +9 -0
- data/lib/active_record/cursor_paginator/version.rb +1 -1
- data/lib/active_record/cursor_paginator.rb +36 -3
- metadata +4 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0e6079364fab39f26c9d63199730cc44ae0138c5c3d8452aa1b73219e0afa0e1
|
|
4
|
+
data.tar.gz: 36d9c3020d18dafe2905b18a6a50bebee06ab17caff4ff4abd4eb9bb965aa851
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: db459de8e2b52873f5ccb95e9bb7b957af9381a30fcfca97786189874bfacc8808f80fb939ea86d54c8f50cb5983b263089df16f4e7f2294387d41757cf723d1
|
|
7
|
+
data.tar.gz: a344ab46f80d38a5c43d890793031a31194d3f3b7dfe6b53258c94a77a08386470c7201e46f5d6833cd2f9e77c0f3fa940afb0306c951648193b1f04f0530ce9
|
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
ruby-3.
|
|
1
|
+
ruby-3.4.4
|
data/CHANGELOG.md
CHANGED
|
@@ -160,10 +160,23 @@ module ActiveRecord
|
|
|
160
160
|
# value from this other field as well as the records ID to resolve the order
|
|
161
161
|
# of duplicates in the non-ID field.
|
|
162
162
|
#
|
|
163
|
+
# For enum columns, we store the raw integer value instead of the string
|
|
164
|
+
# representation to ensure proper SQL comparison in WHERE clauses.
|
|
165
|
+
#
|
|
163
166
|
# @param record [ActiveRecord] Model instance for which we want the cursor
|
|
164
167
|
# @return [String]
|
|
165
168
|
def cursor_for_record(record)
|
|
166
|
-
unencoded_cursor = @fields.map
|
|
169
|
+
unencoded_cursor = @fields.map do |field|
|
|
170
|
+
field_name = field.keys.first
|
|
171
|
+
value = if record.class.defined_enums.key?(field_name.to_s)
|
|
172
|
+
# For enum columns, get the raw integer value from the database
|
|
173
|
+
record.read_attribute_before_type_cast(field_name)
|
|
174
|
+
else
|
|
175
|
+
# For regular columns, get the typed value
|
|
176
|
+
record[field_name]
|
|
177
|
+
end
|
|
178
|
+
{ field_name => value }
|
|
179
|
+
end
|
|
167
180
|
Base64.strict_encode64(unencoded_cursor.to_json)
|
|
168
181
|
end
|
|
169
182
|
|
|
@@ -256,10 +269,12 @@ module ActiveRecord
|
|
|
256
269
|
relation = sorted_relation
|
|
257
270
|
prev_fields.each do |col, val|
|
|
258
271
|
col = @aliases[col] if @aliases.has_key? col
|
|
272
|
+
col = qualify_field_if_needed(col)
|
|
259
273
|
relation = relation.where("#{col} = ?", val)
|
|
260
274
|
end
|
|
261
275
|
col, val = current_field
|
|
262
276
|
col = @aliases[col] if @aliases.has_key? col
|
|
277
|
+
col = qualify_field_if_needed(col)
|
|
263
278
|
relation.where("#{col} #{op} ?", val)
|
|
264
279
|
end
|
|
265
280
|
|
|
@@ -276,7 +291,7 @@ module ActiveRecord
|
|
|
276
291
|
# "value [AS|as] alias" という形式に対応する
|
|
277
292
|
# value: spaceがあってもOK. 最小マッチングのため '?' をつける
|
|
278
293
|
# 'as' は使わないのでキャプチャしない
|
|
279
|
-
match = expr.match(
|
|
294
|
+
match = expr.match(/\A(?<value>.+?)\s+(?:as\s+)?(?<alias>\S+)\z/i)
|
|
280
295
|
next if match.nil? || match.length < 3
|
|
281
296
|
|
|
282
297
|
key = trim_quote(match[:alias])
|
|
@@ -287,7 +302,25 @@ module ActiveRecord
|
|
|
287
302
|
end
|
|
288
303
|
|
|
289
304
|
def trim_quote(field)
|
|
290
|
-
field.gsub(/^[
|
|
305
|
+
field.gsub(/^[`"]/, '').gsub(/[`"]$/, '')
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
# Qualifies a field name with the table name unless it is already qualified or is a SQL function.
|
|
309
|
+
#
|
|
310
|
+
# If the field name contains a dot (.) or an opening parenthesis, it is assumed to be
|
|
311
|
+
# already qualified or a SQL function and is returned as-is. Otherwise, the field name
|
|
312
|
+
# is trimmed of quotes and prefixed with the table name.
|
|
313
|
+
#
|
|
314
|
+
# @param field [String] The field name to qualify.
|
|
315
|
+
# @return [String] The qualified field name or the original field if already qualified or a function.
|
|
316
|
+
def qualify_field_if_needed(field)
|
|
317
|
+
# qualified なフィールド名とSQL関数を簡易的に判定します
|
|
318
|
+
if field.include?('.') || field.include?('(')
|
|
319
|
+
field
|
|
320
|
+
else
|
|
321
|
+
field = trim_quote(field)
|
|
322
|
+
"#{@relation.table_name}.#{field}"
|
|
323
|
+
end
|
|
291
324
|
end
|
|
292
325
|
end
|
|
293
326
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: active_record-cursor_paginator
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shinichi Sugiyama
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: activerecord
|
|
@@ -53,7 +52,6 @@ metadata:
|
|
|
53
52
|
source_code_uri: https://github.com/ssugiyama/active_record-cursor_paginator
|
|
54
53
|
changelog_uri: https://github.com/ssugiyama/active_record-cursor_paginator/Changelog.md
|
|
55
54
|
rubygems_mfa_required: 'true'
|
|
56
|
-
post_install_message:
|
|
57
55
|
rdoc_options: []
|
|
58
56
|
require_paths:
|
|
59
57
|
- lib
|
|
@@ -61,15 +59,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
61
59
|
requirements:
|
|
62
60
|
- - ">="
|
|
63
61
|
- !ruby/object:Gem::Version
|
|
64
|
-
version:
|
|
62
|
+
version: 3.0.0
|
|
65
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
64
|
requirements:
|
|
67
65
|
- - ">="
|
|
68
66
|
- !ruby/object:Gem::Version
|
|
69
67
|
version: '0'
|
|
70
68
|
requirements: []
|
|
71
|
-
rubygems_version: 3.
|
|
72
|
-
signing_key:
|
|
69
|
+
rubygems_version: 3.7.2
|
|
73
70
|
specification_version: 4
|
|
74
71
|
summary: cursor pagination for ActiveRecord
|
|
75
72
|
test_files: []
|