taql 0.2.3 → 0.2.5
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 +12 -1
- data/README.md +13 -7
- data/lib/taql/cli.rb +13 -3
- data/lib/taql/table.rb +28 -19
- data/lib/taql/version.rb +1 -1
- data/lib/taql.rb +3 -3
- data/taql.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15ee79ff7f0dca8d5b599ca3ae84c95793acdfa1e8a46d66ac0fd57acbe98298
|
4
|
+
data.tar.gz: 926398c4f0c84677638bbc15602336efbd0b5d56a96c74c5964bd51ddb750187
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 438695540cf0922a1b95138a1eaee8d98a0e618f895915b935420353759279305327f88c513a366edb5d0df29dfbdb3bbb46a527c1f78dfee74f43091bf21bba
|
7
|
+
data.tar.gz: a60d55360eafafdc8f2ecdcded369c1287cc92cd032871af1ceb251162807631148b4ab4800c80d3c25a3f0a4fbf4cdf59e7f762614f716632e28a3037d73844
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## [
|
3
|
+
## [0.2.5] - 2025-05-17
|
4
|
+
|
5
|
+
- Added support for Markdown
|
6
|
+
- Inject connection
|
7
|
+
- Add irb to Gemfile
|
8
|
+
- Update README
|
9
|
+
|
10
|
+
## [0.2.4] - 2025-04-17
|
11
|
+
|
12
|
+
- Add back missing alias
|
13
|
+
- Add back support for older rubies
|
14
|
+
- Map with index
|
4
15
|
|
5
16
|
## [0.2.3] - 2025-04-17
|
6
17
|
|
data/README.md
CHANGED
@@ -27,19 +27,21 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
27
27
|
+----+----------------------+-----------+----------------------+
|
28
28
|
```
|
29
29
|
|
30
|
+
Use the `--markdown` (or `-m`) flag to generate Markdown output:
|
31
|
+
|
30
32
|
```sh
|
31
|
-
~/Developer/check-in
|
32
|
-
+----+------------+------------+-------------------------+-------------------------+
|
33
|
+
~/Developer/check-in % taql --markdown "select id, first_name, last_name, created_at, updated_at from guests limit 3"
|
33
34
|
| ID | FIRST_NAME | LAST_NAME | CREATED_AT | UPDATED_AT |
|
34
|
-
|
35
|
+
|----|------------|------------|-------------------------|-------------------------|
|
35
36
|
| 1 | Alejandro | Bustamante | 2023-07-26 16:26:21 UTC | 2023-07-26 16:26:21 UTC |
|
36
37
|
| 2 | Reina | Zelaya | 2023-07-26 16:26:21 UTC | 2023-07-26 16:26:21 UTC |
|
37
38
|
| 3 | Carla | Barrios | 2023-07-26 16:26:21 UTC | 2023-07-26 16:26:21 UTC |
|
38
|
-
+----+------------+------------+-------------------------+-------------------------+
|
39
39
|
```
|
40
40
|
|
41
|
+
Any valid SQL SELECT statement can be executed:
|
42
|
+
|
41
43
|
```sh
|
42
|
-
~/Developer/check-in
|
44
|
+
~/Developer/check-in % taql "select count(id) as guest_count from guests"
|
43
45
|
+-------------+
|
44
46
|
| GUEST_COUNT |
|
45
47
|
+-------------+
|
@@ -47,8 +49,10 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
47
49
|
+-------------+
|
48
50
|
```
|
49
51
|
|
52
|
+
Within a console:
|
53
|
+
|
50
54
|
```ruby
|
51
|
-
>> Taql.execute(
|
55
|
+
>> Taql.execute("select id, email from users order by created at limit 3").pluck("email")
|
52
56
|
(1.2ms) select id, email from users limit 3
|
53
57
|
+----+---------------------+
|
54
58
|
| ID | EMAIL |
|
@@ -60,6 +64,8 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
60
64
|
=> ["alice@example.com", "bob@example.com", "charlie@example.com"]
|
61
65
|
```
|
62
66
|
|
67
|
+
The return value is a native PG::Result object, which supports mapping or extracting data as shown in the example above.
|
68
|
+
|
63
69
|
```ruby
|
64
70
|
>> Taql.execute("select * from schema_migrations limit 3")
|
65
71
|
(0.7ms) select * from schema_migrations limit 3
|
@@ -70,7 +76,7 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
70
76
|
| 20240815131806 |
|
71
77
|
| 20240815131747 |
|
72
78
|
+----------------+
|
73
|
-
=>
|
79
|
+
=> \#<PG::Result:0x000000012ebf6a38 status=PGRES_TUPLES_OK ntuples=3 nfields=1 cmd_tuples=3>
|
74
80
|
```
|
75
81
|
|
76
82
|
## Development
|
data/lib/taql/cli.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
|
+
require "optparse"
|
2
|
+
|
1
3
|
module Taql
|
2
4
|
class Cli
|
3
|
-
attr_reader :
|
5
|
+
attr_reader :options, :query
|
4
6
|
|
5
7
|
def initialize(argv)
|
6
|
-
@
|
8
|
+
@options = {markdown: false}
|
9
|
+
@query = parse!
|
7
10
|
end
|
8
11
|
|
9
12
|
def run
|
10
13
|
silence { require environment_path }
|
11
|
-
|
14
|
+
|
15
|
+
Taql.execute(*query, options)
|
12
16
|
end
|
13
17
|
|
14
18
|
private
|
@@ -17,6 +21,12 @@ module Taql
|
|
17
21
|
File.expand_path("config/environment", Dir.pwd)
|
18
22
|
end
|
19
23
|
|
24
|
+
def parse!
|
25
|
+
OptionParser.new do |parser|
|
26
|
+
parser.on("-m", "--markdown", TrueClass, "Output table in Markdown")
|
27
|
+
end.parse!(into: options)
|
28
|
+
end
|
29
|
+
|
20
30
|
def silence
|
21
31
|
original_stdout = $stdout.dup
|
22
32
|
$stdout.reopen(IO::NULL)
|
data/lib/taql/table.rb
CHANGED
@@ -5,8 +5,11 @@ module Taql
|
|
5
5
|
SPACE = " ".freeze
|
6
6
|
VERTICAL_BAR = "|".freeze
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
attr_accessor :markdown
|
9
|
+
|
10
|
+
def initialize(entries, markdown: false)
|
11
|
+
@entries = entries.map { |entry| entry.transform_values(&:to_s) }
|
12
|
+
@markdown = markdown
|
10
13
|
end
|
11
14
|
|
12
15
|
def body
|
@@ -35,38 +38,44 @@ module Taql
|
|
35
38
|
|
36
39
|
attr_reader :entries
|
37
40
|
|
41
|
+
def border
|
42
|
+
separator unless markdown
|
43
|
+
end
|
44
|
+
|
38
45
|
def column_widths
|
39
|
-
columns.map {
|
46
|
+
columns.map { |column| column.map(&:length).max }
|
47
|
+
end
|
48
|
+
|
49
|
+
def edge
|
50
|
+
markdown ? VERTICAL_BAR : PLUS
|
40
51
|
end
|
41
52
|
|
42
53
|
def formatted(segments)
|
43
|
-
segments.map do |segment|
|
44
|
-
|
45
|
-
max_length = column_widths[cell_index]
|
46
|
-
[SPACE, segment.ljust(max_length), SPACE].join
|
54
|
+
segments.map.with_index do |segment, index|
|
55
|
+
[SPACE, segment.ljust(column_widths[index]), SPACE].join
|
47
56
|
end.then do |segments|
|
48
57
|
[VERTICAL_BAR, segments.join(VERTICAL_BAR), VERTICAL_BAR].join
|
49
58
|
end
|
50
59
|
end
|
51
60
|
|
52
61
|
def output
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
62
|
+
[
|
63
|
+
border,
|
64
|
+
formatted(headers.map(&:upcase)),
|
65
|
+
separator,
|
66
|
+
body.map(&method(:formatted)).join("\n"),
|
67
|
+
border
|
68
|
+
].compact.join("\n")
|
60
69
|
end
|
61
70
|
|
62
71
|
def separator
|
63
|
-
columns.map do |column|
|
64
|
-
|
65
|
-
max_length = column_widths[column_index]
|
66
|
-
Array.new(max_length + 2, DASH).join
|
72
|
+
columns.map.with_index do |column, index|
|
73
|
+
Array.new(column_widths[index] + 2, DASH).join
|
67
74
|
end.then do |columns|
|
68
|
-
[
|
75
|
+
[edge, columns.join(edge), edge].join
|
69
76
|
end
|
70
77
|
end
|
78
|
+
|
79
|
+
alias_method :to_s, :print
|
71
80
|
end
|
72
81
|
end
|
data/lib/taql/version.rb
CHANGED
data/lib/taql.rb
CHANGED
@@ -5,10 +5,10 @@ require_relative "taql/version"
|
|
5
5
|
module Taql
|
6
6
|
class Error < StandardError; end
|
7
7
|
|
8
|
-
def self.execute(query)
|
9
|
-
|
8
|
+
def self.execute(query, options, connection: ActiveRecord::Base.connection)
|
9
|
+
connection.execute(query).tap do |result|
|
10
10
|
if (results = result.entries).any?
|
11
|
-
$stdout.puts Table.new(results)
|
11
|
+
$stdout.puts Table.new(results, markdown: options[:markdown])
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
data/taql.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.description = "Taql allows you to pretty print SQL table queries in Rails."
|
11
11
|
spec.homepage = "https://github.com/arzezak/taql"
|
12
12
|
spec.license = "MIT"
|
13
|
-
spec.required_ruby_version = ">= 3.
|
13
|
+
spec.required_ruby_version = ">= 3.0.0"
|
14
14
|
|
15
15
|
spec.metadata["homepage_uri"] = spec.homepage
|
16
16
|
spec.metadata["source_code_uri"] = spec.homepage
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: taql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ariel Rzezak
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
12
|
description: Taql allows you to pretty print SQL table queries in Rails.
|
13
13
|
email:
|
@@ -44,14 +44,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 3.0.0
|
48
48
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
49
|
requirements:
|
50
50
|
- - ">="
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '0'
|
53
53
|
requirements: []
|
54
|
-
rubygems_version: 3.6.
|
54
|
+
rubygems_version: 3.6.7
|
55
55
|
specification_version: 4
|
56
56
|
summary: Tableize Rails SQL queries
|
57
57
|
test_files: []
|