db_admin 0.1.2 → 0.1.3

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: f6088beb0959e56e8da0a7da89afc2777b51787c858fa3dfbbc1cb28000c2863
4
- data.tar.gz: ed3c59335703f4c9f73791729f78036336a4bceec777293a5cfd1ffde5adc4ea
3
+ metadata.gz: dab650953c43a0af84a9b7eb9fc7bff6c2a9b5b47e264237eb3c5c4e25dd08fc
4
+ data.tar.gz: 86815bc0a74f7b0ad80e373470af42cb01e0e6eb319684de6dc8d5fcc3bfd194
5
5
  SHA512:
6
- metadata.gz: 0d52e3976234eb2944119fc22c75a16dc611e811eacd66c0bceb0cd9bdec5b6b7310f2396614e490fc6bc6d39ad079bb15159a2eafb4363abfc8fcab32b15f64
7
- data.tar.gz: 0a031caf04fe329413fed852de84aa9be4ee27fb748a15c8b0bfc817c4336dfc508192f94fd436507cb853951236fd7661d0038989389a6b163d5b3bca3058cc
6
+ metadata.gz: 2ab1d7ffda6ae04f8b54a07ad8691e5d7b542f43057e1890d1c4a5387e47d49c2dc976d80d2982732e3b8a4c9c0a98f5de173617757a1bdb8d875e224573bbba
7
+ data.tar.gz: 5651d43ed1a38535dd71b57ffdc2bf0b96b67b4daabb10f02f316d0caeac64864a871575ce625102d6630312a4c3218bb9dc0aaad1241bcd8c5b10642b7baf74
data/README.md CHANGED
@@ -1,13 +1,12 @@
1
1
  ## Ruby Database Admin
2
2
  A gem based on [Sinatra](https://github.com/sinatra/sinatra) and [Sequel](https://github.com/jeremyevans/sequel).
3
-
4
3
  You can use it to manage multiple databases at the same time.
5
4
 
6
5
  Rails user can also use it because it is just a gem. Here are some demo pictures.
7
6
 
8
7
  ![Demo home](./lib/public/demo_home.png)
9
8
 
10
- ![Demo operations](./lib/public/demo_oprations.png)
9
+ ![Demo operations](./lib/public/demo_operations.png)
11
10
 
12
11
  ![Demo hover](./lib/public/demo_hover.png)
13
12
 
@@ -15,12 +14,12 @@ Rails user can also use it because it is just a gem. Here are some demo pictures
15
14
  ~~~bash
16
15
  $ gem install db_admin
17
16
  ~~~
18
- Or add `gem 'db_admin'` to `Gemfile`, then `$ bundle install`.
17
+ Or modify `Gemfile` as below, then `$ bundle install`.
19
18
  ~~~ruby
20
19
  group :development do
21
20
  # A Web UI for database admin. Run `$ db_admin` and then
22
21
  # visit http://localhost:4567
23
- gem 'db_admin'
22
+ gem 'db_admin', require: false
24
23
  end
25
24
  ~~~
26
25
 
@@ -41,7 +40,9 @@ $ ruby db_admin/lib/db_admin.rb # Then visit http://localhost:4567
41
40
  ~~~
42
41
 
43
42
  ### Debugging
44
- Uncomment the below line in `db_admin/lib/db_admin.rb` to auto-reload changed files.
43
+ You need to restart Web Server when you made a change.
44
+
45
+ Uncomment the below line in `./lib/db_admin.rb` to auto-reload changed files.
45
46
  ~~~ruby
46
- require 'sinatra/reloader' if development? # `gem install sinatra-reloader` first.
47
+ require 'sinatra/reloader' if development? # `$ gem install sinatra-reloader` first.
47
48
  ~~~
@@ -1,6 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'db_admin'
4
-
5
- puts "hello world in db_admin bin"
6
-
@@ -3,31 +3,18 @@ require 'sequel'
3
3
  require 'json'
4
4
 
5
5
  class RubyDatabaseAdmin < Sinatra::Base
6
- # require 'sinatra/reloader' if development? # `gem install sinatra-reloader` first if you want to debug this project by auto-reloading changed files.
6
+ # require 'sinatra/reloader' if development? # `$ gem install sinatra-reloader` first if you want to debug this project by auto-reloading changed files.
7
7
 
8
8
  use Rack::MethodOverride
9
9
 
10
10
  DBs = []
11
11
  DB = nil
12
12
 
13
- # Below are direct connect examples. Try to uncomment a line to use it.
14
- #
15
- # DB = Sequel.sqlite('sqlite_example.db') # Connect SQLite db located at './sqlite_example.db'.
16
- #
17
- # Connect PostgreSQL.
13
+ # 'adapter' can be 'postgres', 'mysql2', 'sqlite', 'oracle', etc.
18
14
  # DB = Sequel.connect({ adapter: 'postgres',
19
15
  # host: 'hostname_or_ip',
20
16
  # database: 'database_name',
21
17
  # user: 'user',
22
- # password: '',
23
- # port: 5432 })
24
- #
25
- # 'adapter' can also be 'mysql2', 'postgres', 'sqlite', 'oracle', 'sqlanywhere', 'db2', 'informix', etc.
26
- # We will use default port if port is nil.
27
- # DB = Sequel.connect({ adapter: 'mysql2',
28
- # host: 'hostname_or_ip',
29
- # database: 'database_name',
30
- # user: 'user',
31
18
  # password: '' })
32
19
 
33
20
  DBs << DB unless DB.nil?
@@ -80,7 +67,9 @@ class RubyDatabaseAdmin < Sinatra::Base
80
67
 
81
68
  get '/switch_db/:i' do
82
69
  begin
83
- DB = DBs[params[:i].to_i] if DBs[params[:i].to_i].test_connection
70
+ if should_switch_db?(DBs[params[:i].to_i])
71
+ DB = DBs[params[:i].to_i]
72
+ end
84
73
  rescue Exception => e
85
74
  session[:error] = e.message
86
75
  end
@@ -295,9 +284,9 @@ class RubyDatabaseAdmin < Sinatra::Base
295
284
  eval(/{.*}/.match(DB.inspect)[0])
296
285
  end
297
286
 
298
- # def select_sql?(sql)
299
- # sql[0..5].upcase == 'SELECT'
300
- # end
287
+ def should_switch_db?(new_db)
288
+ new_db.test_connection && new_db != DB
289
+ end
301
290
  end
302
291
 
303
292
  RubyDatabaseAdmin.run!
@@ -5,7 +5,6 @@
5
5
 
6
6
  <form action='connect_another_db' method="post">
7
7
  <select name='adapter'>
8
- <% puts adapter_hash %>
9
8
  <% adapter_hash.reject!{ |k| k == :mysql }.each do |adapter_key, adapter_value| %>
10
9
  <option value='<%= adapter_key %>' <%= 'selected' if database_adapter == adapter_value || adapter_key == params[:adapter] %>><%= adapter_value %></option>
11
10
  <% end %>
@@ -38,4 +37,4 @@
38
37
  <br>
39
38
  </div>
40
39
 
41
- <a href='https://github.com/gazeldx/ruby-db-admin' target='_blank'>ruby-db-admin</a>@github
40
+ <a href='https://github.com/gazeldx/db_admin' target='_blank'>db_admin</a>@github
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lane Zhang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-30 00:00:00.000000000 Z
11
+ date: 2019-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -52,7 +52,7 @@ files:
52
52
  - lib/public/css/bootstrap.min.css
53
53
  - lib/public/demo_home.png
54
54
  - lib/public/demo_hover.png
55
- - lib/public/demo_oprations.png
55
+ - lib/public/demo_operations.png
56
56
  - lib/public/js/bootstrap.min.js
57
57
  - lib/public/js/jquery.min.js
58
58
  - lib/views/_execute_sql.erb