db-gui 0.3.0 → 0.4.0

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: 1a78c9674da527b498d11f7147b066c48d4b9de25f4ad3bffc6d3c7f908e7380
4
- data.tar.gz: 7d8c82fae0cdc343a6ef2dae98a0b820cd73fa9c6c4c128f60d1ecc751429a0a
3
+ metadata.gz: 75e15d34f7435b0c8d0d66b67cc8138b7935c88dad827a9ed2cc3575e9a83b00
4
+ data.tar.gz: 7f19a38c51c2e91423e7c95d7aa631410208f3a9134e6e011c916b827949e6ba
5
5
  SHA512:
6
- metadata.gz: '021209590135c5c94cea318db98b73362c944909d5da2e168544a8524c357f4382baef9776205575459fd0f32f26ec4b86be6de943ec9f04ab0a534574b103d8'
7
- data.tar.gz: 5596987aded997443eff090340dcf0b407c335e84cf2194194ec30101493d96a0b662b61fb51cae55b67a493f17d443c171dd63cc37fdd2ceb8f14c6fad0c453
6
+ metadata.gz: ef5768eb5582be26fb0d2c3089c33bc6d905982981978361713ec764134952d0a0abb246494a6a5c17fe1cd27cff176acb3a719e0e547b5e28e59e6b43e4f4aa
7
+ data.tar.gz: a77221ceb7131f2c0d14b28e1ec3465f740f9c678e0e9936579766019efd9abca519ba0132c609f1a2acbe116ddbc49270df5008c67c1a061335bfbe53d0a39a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.4.0
4
+
5
+ - Remember all DB commands in a history dropdown
6
+ - Remove currently selected DB command from DB command history dropdown
7
+ - Clear DB command history dropdown
8
+
3
9
  ## 0.3.0
4
10
 
5
11
  - Support the ability to save/load multiple databases (DB configs)
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # DB GUI (Database Graphical User Interface) 0.3.0
1
+ # DB GUI (Database Graphical User Interface) 0.4.0
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
 
@@ -8,11 +8,15 @@ It currently supports PostgreSQL as a start, with the potential of supporting ma
8
8
 
9
9
  ![db gui](/screenshots/db-gui-mac.png)
10
10
 
11
+ ![db gui](/screenshots/db-gui-mac-disconnected.png)
12
+
13
+ ![db gui](/screenshots/db-gui-mac-multiple-db-configs.png)
14
+
11
15
  ## Setup
12
16
 
13
17
  Run:
14
18
  ```
15
- gem install db-gui -v0.3.0
19
+ gem install db-gui -v0.4.0
16
20
  ```
17
21
 
18
22
  ## Usage
@@ -26,6 +30,8 @@ Or, run one of the aliases: `db-ui` / `dbgui` / `db-gui`
26
30
 
27
31
  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
32
 
33
+ It remembers DB command history in a dropdown above the DB command text area.
34
+
29
35
  ### Menu Items
30
36
 
31
37
  **Edit -> Copy Table**
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
@@ -10,17 +10,19 @@ class DbGui
10
10
  REGEX_ROW_COUNT = /^\((\d+) row/
11
11
  ERROR_PREFIX = 'ERROR:'
12
12
  NEW_LINE = OS.windows? ? "\r\n" : "\n"
13
+ DB_COMMAND_TIMEOUT_DEFAULT = 300
13
14
 
14
15
  attr_accessor :deleteable
15
16
  alias deleteable? deleteable
16
17
  attr_accessor :connected
17
18
  alias connected? connected
18
19
  attr_accessor :db_command_result
20
+ attr_accessor :db_commands
19
21
  attr_accessor :db_command
20
22
  attr_accessor :db_command_result_selection
21
23
 
22
24
  def initialize
23
- load_db_command
25
+ load_db_commands
24
26
  reset
25
27
  to_h.keys.each do |attribute|
26
28
  Glimmer::DataBinding::Observer.proc do |value|
@@ -37,8 +39,17 @@ class DbGui
37
39
  self.username = nil
38
40
  self.password = nil
39
41
  self.db_command_result = ''
40
- self.db_command_timeout ||= ENV.fetch('DB_COMMAND_TIMEOUT_IN_MILLISECONDS', 300).to_i
42
+ self.db_command_timeout ||= ENV.fetch('DB_COMMAND_TIMEOUT_IN_MILLISECONDS', DB_COMMAND_TIMEOUT_DEFAULT).to_i
41
43
  self.db_command_result_selection = 0
44
+ self.db_commands ||= ['']
45
+ self.db_command ||= ''
46
+ end
47
+
48
+ def db_commands
49
+ if @db_commands == []
50
+ @db_commands = ['']
51
+ end
52
+ @db_commands
42
53
  end
43
54
 
44
55
  def new?
@@ -98,8 +109,23 @@ class DbGui
98
109
  end
99
110
 
100
111
  def run_db_command
112
+ reset_db_command_timeout
101
113
  run_io_command(db_command)
102
- save_db_command
114
+ save_db_commands
115
+ end
116
+
117
+ def clear_db_commands
118
+ self.db_commands = ['']
119
+ self.db_command = ''
120
+ save_db_commands(add_current: false)
121
+ end
122
+
123
+ def remove_db_command
124
+ current_db_command = db_command
125
+ self.db_commands = self.db_commands - [current_db_command.to_s.strip]
126
+ self.db_command = ''
127
+ self.db_command = self.db_commands.last || ''
128
+ save_db_commands(add_current: false)
103
129
  end
104
130
 
105
131
  def db_command_result_count
@@ -182,16 +208,30 @@ class DbGui
182
208
  @line = nil
183
209
  end
184
210
 
185
- def save_db_command
186
- db_commands_array = [db_command] # TODO in the future, support storing multiple DB commands
187
- db_commands_file_content = YAML.dump(db_commands_array)
211
+ def reset_db_command_timeout
212
+ self.db_command_timeout = DB_COMMAND_TIMEOUT_DEFAULT
213
+ end
214
+
215
+ def save_db_commands(add_current: true)
216
+ return if db_command_result_error?
217
+ new_command = db_command.to_s.strip
218
+ self.db_commands ||= []
219
+ db_command_exists_in_db_commands = db_commands.find { |command| new_command == command.to_s.strip }
220
+ if add_current && !db_command_exists_in_db_commands
221
+ new_db_commands = db_commands + [new_command]
222
+ self.db_commands = new_db_commands.reject { |command| command.to_s.strip.empty? }
223
+ end
224
+ self.db_command = ''
225
+ self.db_command = new_command
226
+ db_commands_file_content = YAML.dump(db_command:, db_commands:)
188
227
  File.write(FILE_DB_COMMANDS, db_commands_file_content)
189
228
  end
190
229
 
191
- def load_db_command
230
+ def load_db_commands
192
231
  db_commands_file_content = File.read(FILE_DB_COMMANDS)
193
- db_commands_array = YAML.load(db_commands_file_content)
194
- self.db_command = db_commands_array.first
232
+ db_commands_config = YAML.load(db_commands_file_content)
233
+ self.db_commands = db_commands_config[:db_commands]
234
+ self.db_command = db_commands_config[:db_command]
195
235
  rescue => e
196
236
  puts "No database commands stored yet. #{e.message}"
197
237
  end
@@ -11,19 +11,40 @@ class DbGui
11
11
 
12
12
  body {
13
13
  vertical_box {
14
+ horizontal_box {
15
+ stretchy false
16
+ combobox {
17
+ items <= [db_presenter, 'selected_db.db_commands']
18
+ selected_item <=> [db_presenter, 'selected_db.db_command']
19
+ enabled <= [db_presenter, 'selected_db.db_commands', on_read: -> (value) { value != [''] }]
20
+ }
21
+ button('Remove') {
22
+ stretchy false
23
+ on_clicked do
24
+ db_presenter.selected_db.remove_db_command
25
+ end
26
+ }
27
+ button('Clear') {
28
+ stretchy false
29
+ on_clicked do
30
+ db_presenter.selected_db.clear_db_commands
31
+ end
32
+ }
33
+ }
14
34
  non_wrapping_multiline_entry {
15
35
  text <=> [db_presenter, 'selected_db.db_command']
16
36
  }
17
-
18
37
  horizontal_box {
19
38
  stretchy false
20
39
 
21
40
  button('Run') {
41
+ enabled <= [db_presenter, 'selected_db.db_command', on_read: -> (command) { !command.to_s.strip.empty? }]
42
+
22
43
  on_clicked do
23
44
  db_presenter.selected_db.run_db_command
24
45
  end
25
46
  }
26
-
47
+
27
48
  label('Timeout (msec): ') {
28
49
  stretchy false
29
50
  }
@@ -32,7 +53,7 @@ class DbGui
32
53
  value <=> [db_presenter, 'selected_db.db_command_timeout', on_read: :to_i]
33
54
  }
34
55
 
35
- label('Row(s): ') {
56
+ label('Rows: ') {
36
57
  stretchy false
37
58
  }
38
59
  label {
@@ -10,7 +10,7 @@ class DbGui
10
10
  body {
11
11
  vertical_box {
12
12
  form {
13
- combobox { |me|
13
+ combobox {
14
14
  label 'Selected Config:'
15
15
  items <= [db_presenter, :dbs, on_read: ->(dbs) { dbs.map(&:name) }]
16
16
  selected_item <=> [db_presenter, :selected_db_name]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db-gui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh