appquery 0.7.0.rc5 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f0a7427b588822074b0d97fa98f7008bd4a66a9630619e425421341ad5d74b2d
4
- data.tar.gz: bfc1eead06bc7f5c8044694adb349260bab5ce8b0f11d8918fa1e068b736a2ac
3
+ metadata.gz: f5eeb81f992ea777b44680277fcf8ef0d763aa1e8d4d6b1750eb81f9198d5262
4
+ data.tar.gz: d9939585c40818303e0da886c459ad65c030b2501f8399942cf5b0b2a6d308ab
5
5
  SHA512:
6
- metadata.gz: 9fd7aad6bcc1ec6a05f2fa2bdcebfd2c23b46d48ab9faa3b166651c2d680da82cb4ebee3faa8fcc7d20690777e2342943bbb01180eefab0bcf75ae7ca820745e
7
- data.tar.gz: c3d0cfb70e26b846dadc3b0dc89b1cbdaa6aa5d9de7a5b06cdee583ccd9fb7fd517aa128a8dda341eed92f3e615f501986b06b778c71642810aae485bcc5ed10
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.
@@ -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 @status %>AND status = :status<% end %>
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.except(:page, :per_page))
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
 
@@ -104,7 +104,7 @@ module AppQuery
104
104
 
105
105
  def lex_append_cte
106
106
  emit_token "COMMA", v: ","
107
- emit_token "WHITESPACE", v: "\n "
107
+ emit_token "WHITESPACE", v: "\n"
108
108
  push_return :lex_recursive_cte
109
109
  end
110
110
 
@@ -3,5 +3,5 @@
3
3
  module AppQuery
4
4
  # This should just contain the .dev of the upcoming version.
5
5
  # When doing the actual release, CI will write the tag here before pushing the gem.
6
- VERSION = "0.7.0.rc5"
6
+ VERSION = "0.7.0"
7
7
  end
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
- new_cte = "#{current_cte} AS (\n #{select}\n)"
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appquery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0.rc5
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gert Goet
@@ -56,7 +56,6 @@ files:
56
56
  - assets/banner-dark.svg
57
57
  - assets/banner-light.svg
58
58
  - lib/app_query.rb
59
- - lib/app_query/base.rb
60
59
  - lib/app_query/base_query.rb
61
60
  - lib/app_query/mappable.rb
62
61
  - lib/app_query/paginatable.rb
@@ -1,45 +0,0 @@
1
- module AppQuery
2
- class Base
3
- class_attribute :_cast, default: true, instance_predicate: false
4
- class_attribute :_default_binds, default: {}, instance_predicate: false
5
-
6
- class << self
7
- def run(build_only: false, binds: {}, vars: {}, cast: self.cast, select: nil, **)
8
- _build(binds:, vars:, cast:, select:).then do
9
- build_only ? _1 : _1.select_all
10
- end
11
- end
12
-
13
- def build(**opts)
14
- run(build_only: true, **opts)
15
- end
16
-
17
- def default_binds(v = nil)
18
- return _default_binds if v.nil?
19
- self._default_binds = v
20
- end
21
-
22
- def cast(v = nil)
23
- return _cast if v.nil?
24
- self._cast = v
25
- end
26
-
27
- def query_name
28
- derive_query_name unless defined?(@query_name)
29
- @query_name
30
- end
31
-
32
- attr_writer :query_name
33
-
34
- private
35
-
36
- def _build(cast:, binds: {}, select: nil, vars: {})
37
- AppQuery[query_name, binds:, cast:].render(vars).with_select(select)
38
- end
39
-
40
- def derive_query_name
41
- self.query_name = name.underscore.sub(/_query$/, "")
42
- end
43
- end
44
- end
45
- end