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 +4 -4
- data/CHANGELOG.md +6 -0
- data/CLAUDE.md +3 -2
- data/README.md +25 -3
- data/lib/taql/list.rb +49 -0
- data/lib/taql/railtie.rb +1 -1
- data/lib/taql/table.rb +4 -0
- data/lib/taql/version.rb +1 -1
- data/lib/taql.rb +18 -1
- metadata +2 -1
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,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) →
|
|
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
|
|
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/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
data/lib/taql/table.rb
CHANGED
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
|
|
@@ -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
|