taql 0.4.0 → 0.6.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: 421c44be6a4f2b1d3e932bd05739e9610c75e4881a6528def4195c3f5e92373a
4
- data.tar.gz: 313728eefa6a8d1ac1ffba66ffedd4c9d3dca64837a9442f7e7af05d1f3a8ef4
3
+ metadata.gz: 06cf2ffe64ba72577b6e68ca71d276a1470bba0660521d0df02e9aaff5722112
4
+ data.tar.gz: 452c4e96ea43fa3df92ee786d1b81116162c8ca97f067306e29cdfe44e98a6ab
5
5
  SHA512:
6
- metadata.gz: 8e727a99f3b2a96de285341d35f84e86b0c19ff3d51393dd2446625542e10ceb2d7b217cf194404425b5581cb2c8981011c4c27318d9b6cf9307d3cd706c62f4
7
- data.tar.gz: 623ccfa2db3c57ebd3030a5936a1db9ae1bee76718e2afe7ef9cf5391e4032b62499cc176a4c8599531434da07fa6f620d5792fcfc6eb037e98998274595ffa0
6
+ metadata.gz: a9e418d460768051aefecb0445a4ae6233184099aed19f5295e9c709e755b0d02233136d0bdfdb514b8a397d8d0219ec4395ed0c6c65b13c85f33e556821eb61
7
+ data.tar.gz: 825def129c7a925b42b1656b10825928d6006ceb6be82e912cc40b34d594bf13316a0a9d0d80257ebf192f452a77b0db3520842707256635fb7d41763409f946
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.6.0] - 2026-07-18
4
+
5
+ - Extract shared `Formatter` base class from `Table` and `List`
6
+ - Unify ActiveRecord connection handling in `Taql.active_record_connection`
7
+ - Fix CLI to avoid the Rails 7.2+ `connection` deprecation warning
8
+ - Remove unused `Table#rows`, `#columns`, and `markdown` writer
9
+
10
+ ## [0.5.0] - 2026-03-11
11
+
12
+ - Auto-switch to vertical list layout when table exceeds terminal width
13
+ - Add List class for vertical output formatting
14
+ - Right-align headers in vertical list output
15
+
3
16
  ## [0.4.0] - 2026-03-11
4
17
 
5
18
  - Fix CLI to use passed argv instead of global ARGV
data/CLAUDE.md CHANGED
@@ -22,12 +22,13 @@ bin/setup # Install dependencies
22
22
 
23
23
  - `lib/taql.rb` — Main module; `.execute(query, options, connection:)` entry point
24
24
  - `lib/taql/table.rb` — Table formatting (ASCII borders + Markdown mode); handles column width calculation
25
+ - `lib/taql/list.rb` — Vertical list formatting; used when table exceeds terminal width
25
26
  - `lib/taql/cli.rb` — CLI parser (`--markdown/-m` flag); loads Rails env, calls `Taql.execute`
26
27
  - `lib/taql/railtie.rb` — Rails integration; sets `@default_connection` from ActiveRecord pool
27
28
  - `exe/taql` — CLI executable entry point
28
29
 
29
- **Flow:** CLI loads Rails environment → parses args → `Taql.execute` uses ActiveRecord connection (from Railtie or explicit) → wraps result in `Table` → prints formatted output.
30
+ **Flow:** CLI loads Rails environment → parses args → `Taql.execute` uses ActiveRecord connection (from Railtie or explicit) → auto-selects `Table` or `List` based on terminal width → prints formatted output.
30
31
 
31
32
  ## Testing
32
33
 
33
- Tests use Minitest with mocked database connections. Test files mirror lib structure: `test_taql.rb`, `test_table.rb`, `test_cli.rb`. CI runs on Ruby 3.4 via GitHub Actions.
34
+ Tests use Minitest with mocked database connections. Test files mirror lib structure: `test_taql.rb`, `test_table.rb`, `test_list.rb`, `test_cli.rb`. CI runs on Ruby 3.4 via GitHub Actions.
data/README.md CHANGED
@@ -27,6 +27,13 @@ $ gem install taql
27
27
  +----+----------------------+-----------+----------------------+
28
28
  ```
29
29
 
30
+ Use `--version` (or `-v`) to check the installed version:
31
+
32
+ ```sh
33
+ $ taql --version
34
+ taql 0.4.0
35
+ ```
36
+
30
37
  Use the `--markdown` (or `-m`) flag to generate Markdown output:
31
38
 
32
39
  ```sh
@@ -52,7 +59,7 @@ Any valid SQL SELECT statement can be executed:
52
59
  Within a console:
53
60
 
54
61
  ```ruby
55
- >> Taql.execute("select id, email from users order by created at limit 3").pluck("email")
62
+ >> Taql.execute("select id, email from users order by created_at limit 3").pluck("email")
56
63
  (1.2ms) select id, email from users limit 3
57
64
  +----+---------------------+
58
65
  | ID | EMAIL |
@@ -79,6 +86,21 @@ The return value is a native PG::Result object, which supports mapping or extrac
79
86
  => #<PG::Result:0x000000012ebf6a38 status=PGRES_TUPLES_OK ntuples=3 nfields=1 cmd_tuples=3>
80
87
  ```
81
88
 
89
+ When results exceed terminal width, output automatically switches to a vertical list format:
90
+
91
+ ```
92
+ ----------------------------------------
93
+ ID | 1
94
+ ADMIN | false
95
+ EMAIL | alice@example.com
96
+ CREATED_AT | 2021-10-01 00:00:00 UTC
97
+ ----------------------------------------
98
+ ```
99
+
100
+ ## TODO
101
+
102
+ - [ ] `--list` / `--table` CLI flags to override auto-detection
103
+
82
104
  ## Development
83
105
 
84
106
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -91,7 +113,7 @@ To release a new version, update the version number in `version.rb`, and then ru
91
113
 
92
114
  ## Contributing
93
115
 
94
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/taql. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/taql/blob/main/CODE_OF_CONDUCT.md).
116
+ Bug reports and pull requests are welcome on GitHub at https://github.com/arzezak/taql. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/arzezak/taql/blob/main/CODE_OF_CONDUCT.md).
95
117
 
96
118
  ## License
97
119
 
@@ -99,4 +121,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
99
121
 
100
122
  ## Code of Conduct
101
123
 
102
- Everyone interacting in the Taql project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/taql/blob/main/CODE_OF_CONDUCT.md).
124
+ Everyone interacting in the Taql project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/arzezak/taql/blob/main/CODE_OF_CONDUCT.md).
data/lib/taql/cli.rb CHANGED
@@ -15,7 +15,7 @@ module Taql
15
15
  def run
16
16
  silence { require environment_path }
17
17
 
18
- Taql.execute(*query, options, connection: ActiveRecord::Base.connection)
18
+ Taql.execute(*query, options, connection: Taql.active_record_connection)
19
19
  end
20
20
 
21
21
  private
@@ -0,0 +1,23 @@
1
+ module Taql
2
+ class Formatter
3
+ DASH = "-".freeze
4
+
5
+ def initialize(entries)
6
+ @entries = entries.map { |entry| entry.transform_values(&:to_s) }
7
+ end
8
+
9
+ def headers
10
+ @headers ||= entries.flat_map(&:keys).uniq
11
+ end
12
+
13
+ def print
14
+ output if entries.any?
15
+ end
16
+
17
+ alias_method :to_s, :print
18
+
19
+ private
20
+
21
+ attr_reader :entries
22
+ end
23
+ end
data/lib/taql/list.rb ADDED
@@ -0,0 +1,38 @@
1
+ require_relative "formatter"
2
+
3
+ module Taql
4
+ class List < Formatter
5
+ PIPE = " | ".freeze
6
+
7
+ def initialize(entries, terminal_width: nil)
8
+ super(entries)
9
+ @terminal_width = terminal_width
10
+ end
11
+
12
+ private
13
+
14
+ def max_header_width
15
+ @max_header_width ||= headers.map(&:length).max
16
+ end
17
+
18
+ def divider_width
19
+ @terminal_width || 32
20
+ end
21
+
22
+ def output
23
+ records = entries.map { |entry| [separator, *rows(entry)].join("\n") }
24
+
25
+ [*records, separator].join("\n")
26
+ end
27
+
28
+ def separator
29
+ @separator ||= DASH * divider_width
30
+ end
31
+
32
+ def rows(entry)
33
+ headers.map do |header|
34
+ "#{header.upcase.rjust(max_header_width)}#{PIPE}#{entry[header]}"
35
+ end
36
+ end
37
+ end
38
+ end
data/lib/taql/railtie.rb CHANGED
@@ -6,16 +6,8 @@ module Taql
6
6
 
7
7
  initializer "taql.initialize" do
8
8
  ActiveSupport.on_load(:active_record) do
9
- Taql.instance_variable_set(:@default_connection, method(:connection))
9
+ Taql.default_connection = Taql.method(:active_record_connection)
10
10
  end
11
11
  end
12
-
13
- def self.connection
14
- pool.respond_to?(:lease_connection) ? pool.lease_connection : pool.connection
15
- end
16
-
17
- def self.pool
18
- ActiveRecord::Base.connection_pool
19
- end
20
12
  end
21
13
  end
data/lib/taql/table.rb CHANGED
@@ -1,49 +1,36 @@
1
+ require_relative "formatter"
2
+
1
3
  module Taql
2
- class Table
3
- DASH = "-".freeze
4
+ class Table < Formatter
4
5
  PLUS = "+".freeze
5
6
  SPACE = " ".freeze
6
7
  VERTICAL_BAR = "|".freeze
7
8
 
8
- attr_accessor :markdown
9
+ attr_reader :markdown
9
10
 
10
11
  def initialize(entries, markdown: false)
11
- @entries = entries.map { |entry| entry.transform_values(&:to_s) }
12
+ super(entries)
12
13
  @markdown = markdown
13
14
  end
14
15
 
15
- def body
16
- entries.map(&:values)
17
- end
18
-
19
- def columns
20
- @columns ||= headers.map do |header|
21
- [header, *entries.map { |entry| entry[header] }]
22
- end
23
- end
24
-
25
- def headers
26
- @headers ||= entries.flat_map(&:keys).uniq
16
+ def table_width
17
+ column_widths.sum + (3 * headers.count) + 1
27
18
  end
28
19
 
29
- def print
30
- output if entries.any?
31
- end
32
-
33
- def rows
34
- [headers, *body]
20
+ def body
21
+ entries.map(&:values)
35
22
  end
36
23
 
37
24
  private
38
25
 
39
- attr_reader :entries
40
-
41
26
  def border
42
27
  separator unless markdown
43
28
  end
44
29
 
45
30
  def column_widths
46
- @column_widths ||= columns.map { |column| column.map(&:length).max }
31
+ @column_widths ||= headers.map do |header|
32
+ [header, *entries.map { |entry| entry[header] }].map(&:length).max
33
+ end
47
34
  end
48
35
 
49
36
  def edge
@@ -69,13 +56,11 @@ module Taql
69
56
  end
70
57
 
71
58
  def separator
72
- columns.map.with_index do |column, index|
73
- Array.new(column_widths[index] + 2, DASH).join
74
- end.then do |columns|
75
- [edge, columns.join(edge), edge].join
59
+ column_widths.map do |width|
60
+ DASH * (width + 2)
61
+ end.then do |segments|
62
+ [edge, segments.join(edge), edge].join
76
63
  end
77
64
  end
78
-
79
- alias_method :to_s, :print
80
65
  end
81
66
  end
data/lib/taql/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Taql
2
- VERSION = "0.4.0"
2
+ VERSION = "0.6.0"
3
3
  end
data/lib/taql.rb CHANGED
@@ -1,20 +1,44 @@
1
+ require "io/console"
1
2
  require_relative "taql/cli"
3
+ require_relative "taql/list"
2
4
  require_relative "taql/table"
3
5
  require_relative "taql/version"
4
6
  require_relative "taql/railtie" if defined?(Rails)
5
7
 
6
8
  module Taql
7
9
  class << self
10
+ attr_writer :default_connection
11
+
8
12
  def execute(query, options = {}, connection: nil)
9
13
  (connection || default_connection).execute(query).tap do |result|
10
14
  if (results = result.entries).any?
11
- $stdout.puts Table.new(results, markdown: options[:markdown])
15
+ $stdout.puts formatter(results, markdown: options[:markdown])
12
16
  end
13
17
  end
14
18
  end
15
19
 
20
+ def active_record_connection
21
+ pool = ActiveRecord::Base.connection_pool
22
+ pool.respond_to?(:lease_connection) ? pool.lease_connection : pool.connection
23
+ end
24
+
16
25
  private
17
26
 
27
+ def formatter(results, markdown:)
28
+ table = Table.new(results, markdown: markdown)
29
+ width = terminal_width
30
+
31
+ if !markdown && width && table.table_width > width
32
+ List.new(results, terminal_width: width)
33
+ else
34
+ table
35
+ end
36
+ end
37
+
38
+ def terminal_width
39
+ IO.console&.winsize&.last
40
+ end
41
+
18
42
  def default_connection
19
43
  @default_connection&.call || raise("Taql not properly initialized with Rails")
20
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ariel Rzezak
@@ -29,6 +29,8 @@ files:
29
29
  - exe/taql
30
30
  - lib/taql.rb
31
31
  - lib/taql/cli.rb
32
+ - lib/taql/formatter.rb
33
+ - lib/taql/list.rb
32
34
  - lib/taql/railtie.rb
33
35
  - lib/taql/table.rb
34
36
  - lib/taql/version.rb
@@ -54,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
56
  - !ruby/object:Gem::Version
55
57
  version: '0'
56
58
  requirements: []
57
- rubygems_version: 4.0.3
59
+ rubygems_version: 4.0.14
58
60
  specification_version: 4
59
61
  summary: Tableize Rails SQL queries
60
62
  test_files: []