taql 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c79d6f21fce22d45f9e3565a7c6f809b503ac534586115c33c02c291b171b7c
4
- data.tar.gz: 159b78b65cf3292a321696a5557874a82a091b37b9d9274cb56e7b43346c3d2d
3
+ metadata.gz: 9eab3ab0fca8b6a61702ba40f696b7df8f0405bd76d8352620e9d6aa23d78aa1
4
+ data.tar.gz: 1b5568b7ff3cfcc0ee2f8fb847ed3217c67b3163d8a9ea4e476485793e2c6bfe
5
5
  SHA512:
6
- metadata.gz: 491fbdb6dfa1cfc2074d0cca5c10f06ac43525ddd696380f5255f287364272b0a01e326fe8712bdfe616fcb614b373dd6dc2defe89c0fc76d68ea0c753a40633
7
- data.tar.gz: 54db2ec859a48662429297d83e8d81c5ebd59517f329c53690214716306a7ffa2303fa98097b1507950cc54954df85a19b4826222fad6d7ccff7166aeb31e196
6
+ metadata.gz: ac7fd1fd09179d0e1b367aee9330b54b0b4f0f0f54d3e83460314d99c88a3afa2390621525681e567255511964d556e757dc5f3ce79daf409d17cf5cde5991e2
7
+ data.tar.gz: 828d90c486a79da04be7acddabd360a3d08f433415bc4da379978d134909c93ab226331fb9f985d6f00c1728d2bef7f63773295340596238b34532941c446e8c
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.2.1] - 2024-08-24
6
+
7
+ - Fixed release
8
+
9
+ ## [0.2.0] - 2024-08-24
10
+
11
+ - Added CLI
12
+
5
13
  ## [0.1.0] - 2024-08-23
6
14
 
7
15
  - 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.1"
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,7 @@ 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
+ $stdout.puts Table.new(result.entries)
10
11
  end
11
12
  end
12
13
  end
data/taql.gemspec CHANGED
@@ -6,8 +6,8 @@ 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"
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
  spec.metadata["source_code_uri"] = spec.homepage
17
17
  spec.metadata["changelog_uri"] = "#{spec.homepage}/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,20 @@
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ariel Rzezak
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-23 00:00:00.000000000 Z
11
+ date: 2024-08-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Taql allows you to pretty print SQL on your Rails console.
13
+ description: Taql allows you to pretty print SQL table queries in Rails.
14
14
  email:
15
15
  - arzezak@gmail.com
16
- executables: []
16
+ executables:
17
+ - taql
17
18
  extensions: []
18
19
  extra_rdoc_files: []
19
20
  files:
@@ -24,7 +25,9 @@ files:
24
25
  - Rakefile
25
26
  - bin/console
26
27
  - bin/setup
28
+ - exe/taql
27
29
  - lib/taql.rb
30
+ - lib/taql/cli.rb
28
31
  - lib/taql/table.rb
29
32
  - lib/taql/version.rb
30
33
  - taql.gemspec
@@ -53,5 +56,5 @@ requirements: []
53
56
  rubygems_version: 3.5.17
54
57
  signing_key:
55
58
  specification_version: 4
56
- summary: Tableize SQL queries on your Rails console
59
+ summary: Tableize Rails SQL queries
57
60
  test_files: []