taql 0.3.7 → 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 +4 -4
- data/CHANGELOG.md +16 -0
- data/CLAUDE.md +34 -0
- data/README.md +25 -3
- data/RELEASING.md +7 -0
- data/lib/taql/cli.rb +7 -2
- data/lib/taql/list.rb +49 -0
- data/lib/taql/railtie.rb +9 -1
- data/lib/taql/table.rb +7 -3
- data/lib/taql/version.rb +1 -1
- data/lib/taql.rb +18 -1
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a347baf32a9b92dccb94907b40b42d35d00a5f8929f5938842e774d0dfe810a6
|
|
4
|
+
data.tar.gz: 261b1878bc277f27c9d803a675f7ccc085c71eea9639bcdcdd8e6d44b28d5c82
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f0aa1e50f2e9adfcc0013fe53d2a16d44f1b67cb3204c14f86cdff0c30a6e5b213eb5710c1573aa8be0cc1080f057b77e050882b762d23fb1f86b6f5f8e14cdb
|
|
7
|
+
data.tar.gz: 817431a4c417af5c022fc893e0e40b5c8501f0e1470f64e5049b0a916cf20c448d574b48e62562c5e4f2b15bf150724c8ad5aa0f72cc404c6cfd928bcc64c87b
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
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
|
+
|
|
9
|
+
## [0.4.0] - 2026-03-11
|
|
10
|
+
|
|
11
|
+
- Fix CLI to use passed argv instead of global ARGV
|
|
12
|
+
- Fix CLI to use ActiveRecord connection directly after booting Rails
|
|
13
|
+
- Memoize Table headers, columns, and column_widths
|
|
14
|
+
- Fix headers deduplication for heterogeneous entries
|
|
15
|
+
- Raise error when CLI is invoked without a query
|
|
16
|
+
- Add --version flag to CLI
|
|
17
|
+
- Support Rails 7.2+ lease_connection
|
|
18
|
+
|
|
3
19
|
## [0.3.7] - 2025-09-01
|
|
4
20
|
|
|
5
21
|
- Add Railtie
|
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## About
|
|
6
|
+
|
|
7
|
+
Taql is a Ruby gem that formats SQL query results into pretty-printed tables (ASCII or Markdown). Provides both a CLI (`taql "SELECT ..."`) and programmatic API (`Taql.execute(query)`) for use with Rails/ActiveRecord.
|
|
8
|
+
|
|
9
|
+
## Commands
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
bundle exec rake # Run tests + lint (default)
|
|
13
|
+
rake test # Run all tests (minitest)
|
|
14
|
+
rake test TEST=test/test_table.rb # Single test file
|
|
15
|
+
rake test TEST=test/test_table.rb TESTOPTS="--name=test_something" # Single test method
|
|
16
|
+
rake standard # Lint (Standard Ruby)
|
|
17
|
+
rake standard:fix # Auto-fix lint issues
|
|
18
|
+
bin/setup # Install dependencies
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Architecture
|
|
22
|
+
|
|
23
|
+
- `lib/taql.rb` — Main module; `.execute(query, options, connection:)` entry point
|
|
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
|
|
26
|
+
- `lib/taql/cli.rb` — CLI parser (`--markdown/-m` flag); loads Rails env, calls `Taql.execute`
|
|
27
|
+
- `lib/taql/railtie.rb` — Rails integration; sets `@default_connection` from ActiveRecord pool
|
|
28
|
+
- `exe/taql` — CLI executable entry point
|
|
29
|
+
|
|
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.
|
|
31
|
+
|
|
32
|
+
## Testing
|
|
33
|
+
|
|
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
|
|
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/
|
|
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/
|
|
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/RELEASING.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Releasing
|
|
2
|
+
|
|
3
|
+
1. Update version in `lib/taql/version.rb`
|
|
4
|
+
2. Run `bundle install` to update lockfile
|
|
5
|
+
3. Update `CHANGELOG.md` with new version and changes
|
|
6
|
+
4. Commit: `git commit -am "Release vX.Y.Z"`
|
|
7
|
+
5. Run `bundle exec rake release` (builds gem, creates git tag, pushes to RubyGems)
|
data/lib/taql/cli.rb
CHANGED
|
@@ -5,14 +5,17 @@ module Taql
|
|
|
5
5
|
attr_reader :options, :query
|
|
6
6
|
|
|
7
7
|
def initialize(argv)
|
|
8
|
+
@argv = argv
|
|
8
9
|
@options = {markdown: false}
|
|
9
10
|
@query = parse!
|
|
11
|
+
|
|
12
|
+
raise ArgumentError, "Usage: taql [--markdown] QUERY" if @query.empty?
|
|
10
13
|
end
|
|
11
14
|
|
|
12
15
|
def run
|
|
13
16
|
silence { require environment_path }
|
|
14
17
|
|
|
15
|
-
Taql.execute(*query, options)
|
|
18
|
+
Taql.execute(*query, options, connection: ActiveRecord::Base.connection)
|
|
16
19
|
end
|
|
17
20
|
|
|
18
21
|
private
|
|
@@ -24,7 +27,9 @@ module Taql
|
|
|
24
27
|
def parse!
|
|
25
28
|
OptionParser.new do |parser|
|
|
26
29
|
parser.on("-m", "--markdown", TrueClass, "Output table in Markdown")
|
|
27
|
-
|
|
30
|
+
parser.program_name = "taql"
|
|
31
|
+
parser.version = Taql::VERSION
|
|
32
|
+
end.parse!(@argv, into: options)
|
|
28
33
|
end
|
|
29
34
|
|
|
30
35
|
def silence
|
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,8 +6,16 @@ module Taql
|
|
|
6
6
|
|
|
7
7
|
initializer "taql.initialize" do
|
|
8
8
|
ActiveSupport.on_load(:active_record) do
|
|
9
|
-
Taql.
|
|
9
|
+
Taql.default_connection = method(: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
|
|
12
20
|
end
|
|
13
21
|
end
|
data/lib/taql/table.rb
CHANGED
|
@@ -12,18 +12,22 @@ 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
|
|
18
22
|
|
|
19
23
|
def columns
|
|
20
|
-
headers.map do |header|
|
|
24
|
+
@columns ||= headers.map do |header|
|
|
21
25
|
[header, *entries.map { |entry| entry[header] }]
|
|
22
26
|
end
|
|
23
27
|
end
|
|
24
28
|
|
|
25
29
|
def headers
|
|
26
|
-
entries.
|
|
30
|
+
@headers ||= entries.flat_map(&:keys).uniq
|
|
27
31
|
end
|
|
28
32
|
|
|
29
33
|
def print
|
|
@@ -43,7 +47,7 @@ module Taql
|
|
|
43
47
|
end
|
|
44
48
|
|
|
45
49
|
def column_widths
|
|
46
|
-
columns.map { |column| column.map(&:length).max }
|
|
50
|
+
@column_widths ||= columns.map { |column| column.map(&:length).max }
|
|
47
51
|
end
|
|
48
52
|
|
|
49
53
|
def edge
|
data/lib/taql/version.rb
CHANGED
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
|
|
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
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ariel Rzezak
|
|
@@ -18,15 +18,18 @@ extensions: []
|
|
|
18
18
|
extra_rdoc_files: []
|
|
19
19
|
files:
|
|
20
20
|
- CHANGELOG.md
|
|
21
|
+
- CLAUDE.md
|
|
21
22
|
- CODE_OF_CONDUCT.md
|
|
22
23
|
- LICENSE.txt
|
|
23
24
|
- README.md
|
|
25
|
+
- RELEASING.md
|
|
24
26
|
- Rakefile
|
|
25
27
|
- bin/console
|
|
26
28
|
- bin/setup
|
|
27
29
|
- exe/taql
|
|
28
30
|
- lib/taql.rb
|
|
29
31
|
- lib/taql/cli.rb
|
|
32
|
+
- lib/taql/list.rb
|
|
30
33
|
- lib/taql/railtie.rb
|
|
31
34
|
- lib/taql/table.rb
|
|
32
35
|
- lib/taql/version.rb
|
|
@@ -52,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
52
55
|
- !ruby/object:Gem::Version
|
|
53
56
|
version: '0'
|
|
54
57
|
requirements: []
|
|
55
|
-
rubygems_version:
|
|
58
|
+
rubygems_version: 4.0.3
|
|
56
59
|
specification_version: 4
|
|
57
60
|
summary: Tableize Rails SQL queries
|
|
58
61
|
test_files: []
|