taql 0.1.0 → 0.2.2

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: 9c79d6f21fce22d45f9e3565a7c6f809b503ac534586115c33c02c291b171b7c
4
- data.tar.gz: 159b78b65cf3292a321696a5557874a82a091b37b9d9274cb56e7b43346c3d2d
3
+ metadata.gz: bb1e8ae5f3c7d362624184f2f456a7922e9190da278309e3c5e09e93ebf074e2
4
+ data.tar.gz: f27ad9873ea02dee880ec14e7a595729f96399cac8569d88d4b083bdacd12fed
5
5
  SHA512:
6
- metadata.gz: 491fbdb6dfa1cfc2074d0cca5c10f06ac43525ddd696380f5255f287364272b0a01e326fe8712bdfe616fcb614b373dd6dc2defe89c0fc76d68ea0c753a40633
7
- data.tar.gz: 54db2ec859a48662429297d83e8d81c5ebd59517f329c53690214716306a7ffa2303fa98097b1507950cc54954df85a19b4826222fad6d7ccff7166aeb31e196
6
+ metadata.gz: e37c9fc4698480c30a44662f514e811a615b2b4875e2e1f87168f34e61aae82a8854eac81b54f675fbee443aee10da324f09b0807e5ca46e666ec75cc850ef9a
7
+ data.tar.gz: 3ecf307be8ce238992e2cfa598052dc66c3ba18680980fa2953404b18fc12248f448aae6e16a7c15f1bec285ac63e63f4e5199c8a749f9ddb4c810357608812a
data/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.2.2] - 2025-04-08
6
+
7
+ - Fixed a bug displaying empty tables
8
+
9
+ ## [0.2.1] - 2024-08-24
10
+
11
+ - Fixed release
12
+
13
+ ## [0.2.0] - 2024-08-24
14
+
15
+ - Added CLI
16
+
5
17
  ## [0.1.0] - 2024-08-23
6
18
 
7
19
  - Added SQL query table formatting
data/README.md CHANGED
@@ -18,24 +18,59 @@ If bundler is not being used to manage dependencies, install the gem by executin
18
18
 
19
19
  ## Usage
20
20
 
21
+ ```sh
22
+ ~/Developer/writebook % taql "select id, title, author, slug from books"
23
+ +----+----------------------+-----------+----------------------+
24
+ | ID | TITLE | AUTHOR | SLUG |
25
+ +----+----------------------+-----------+----------------------+
26
+ | 1 | The Writebook Manual | 37signals | the-writebook-manual |
27
+ +----+----------------------+-----------+----------------------+
28
+ ```
29
+
30
+ ```sh
31
+ ~/Developer/check-in (main) % taql "select id, first_name, last_name, created_at, updated_at from guests limit 3"
32
+ +----+------------+------------+-------------------------+-------------------------+
33
+ | ID | FIRST_NAME | LAST_NAME | CREATED_AT | UPDATED_AT |
34
+ +----+------------+------------+-------------------------+-------------------------+
35
+ | 1 | Alejandro | Bustamante | 2023-07-26 16:26:21 UTC | 2023-07-26 16:26:21 UTC |
36
+ | 2 | Reina | Zelaya | 2023-07-26 16:26:21 UTC | 2023-07-26 16:26:21 UTC |
37
+ | 3 | Carla | Barrios | 2023-07-26 16:26:21 UTC | 2023-07-26 16:26:21 UTC |
38
+ +----+------------+------------+-------------------------+-------------------------+
39
+ ```
40
+
41
+ ```sh
42
+ ~/Developer/check-in (main|!|+) % taql "select count(id) as guest_count from guests"
43
+ +-------------+
44
+ | GUEST_COUNT |
45
+ +-------------+
46
+ | 3721 |
47
+ +-------------+
48
+ ```
49
+
50
+ ```ruby
51
+ >> Taql.execute('select id, email from users order by created at limit 3').pluck("email")
52
+ (1.2ms) select id, email from users limit 3
53
+ +----+---------------------+
54
+ | ID | EMAIL |
55
+ +----+---------------------+
56
+ | 1 | alice@example.com |
57
+ | 2 | bob@example.com |
58
+ | 3 | charlie@example.com |
59
+ +----+---------------------+
60
+ => ["alice@example.com", "bob@example.com", "charlie@example.com"]
61
+ ```
62
+
21
63
  ```ruby
22
- >> Taql.execute("select * from schema_migrations limit 10")
23
- (0.7ms) select * from schema_migrations limit 10
64
+ >> Taql.execute("select * from schema_migrations limit 3")
65
+ (0.7ms) select * from schema_migrations limit 3
24
66
  +----------------+
25
67
  | VERSION |
26
68
  +----------------+
27
69
  | 20240819175830 |
28
70
  | 20240815131806 |
29
71
  | 20240815131747 |
30
- | 20240814161544 |
31
- | 20240814161045 |
32
- | 20240813193038 |
33
- | 20240806190918 |
34
- | 20240729170920 |
35
- | 20240724221738 |
36
- | 20240724220458 |
37
72
  +----------------+
38
- => #<PG::Result:0x000000012ebf6a38 status=PGRES_TUPLES_OK ntuples=10 nfields=1 cmd_tuples=10>
73
+ => #<PG::Result:0x000000012ebf6a38 status=PGRES_TUPLES_OK ntuples=3 nfields=1 cmd_tuples=3>
39
74
  ```
40
75
 
41
76
  ## Development
data/exe/taql ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift("#{__dir__}/../lib")
4
+
5
+ require "taql"
6
+
7
+ Taql::Cli.new(ARGV).run
data/lib/taql/cli.rb ADDED
@@ -0,0 +1,28 @@
1
+ module Taql
2
+ class Cli
3
+ attr_reader :argv
4
+
5
+ def initialize(argv)
6
+ @argv = argv
7
+ end
8
+
9
+ def run
10
+ silence { require environment_path }
11
+ Taql.execute(*argv)
12
+ end
13
+
14
+ private
15
+
16
+ def environment_path
17
+ File.expand_path("config/environment", Dir.pwd)
18
+ end
19
+
20
+ def silence
21
+ original_stdout = $stdout.dup
22
+ $stdout.reopen(IO::NULL)
23
+ yield
24
+ ensure
25
+ $stdout.reopen(original_stdout)
26
+ end
27
+ end
28
+ end
data/lib/taql/table.rb CHANGED
@@ -1,22 +1,23 @@
1
1
  module Taql
2
2
  class Table
3
- attr_reader :entries, :io
3
+ attr_reader :entries
4
4
 
5
- def initialize(entries, io: $stdout)
5
+ def initialize(entries)
6
6
  @entries = entries
7
- @io = io
8
7
  end
9
8
 
10
9
  def print
11
- [
12
- separator,
13
- formatted_headers,
14
- separator,
15
- formatted_entries,
16
- separator
17
- ].each do |output|
18
- io.puts output
19
- end
10
+ <<~OUTPUT
11
+ #{separator}
12
+ #{formatted_headers}
13
+ #{separator}
14
+ #{formatted_entries.join("\n")}
15
+ #{separator}
16
+ OUTPUT
17
+ end
18
+
19
+ def to_s
20
+ print
20
21
  end
21
22
 
22
23
  def formatted_entries
data/lib/taql/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Taql
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.2"
3
3
  end
data/lib/taql.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require_relative "taql/cli"
1
2
  require_relative "taql/table"
2
3
  require_relative "taql/version"
3
4
 
@@ -6,7 +7,9 @@ module Taql
6
7
 
7
8
  def self.execute(query)
8
9
  ActiveRecord::Base.connection.execute(query).tap do |result|
9
- Table.new(result.entries).print
10
+ if (results = result.entries).any?
11
+ $stdout.puts Table.new(results)
12
+ end
10
13
  end
11
14
  end
12
15
  end
data/taql.gemspec CHANGED
@@ -6,17 +6,17 @@ Gem::Specification.new do |spec|
6
6
  spec.authors = ["Ariel Rzezak"]
7
7
  spec.email = ["arzezak@gmail.com"]
8
8
 
9
- spec.summary = "Tableize SQL queries on your Rails console"
10
- spec.description = "Taql allows you to pretty print SQL on your Rails console."
9
+ spec.summary = "Tableize Rails SQL queries"
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
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
17
- spec.metadata["changelog_uri"] = "#{spec.homepage}/CHANGELOG.md"
17
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md"
18
18
 
19
- spec.files = Dir["*.gemspec", "*.{md,txt}", "Rakefile", "{bin,lib}/**/*"]
19
+ spec.files = Dir["*.gemspec", "*.{md,txt}", "Rakefile", "{bin,exe,lib}/**/*"]
20
20
  spec.bindir = "exe"
21
21
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ariel Rzezak
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-08-23 00:00:00.000000000 Z
10
+ date: 2025-04-08 00:00:00.000000000 Z
12
11
  dependencies: []
13
- description: Taql allows you to pretty print SQL on your Rails console.
12
+ description: Taql allows you to pretty print SQL table queries in Rails.
14
13
  email:
15
14
  - arzezak@gmail.com
16
- executables: []
15
+ executables:
16
+ - taql
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
@@ -24,7 +24,9 @@ files:
24
24
  - Rakefile
25
25
  - bin/console
26
26
  - bin/setup
27
+ - exe/taql
27
28
  - lib/taql.rb
29
+ - lib/taql/cli.rb
28
30
  - lib/taql/table.rb
29
31
  - lib/taql/version.rb
30
32
  - taql.gemspec
@@ -34,8 +36,7 @@ licenses:
34
36
  metadata:
35
37
  homepage_uri: https://github.com/arzezak/taql
36
38
  source_code_uri: https://github.com/arzezak/taql
37
- changelog_uri: https://github.com/arzezak/taql/CHANGELOG.md
38
- post_install_message:
39
+ changelog_uri: https://github.com/arzezak/taql/blob/main/CHANGELOG.md
39
40
  rdoc_options: []
40
41
  require_paths:
41
42
  - lib
@@ -50,8 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
51
  - !ruby/object:Gem::Version
51
52
  version: '0'
52
53
  requirements: []
53
- rubygems_version: 3.5.17
54
- signing_key:
54
+ rubygems_version: 3.6.5
55
55
  specification_version: 4
56
- summary: Tableize SQL queries on your Rails console
56
+ summary: Tableize Rails SQL queries
57
57
  test_files: []