taql 0.2.7 → 0.4.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 +14 -0
- data/CLAUDE.md +33 -0
- data/RELEASING.md +7 -0
- data/lib/taql/cli.rb +7 -2
- data/lib/taql/railtie.rb +21 -0
- data/lib/taql/table.rb +3 -3
- data/lib/taql/version.rb +1 -1
- data/lib/taql.rb +13 -6
- 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: 421c44be6a4f2b1d3e932bd05739e9610c75e4881a6528def4195c3f5e92373a
|
|
4
|
+
data.tar.gz: 313728eefa6a8d1ac1ffba66ffedd4c9d3dca64837a9442f7e7af05d1f3a8ef4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8e727a99f3b2a96de285341d35f84e86b0c19ff3d51393dd2446625542e10ceb2d7b217cf194404425b5581cb2c8981011c4c27318d9b6cf9307d3cd706c62f4
|
|
7
|
+
data.tar.gz: 623ccfa2db3c57ebd3030a5936a1db9ae1bee76718e2afe7ef9cf5391e4032b62499cc176a4c8599531434da07fa6f620d5792fcfc6eb037e98998274595ffa0
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.4.0] - 2026-03-11
|
|
4
|
+
|
|
5
|
+
- Fix CLI to use passed argv instead of global ARGV
|
|
6
|
+
- Fix CLI to use ActiveRecord connection directly after booting Rails
|
|
7
|
+
- Memoize Table headers, columns, and column_widths
|
|
8
|
+
- Fix headers deduplication for heterogeneous entries
|
|
9
|
+
- Raise error when CLI is invoked without a query
|
|
10
|
+
- Add --version flag to CLI
|
|
11
|
+
- Support Rails 7.2+ lease_connection
|
|
12
|
+
|
|
13
|
+
## [0.3.7] - 2025-09-01
|
|
14
|
+
|
|
15
|
+
- Add Railtie
|
|
16
|
+
|
|
3
17
|
## [0.2.7] - 2025-06-27
|
|
4
18
|
|
|
5
19
|
- Provide default options
|
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
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/cli.rb` — CLI parser (`--markdown/-m` flag); loads Rails env, calls `Taql.execute`
|
|
26
|
+
- `lib/taql/railtie.rb` — Rails integration; sets `@default_connection` from ActiveRecord pool
|
|
27
|
+
- `exe/taql` — CLI executable entry point
|
|
28
|
+
|
|
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
|
+
|
|
31
|
+
## Testing
|
|
32
|
+
|
|
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.
|
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/railtie.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require "rails/railtie"
|
|
2
|
+
|
|
3
|
+
module Taql
|
|
4
|
+
class Railtie < Rails::Railtie
|
|
5
|
+
railtie_name :taql
|
|
6
|
+
|
|
7
|
+
initializer "taql.initialize" do
|
|
8
|
+
ActiveSupport.on_load(:active_record) do
|
|
9
|
+
Taql.instance_variable_set(:@default_connection, method(:connection))
|
|
10
|
+
end
|
|
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
|
+
end
|
|
21
|
+
end
|
data/lib/taql/table.rb
CHANGED
|
@@ -17,13 +17,13 @@ module Taql
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def columns
|
|
20
|
-
headers.map do |header|
|
|
20
|
+
@columns ||= headers.map do |header|
|
|
21
21
|
[header, *entries.map { |entry| entry[header] }]
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def headers
|
|
26
|
-
entries.
|
|
26
|
+
@headers ||= entries.flat_map(&:keys).uniq
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def print
|
|
@@ -43,7 +43,7 @@ module Taql
|
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
def column_widths
|
|
46
|
-
columns.map { |column| column.map(&:length).max }
|
|
46
|
+
@column_widths ||= columns.map { |column| column.map(&:length).max }
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
def edge
|
data/lib/taql/version.rb
CHANGED
data/lib/taql.rb
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
require_relative "taql/cli"
|
|
2
2
|
require_relative "taql/table"
|
|
3
3
|
require_relative "taql/version"
|
|
4
|
+
require_relative "taql/railtie" if defined?(Rails)
|
|
4
5
|
|
|
5
6
|
module Taql
|
|
6
|
-
class
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
class << self
|
|
8
|
+
def execute(query, options = {}, connection: nil)
|
|
9
|
+
(connection || default_connection).execute(query).tap do |result|
|
|
10
|
+
if (results = result.entries).any?
|
|
11
|
+
$stdout.puts Table.new(results, markdown: options[:markdown])
|
|
12
|
+
end
|
|
12
13
|
end
|
|
13
14
|
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def default_connection
|
|
19
|
+
@default_connection&.call || raise("Taql not properly initialized with Rails")
|
|
20
|
+
end
|
|
14
21
|
end
|
|
15
22
|
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.4.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/railtie.rb
|
|
30
33
|
- lib/taql/table.rb
|
|
31
34
|
- lib/taql/version.rb
|
|
32
35
|
- taql.gemspec
|
|
@@ -51,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
51
54
|
- !ruby/object:Gem::Version
|
|
52
55
|
version: '0'
|
|
53
56
|
requirements: []
|
|
54
|
-
rubygems_version:
|
|
57
|
+
rubygems_version: 4.0.3
|
|
55
58
|
specification_version: 4
|
|
56
59
|
summary: Tableize Rails SQL queries
|
|
57
60
|
test_files: []
|