appquery 0.7.0.rc6 → 0.7.0
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/CHANGELOG.md +26 -0
- data/lib/app_query/base_query.rb +4 -1
- data/lib/app_query/paginatable.rb +7 -1
- data/lib/app_query/render_helpers.rb +1 -0
- data/lib/app_query/tokenizer.rb +1 -1
- data/lib/app_query/version.rb +1 -1
- data/lib/app_query.rb +3 -4
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f5eeb81f992ea777b44680277fcf8ef0d763aa1e8d4d6b1750eb81f9198d5262
|
|
4
|
+
data.tar.gz: d9939585c40818303e0da886c459ad65c030b2501f8399942cf5b0b2a6d308ab
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8f5a4abb4f4e38477dba038d927ac19bef2c0b252f41d820e78706ab60bd2d22dcd07ee739781266fa52bb86317f44347a98bae1e109159c5a805c778534602c
|
|
7
|
+
data.tar.gz: 73f165536629ca28cd7077156ed67ee5b78f6b750fe7c69d62d98c8c6005ba004b770972b600378f7a05be36bb7a5bc214f2bf55a8c7695f509d76971a37dd3d
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
### 💥 Breaking Changes
|
|
4
|
+
|
|
5
|
+
- ⛔ drop Ruby 3.2 support
|
|
6
|
+
Ruby 3.2 will be EOL in 2 months but is already no longer working for Rails >v8.1.
|
|
7
|
+
|
|
8
|
+
### ✨ Features
|
|
9
|
+
|
|
10
|
+
- 🗒️ Paginatable: unpaginated
|
|
11
|
+
Override any setting for pagination:
|
|
12
|
+
```ruby
|
|
13
|
+
query = ArticlesQuery.build
|
|
14
|
+
=> #<RecentQuery:0x000000016ed7ef78 @page=1, @per_page=10, ...>
|
|
15
|
+
query.unpaginated.count
|
|
16
|
+
#=> 699
|
|
17
|
+
```
|
|
18
|
+
Also: when `@page.nil?` then paginate erb-helper renders nothing:
|
|
19
|
+
```ruby
|
|
20
|
+
# articles_query.erb.sql
|
|
21
|
+
# before
|
|
22
|
+
# skip pagination when we need the total count
|
|
23
|
+
<%= @page && paginate(page:, per_page:) -%>
|
|
24
|
+
# after
|
|
25
|
+
<%= paginate(page:, per_page:) -%>
|
|
26
|
+
```
|
|
27
|
+
- 🌗 darkmode for API docs
|
|
28
|
+
|
|
3
29
|
### 🐛 Fixes
|
|
4
30
|
|
|
5
31
|
- 🔧 Fix literal strings containing parentheses breaking CTE-parsing.
|
data/lib/app_query/base_query.rb
CHANGED
|
@@ -64,14 +64,17 @@ module AppQuery
|
|
|
64
64
|
# @example SQL template (app/queries/articles.sql.erb)
|
|
65
65
|
# SELECT * FROM articles
|
|
66
66
|
# WHERE author_id = :author_id
|
|
67
|
-
# <% if @
|
|
67
|
+
# <% if @editor %>AND status = :status<% end %>
|
|
68
68
|
# ORDER BY <%= @order_by %>
|
|
69
69
|
#
|
|
70
70
|
# @example Query class (app/queries/articles_query.rb)
|
|
71
71
|
# class ArticlesQuery < AppQuery::BaseQuery
|
|
72
72
|
# bind :author_id
|
|
73
73
|
# bind :status, default: nil
|
|
74
|
+
#
|
|
75
|
+
# var :editor, default: false
|
|
74
76
|
# var :order_by, default: "created_at DESC"
|
|
77
|
+
#
|
|
75
78
|
# cast published_at: :datetime
|
|
76
79
|
# end
|
|
77
80
|
#
|
|
@@ -125,6 +125,12 @@ module AppQuery
|
|
|
125
125
|
self
|
|
126
126
|
end
|
|
127
127
|
|
|
128
|
+
def unpaginated
|
|
129
|
+
@page = nil
|
|
130
|
+
@per_page = nil
|
|
131
|
+
self
|
|
132
|
+
end
|
|
133
|
+
|
|
128
134
|
def entries
|
|
129
135
|
@_entries ||= build_paginated_result(super)
|
|
130
136
|
end
|
|
@@ -135,7 +141,7 @@ module AppQuery
|
|
|
135
141
|
|
|
136
142
|
def unpaginated_query
|
|
137
143
|
base_query
|
|
138
|
-
.render(**render_vars
|
|
144
|
+
.render(**render_vars, page: nil)
|
|
139
145
|
.with_binds(**bind_vars)
|
|
140
146
|
end
|
|
141
147
|
|
|
@@ -214,6 +214,7 @@ module AppQuery
|
|
|
214
214
|
#
|
|
215
215
|
# @raise [ArgumentError] if page or per_page is not a positive integer
|
|
216
216
|
def paginate(page:, per_page:)
|
|
217
|
+
return "" if page.nil?
|
|
217
218
|
raise ArgumentError, "page must be a positive integer (got #{page.inspect})" unless page.is_a?(Integer) && page > 0
|
|
218
219
|
raise ArgumentError, "per_page must be a positive integer (got #{per_page.inspect})" unless per_page.is_a?(Integer) && per_page > 0
|
|
219
220
|
|
data/lib/app_query/tokenizer.rb
CHANGED
data/lib/app_query/version.rb
CHANGED
data/lib/app_query.rb
CHANGED
|
@@ -772,8 +772,9 @@ module AppQuery
|
|
|
772
772
|
# Replace :_ with the current CTE name
|
|
773
773
|
processed_sql = sql.gsub(/:_\b/, current_cte)
|
|
774
774
|
|
|
775
|
-
# Wrap current SELECT in numbered CTE
|
|
776
|
-
|
|
775
|
+
# Wrap current SELECT in numbered CTE (indent all lines, strip trailing whitespace)
|
|
776
|
+
indented_select = select.rstrip.gsub("\n", "\n ")
|
|
777
|
+
new_cte = "#{current_cte} AS (\n #{indented_select}\n)"
|
|
777
778
|
|
|
778
779
|
append_cte(new_cte).then do |q|
|
|
779
780
|
# Replace the SELECT token with processed_sql and increment depth
|
|
@@ -963,5 +964,3 @@ rescue LoadError
|
|
|
963
964
|
end
|
|
964
965
|
|
|
965
966
|
require_relative "app_query/rspec" if Object.const_defined? :RSpec
|
|
966
|
-
|
|
967
|
-
require "app_query/base" if defined?(ActiveRecord::Base)
|