taql 0.4.0 → 0.5.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: a347baf32a9b92dccb94907b40b42d35d00a5f8929f5938842e774d0dfe810a6
4
+ data.tar.gz: 261b1878bc277f27c9d803a675f7ccc085c71eea9639bcdcdd8e6d44b28d5c82
5
5
  SHA512:
6
- metadata.gz: 8e727a99f3b2a96de285341d35f84e86b0c19ff3d51393dd2446625542e10ceb2d7b217cf194404425b5581cb2c8981011c4c27318d9b6cf9307d3cd706c62f4
7
- data.tar.gz: 623ccfa2db3c57ebd3030a5936a1db9ae1bee76718e2afe7ef9cf5391e4032b62499cc176a4c8599531434da07fa6f620d5792fcfc6eb037e98998274595ffa0
6
+ metadata.gz: f0aa1e50f2e9adfcc0013fe53d2a16d44f1b67cb3204c14f86cdff0c30a6e5b213eb5710c1573aa8be0cc1080f057b77e050882b762d23fb1f86b6f5f8e14cdb
7
+ data.tar.gz: 817431a4c417af5c022fc893e0e40b5c8501f0e1470f64e5049b0a916cf20c448d574b48e62562c5e4f2b15bf150724c8ad5aa0f72cc404c6cfd928bcc64c87b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.5.0] - 2026-03-11
4
+
5
+ - Auto-switch to vertical list layout when table exceeds terminal width
6
+ - Add List class for vertical output formatting
7
+ - Right-align headers in vertical list output
8
+
3
9
  ## [0.4.0] - 2026-03-11
4
10
 
5
11
  - 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/list.rb ADDED
@@ -0,0 +1,49 @@
1
+ module Taql
2
+ class List
3
+ DASH = "-".freeze
4
+ PIPE = " | ".freeze
5
+
6
+ def initialize(entries, terminal_width: nil)
7
+ @entries = entries.map { |entry| entry.transform_values(&:to_s) }
8
+ @terminal_width = terminal_width
9
+ end
10
+
11
+ def print
12
+ output if entries.any?
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :entries
18
+
19
+ def headers
20
+ @headers ||= entries.flat_map(&:keys).uniq
21
+ end
22
+
23
+ def max_header_width
24
+ @max_header_width ||= headers.map(&:length).max
25
+ end
26
+
27
+ def divider_width
28
+ @terminal_width&.finite? ? @terminal_width : 32
29
+ end
30
+
31
+ def output
32
+ records = entries.map { |entry| [separator, *rows(entry)].join("\n") }
33
+
34
+ [*records, separator].join("\n")
35
+ end
36
+
37
+ def separator
38
+ DASH * divider_width
39
+ end
40
+
41
+ def rows(entry)
42
+ headers.map do |header|
43
+ "#{header.upcase.rjust(max_header_width)}#{PIPE}#{entry[header]}"
44
+ end
45
+ end
46
+
47
+ alias_method :to_s, :print
48
+ end
49
+ end
data/lib/taql/railtie.rb CHANGED
@@ -6,7 +6,7 @@ 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 = method(:connection)
10
10
  end
11
11
  end
12
12
 
data/lib/taql/table.rb CHANGED
@@ -12,6 +12,10 @@ module Taql
12
12
  @markdown = markdown
13
13
  end
14
14
 
15
+ def table_width
16
+ column_widths.sum + (3 * columns.count) + 1
17
+ end
18
+
15
19
  def body
16
20
  entries.map(&:values)
17
21
  end
data/lib/taql/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Taql
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/taql.rb CHANGED
@@ -1,20 +1,37 @@
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
 
16
20
  private
17
21
 
22
+ def formatter(results, markdown: false)
23
+ table = Table.new(results, markdown: markdown)
24
+ if !markdown && table.table_width > terminal_width
25
+ List.new(results, terminal_width: terminal_width)
26
+ else
27
+ table
28
+ end
29
+ end
30
+
31
+ def terminal_width
32
+ IO.console&.winsize&.last || Float::INFINITY
33
+ end
34
+
18
35
  def default_connection
19
36
  @default_connection&.call || raise("Taql not properly initialized with Rails")
20
37
  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.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ariel Rzezak
@@ -29,6 +29,7 @@ files:
29
29
  - exe/taql
30
30
  - lib/taql.rb
31
31
  - lib/taql/cli.rb
32
+ - lib/taql/list.rb
32
33
  - lib/taql/railtie.rb
33
34
  - lib/taql/table.rb
34
35
  - lib/taql/version.rb