db-gui 0.1.1 → 0.2.1

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: 32291b6eecdc2752f695361d340e0f00c6e32bfb9b9d57821bbfafe884a6adbf
4
- data.tar.gz: c0e66b0a2362651790810c50166c27a75e44fe1da68df13c10019a43f3db22f0
3
+ metadata.gz: 38eb8b2669f281d3dddb78945f259d5fe8dea12eb31b51f5761ce4ced71381e9
4
+ data.tar.gz: a0cb8959b31975f176302f20404011e3a8115d5e597461de0f90fe57a5305cf3
5
5
  SHA512:
6
- metadata.gz: 99f98299b9d09171625237220c2c0d2d687bcfbd703c3e6c9e46fa5bc67308b68bfa5d9637fac2e5940b0e05c83ddfe0a52ca2156dcbfb03e41203d775ca506e
7
- data.tar.gz: 1d280fbf96dc8efd81054d36808218f3cd21c2eff8a63f2a6575dd815de6e05d94c6e388f80ec146b657c9e93f283f8f11bb9f19868b514f0160b6f9d9c21cb2
6
+ metadata.gz: b664e4ed31d076e644451b58bd809dc9e9f58b8526d96d052d41eef238c4f293413f886eb0b4fe7f0d9fe19b66eba563d7d98f936fad43d0032b0e4f590ed9ec
7
+ data.tar.gz: 43696e4a6cb8ecd26363a5dc9f33588b1b88895aa5c16a63a88caa6fce393c9d2907f05e52b9ce66ecc3e35d6de8549e85e29f34af1191b81a1fda5b03e8cf5e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.2.1
4
+
5
+ - Fix bug in 0.2.0 with crashing whenever running a DB query for the second time.
6
+
7
+ ## 0.2.0
8
+
9
+ - Edit -> Copy Table menu item to copy table data as a formatted string to the clipboard
10
+ - Edit -> Copy Selected Row menu item to copy selected row data as a formatted string to the clipboard
11
+
3
12
  ## 0.1.1
4
13
 
5
14
  - Automatically extend DB command timeout after timing out by retrying 6 times (7 times total) with exponential timeout increases
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # DB GUI (Database Graphical User Interface) 0.1.1
1
+ # DB GUI (Database Graphical User Interface) 0.2.1
2
2
  ## [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=40 /> Glimmer DSL for LibUI Application](https://github.com/AndyObtiva/glimmer-dsl-libui)
3
3
  [![Gem Version](https://badge.fury.io/rb/db-gui.svg)](http://badge.fury.io/rb/db-gui)
4
4
 
@@ -12,7 +12,7 @@ It currently supports PostgreSQL as a start, with the potential of supporting ma
12
12
 
13
13
  Run:
14
14
  ```
15
- gem install db-gui -v0.1.1
15
+ gem install db-gui -v0.2.1
16
16
  ```
17
17
 
18
18
  ## Usage
@@ -26,6 +26,16 @@ Or, run one of the aliases: `db-ui` / `dbgui` / `db-gui`
26
26
 
27
27
  Note that it stores the last connection details under `~/.db_gui`, and will auto-connect using that configuration on startup for extra convenience (in the future, there is the potential to support multiple connection configurations).
28
28
 
29
+ ### Menu Items
30
+
31
+ **Edit -> Copy Table**
32
+
33
+ Click on this menu item to copy the table data as a formatted string to the clipboard.
34
+
35
+ **Edit -> Copy Selected Row**
36
+
37
+ Click on this menu item to copy the selected row data as a formatted string to the clipboard.
38
+
29
39
  ## Change Log
30
40
 
31
41
  [CHANGELOG.md](/CHANGELOG.md)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.1
@@ -1,5 +1,6 @@
1
1
  require 'fileutils'
2
2
  require 'timeout'
3
+ require 'clipboard'
3
4
 
4
5
  class DbGui
5
6
  module Model
@@ -12,11 +13,13 @@ class DbGui
12
13
  COUNT_RETRIES = ENV.fetch('DB_COMMAND_COUNT_RETRIES', 7)
13
14
  REGEX_ROW_COUNT = /^\((\d+) row/
14
15
  ERROR_PREFIX = 'ERROR:'
16
+ NEW_LINE = OS.windows? ? "\r\n" : "\n"
15
17
 
16
18
  attr_accessor :connected
17
19
  alias connected? connected
18
20
  attr_accessor :db_command_result
19
21
  attr_accessor :db_command
22
+ attr_accessor :db_command_result_selection
20
23
 
21
24
  def initialize
22
25
  load_db_config
@@ -24,6 +27,7 @@ class DbGui
24
27
  self.port ||= 5432 # PostgreSQL default port
25
28
  self.db_command_result = ''
26
29
  self.db_command_timeout ||= ENV.fetch('DB_COMMAND_TIMEOUT_IN_MILLISECONDS', 300).to_i
30
+ self.db_command_result_selection = 0
27
31
  connect if to_h.except(:password).none? {|value| value.nil? || (value.respond_to?(:empty?) && value.empty?) }
28
32
  end
29
33
 
@@ -94,6 +98,30 @@ class DbGui
94
98
  db_command_result.to_s.strip.start_with?(ERROR_PREFIX)
95
99
  end
96
100
 
101
+ def copy_table
102
+ return if db_command_result_rows.empty?
103
+ Clipboard.copy(formatted_table_string)
104
+ end
105
+
106
+ def copy_selected_row
107
+ return if db_command_result_rows.empty?
108
+ Clipboard.copy(formatted_selected_row_string)
109
+ end
110
+
111
+ def formatted_table_string
112
+ column_max_lengths = db_command_result_column_max_lengths
113
+ db_command_result_rows.map do |row|
114
+ row.each_with_index.map do |data, column_index|
115
+ data.ljust(column_max_lengths[column_index])
116
+ end.join(" | ")
117
+ end.join(NEW_LINE)
118
+ end
119
+
120
+ def formatted_selected_row_string
121
+ selected_row = db_command_result_rows[db_command_result_selection]
122
+ selected_row.join(' | ')
123
+ end
124
+
97
125
  private
98
126
 
99
127
  def read_io_into_db_command_result
@@ -174,6 +202,18 @@ class DbGui
174
202
  end
175
203
  [count, headers, rows]
176
204
  end
205
+
206
+ def db_command_result_column_max_lengths
207
+ column_count = db_command_result_rows.first.size
208
+ column_max_lengths = []
209
+ db_command_result_rows.each do |row|
210
+ row.each_with_index do |value, column_index|
211
+ column_max_lengths[column_index] ||= 0
212
+ column_max_lengths[column_index] = [column_max_lengths[column_index], value.size].max
213
+ end
214
+ end
215
+ column_max_lengths
216
+ end
177
217
  end
178
218
  end
179
219
  end
@@ -19,6 +19,12 @@ class DbGui
19
19
  end
20
20
 
21
21
  cell_rows db.db_command_result_rows
22
+ selection_mode :one
23
+ selection db.db_command_result_selection
24
+
25
+ on_selection_changed do |t, selection, added_selection, removed_selection|
26
+ db.db_command_result_selection = selection
27
+ end
22
28
  }
23
29
  else
24
30
  label('No data')
@@ -13,7 +13,7 @@ class DbGui
13
13
 
14
14
  before_body do
15
15
  @db = Model::Db.new
16
- # menu_bar # TODO implement
16
+ menu_bar
17
17
  end
18
18
 
19
19
  body {
@@ -35,38 +35,48 @@ class DbGui
35
35
  }
36
36
  }
37
37
 
38
- # def menu_bar
39
- # menu('File') {
40
- # menu_item('Preferences...') {
41
- # on_clicked do
42
- # display_preferences_dialog
43
- # end
44
- # }
45
- #
46
- # quit_menu_item if OS.mac?
47
- # }
48
- # menu('Help') {
49
- # if OS.mac?
50
- # about_menu_item {
51
- # on_clicked do
52
- # display_about_dialog
53
- # end
54
- # }
55
- # end
56
- #
57
- # menu_item('About') {
58
- # on_clicked do
59
- # display_about_dialog
60
- # end
61
- # }
62
- # }
63
- # end
64
- #
65
- # def display_about_dialog
66
- # message = "Db Gui #{VERSION}\n\n#{LICENSE}"
67
- # msg_box('About', message)
68
- # end
69
- #
38
+ def menu_bar
39
+ menu('Edit') {
40
+ menu_item('Copy Table') {
41
+ enabled <= [db, :db_command_result_rows, computed_by: :db_command_result, on_read: -> (data) { !data.empty? }]
42
+
43
+ on_clicked do
44
+ db.copy_table
45
+ end
46
+ }
47
+
48
+ menu_item('Copy Selected Row') {
49
+ enabled <= [db, :db_command_result_rows, computed_by: :db_command_result, on_read: -> (data) { !data.empty? }]
50
+
51
+ on_clicked do
52
+ db.copy_selected_row
53
+ end
54
+ }
55
+
56
+ quit_menu_item if OS.mac?
57
+ }
58
+ menu('Help') {
59
+ if OS.mac?
60
+ about_menu_item {
61
+ on_clicked do
62
+ display_about_dialog
63
+ end
64
+ }
65
+ end
66
+
67
+ menu_item('About') {
68
+ on_clicked do
69
+ display_about_dialog
70
+ end
71
+ }
72
+ }
73
+ end
74
+
75
+ def display_about_dialog
76
+ message = "DB GUI #{VERSION}\n\n#{LICENSE}"
77
+ msg_box('About', message)
78
+ end
79
+
70
80
  # def display_preferences_dialog
71
81
  # window {
72
82
  # title 'Preferences'
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db-gui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-03-24 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: glimmer-dsl-libui
@@ -24,6 +23,20 @@ dependencies:
24
23
  - - "~>"
25
24
  - !ruby/object:Gem::Version
26
25
  version: 0.12.7
26
+ - !ruby/object:Gem::Dependency
27
+ name: clipboard
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 2.0.0
27
40
  - !ruby/object:Gem::Dependency
28
41
  name: rspec
29
42
  requirement: !ruby/object:Gem::Requirement
@@ -67,12 +80,12 @@ dependencies:
67
80
  - !ruby/object:Gem::Version
68
81
  version: '0'
69
82
  description: DB GUI (Database Graphical User Interface) - Enables Interaction with
70
- Relational SQL Databases
83
+ Relational SQL Databases. This alpha version only supports PostgreSQL at the moment.
71
84
  email: andy.am@gmail.com
72
85
  executables:
73
86
  - db-gui
74
- - dbgui
75
87
  - db-ui
88
+ - dbgui
76
89
  - dbui
77
90
  extensions: []
78
91
  extra_rdoc_files:
@@ -102,7 +115,6 @@ homepage: http://github.com/AndyObtiva/db-gui
102
115
  licenses:
103
116
  - MIT
104
117
  metadata: {}
105
- post_install_message:
106
118
  rdoc_options: []
107
119
  require_paths:
108
120
  - lib
@@ -118,8 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
130
  - !ruby/object:Gem::Version
119
131
  version: '0'
120
132
  requirements: []
121
- rubygems_version: 3.4.19
122
- signing_key:
133
+ rubygems_version: 3.6.7
123
134
  specification_version: 4
124
135
  summary: DB GUI
125
136
  test_files: []