taql 0.2.4 → 0.2.6

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: f24bc719d96fb2e39e7c563bff21d9faa0b571570fcc1c76014636f4e7ebd05a
4
- data.tar.gz: 62abbf13a4fef7e0ab96324833e4a8f505c0e27103e95ddabcdcc3f23f3c2ee8
3
+ metadata.gz: 51560820483201d09e0deeeb279062896454dd4e74796461e6513800ef39a1a5
4
+ data.tar.gz: a6bb0f39c93942d1fd4be527ecb9c59fffced9a5aa8ab490a4a340009d418388
5
5
  SHA512:
6
- metadata.gz: b36295a5bcb1d37eb1c2c129447d13776ae6119b02bdefe22619da59176835e7dcfae8381abda207bffbf239da871c5790662b32085fb7135f5b913458d80ada
7
- data.tar.gz: dd9a2b409e6f9bd4fbf8fa974dee215da841828f6c3fe4dccfe6ec9df04232e9efe3344b670b4c6fb3732d63929d614eba67d34cef8235833d1943f45f7087f5
6
+ metadata.gz: f9fa6aa118887bf1302c65b12623e4becdb30aa3a1c0a7d4239f768591b8bc937a1d8ad0604f8c2b0b856bd9452fc45aae7bd970320228288a56c7b81a9e5f9b
7
+ data.tar.gz: 87aff05a7d6b00528811490d27699ce15c3ad4770a582a716e0c9904958f4bbd376228a6e507c40aae48edc05f2c25c106cb548633ae924785a321244218c04c
data/CHANGELOG.md CHANGED
@@ -1,6 +1,15 @@
1
1
  # Changelog
2
2
 
3
- ## [Unreleased]
3
+ ## [0.2.6] - 2025-05-17
4
+
5
+ - Fix version
6
+
7
+ ## [0.2.5] - 2025-05-17
8
+
9
+ - Added support for Markdown
10
+ - Inject connection
11
+ - Add irb to Gemfile
12
+ - Update README
4
13
 
5
14
  ## [0.2.4] - 2025-04-17
6
15
 
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 (main) % taql "select id, first_name, last_name, created_at, updated_at from guests limit 3"
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 (main|!|+) % taql "select count(id) as guest_count from guests"
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('select id, email from users order by created at limit 3').pluck("email")
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
- => #<PG::Result:0x000000012ebf6a38 status=PGRES_TUPLES_OK ntuples=3 nfields=1 cmd_tuples=3>
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 :argv
5
+ attr_reader :options, :query
4
6
 
5
7
  def initialize(argv)
6
- @argv = argv
8
+ @options = {markdown: false}
9
+ @query = parse!
7
10
  end
8
11
 
9
12
  def run
10
13
  silence { require environment_path }
11
- Taql.execute(*argv)
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
- def initialize(entries)
8
+ attr_accessor :markdown
9
+
10
+ def initialize(entries, markdown: false)
9
11
  @entries = entries.map { |entry| entry.transform_values(&:to_s) }
12
+ @markdown = markdown
10
13
  end
11
14
 
12
15
  def body
@@ -35,10 +38,18 @@ 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
46
  columns.map { |column| column.map(&:length).max }
40
47
  end
41
48
 
49
+ def edge
50
+ markdown ? VERTICAL_BAR : PLUS
51
+ end
52
+
42
53
  def formatted(segments)
43
54
  segments.map.with_index do |segment, index|
44
55
  [SPACE, segment.ljust(column_widths[index]), SPACE].join
@@ -48,20 +59,20 @@ module Taql
48
59
  end
49
60
 
50
61
  def output
51
- <<~OUTPUT
52
- #{separator}
53
- #{formatted(headers.map(&:upcase))}
54
- #{separator}
55
- #{body.map(&method(:formatted)).join("\n")}
56
- #{separator}
57
- OUTPUT
62
+ [
63
+ border,
64
+ formatted(headers.map(&:upcase)),
65
+ separator,
66
+ body.map(&method(:formatted)).join("\n"),
67
+ border
68
+ ].compact.join("\n")
58
69
  end
59
70
 
60
71
  def separator
61
72
  columns.map.with_index do |column, index|
62
73
  Array.new(column_widths[index] + 2, DASH).join
63
74
  end.then do |columns|
64
- [PLUS, columns.join(PLUS), PLUS].join
75
+ [edge, columns.join(edge), edge].join
65
76
  end
66
77
  end
67
78
 
data/lib/taql/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Taql
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.6"
3
3
  end
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
- ActiveRecord::Base.connection.execute(query).tap do |result|
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
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
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ariel Rzezak
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-04-17 00:00:00.000000000 Z
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:
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  - !ruby/object:Gem::Version
52
52
  version: '0'
53
53
  requirements: []
54
- rubygems_version: 3.6.5
54
+ rubygems_version: 3.6.7
55
55
  specification_version: 4
56
56
  summary: Tableize Rails SQL queries
57
57
  test_files: []