sqlui 0.1.19 → 0.1.21

Sign up to get free protection for your applications and to get access to all the features.
data/app/sqlui.rb ADDED
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'sqlui_config'
4
+ require_relative 'server'
5
+
6
+ # Main entry point.
7
+ class Sqlui
8
+ MAX_ROWS = 1_000
9
+
10
+ def initialize(config_file)
11
+ raise 'you must specify a configuration file' unless config_file
12
+ raise 'configuration file does not exist' unless File.exist?(config_file)
13
+
14
+ @config = SqluiConfig.new(config_file)
15
+ @resources_dir = File.join(File.expand_path('..', File.dirname(__FILE__)), 'client', 'resources')
16
+
17
+ # Connect to each database to verify each can be connected to.
18
+ @config.database_configs.each { |database| database.with_client { |client| client } }
19
+ end
20
+
21
+ def run
22
+ Server.init_and_run(@config, @resources_dir)
23
+ end
24
+
25
+ def self.from_command_line(args)
26
+ if args.include?('-v') || args.include?('--version')
27
+ puts File.read('.version')
28
+ exit
29
+ end
30
+
31
+ raise 'you must specify a configuration file' unless args.size == 1
32
+ raise 'configuration file does not exist' unless File.exist?(args[0])
33
+
34
+ Sqlui.new(args[0])
35
+ end
36
+ end
data/app/sqlui_config.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'yaml'
4
4
  require_relative 'database_config'
5
+ require_relative 'args'
5
6
 
6
7
  # App config including database configs.
7
8
  class SqluiConfig
@@ -10,40 +11,34 @@ class SqluiConfig
10
11
  def initialize(filename)
11
12
  config = YAML.safe_load(ERB.new(File.read(filename)).result)
12
13
  deep_symbolize!(config)
13
- @name = fetch_non_empty_string(config, :name).strip
14
- @list_url_path = fetch_non_empty_string(config, :list_url_path).strip
14
+ @name = Args.fetch_non_empty_string(config, :name).strip
15
+ @list_url_path = Args.fetch_non_empty_string(config, :list_url_path).strip
15
16
  raise ArgumentError, 'list_url_path should start with a /' unless @list_url_path.start_with?('/')
16
17
  if @list_url_path.length > 1 && @list_url_path.end_with?('/')
17
18
  raise ArgumentError, 'list_url_path should not end with a /'
18
19
  end
19
20
 
20
- databases = config[:databases]
21
- if databases.nil? || !databases.is_a?(Hash) || databases.empty?
22
- raise ArgumentError, 'required parameter databases missing'
23
- end
24
-
21
+ databases = Args.fetch_non_empty_hash(config, :databases)
25
22
  @database_configs = databases.map do |_, current|
26
23
  DatabaseConfig.new(current)
27
24
  end
28
25
  end
29
26
 
30
27
  def database_config_for(url_path:)
31
- @database_configs.find { |database| database.url_path == url_path } || raise("no config found for path #{url_path}")
28
+ config = @database_configs.find { |database| database.url_path == url_path }
29
+ raise ArgumentError, "no config found for path #{url_path}" unless config
30
+
31
+ config
32
32
  end
33
33
 
34
34
  private
35
35
 
36
- def fetch_non_empty_string(hash, key)
37
- value = hash[key]
38
- raise ArgumentError, "required parameter #{key} missing" if value.nil? || !value.is_a?(String) || value.strip.empty?
39
-
40
- value.strip
41
- end
42
-
43
36
  def deep_symbolize!(object)
44
- return unless object.is_a? Hash
37
+ return object unless object.is_a? Hash
45
38
 
46
39
  object.transform_keys!(&:to_sym)
47
40
  object.each_value { |child| deep_symbolize!(child) }
41
+
42
+ object
48
43
  end
49
44
  end
@@ -1,66 +1,98 @@
1
1
  <html>
2
- <head>
3
- <title>Databases</title>
2
+ <head>
3
+ <title>Databases</title>
4
4
 
5
- <style>
5
+ <style>
6
6
  body {
7
- font-family: Helvetica;
8
- margin: 0px;
7
+ font-family: Helvetica;
8
+ margin: 0px;
9
9
  }
10
10
 
11
11
  h1 {
12
- font-size: 30px;
13
- margin: 10px;
12
+ font-size: 22px;
13
+ }
14
+
15
+ h2 {
16
+ font-size: 20px;
17
+ }
18
+
19
+ p {
20
+ font-size: 18px;
21
+ }
22
+
23
+ .header-box {
24
+ display: flex;
25
+ flex-direction: row;
26
+ border-bottom: 1px solid #ddd;
27
+ height: 36px;
28
+ font-family: Helvetica;
29
+ }
30
+
31
+ .header, .server-name {
32
+ display: flex;
33
+ align-items: center;
34
+ justify-content: start;
35
+ color: #333;
36
+ }
37
+
38
+ .server-name {
39
+ flex: 1;
40
+ padding-left: 15px;
41
+ font-weight: normal;
42
+ }
14
43
 
44
+ .header {
45
+ font-weight: bold;
46
+ padding-left: 5px;
15
47
  }
16
48
 
17
49
  .database a {
18
- margin-right: 10px;
19
- color: darkblue;
20
- font-size: 16px;
50
+ margin-right: 10px;
51
+ color: darkblue;
52
+ font-size: 16px
21
53
  }
22
54
 
23
55
  .database h2 {
24
- margin: 0px;
25
- font-size: 20px;
26
- font-weight: bold;
56
+ margin: 0px;
27
57
  }
28
58
 
29
59
  .database p {
30
- margin: 0px;
31
- margin-top: 10px;
32
- font-size: 16px;
60
+ margin: 0px;
61
+ margin-top: 10px;
33
62
  }
34
63
 
35
64
  .database {
36
- margin: 0px;
37
- padding: 10px;
38
- cursor: pointer;
39
- border-bottom: 1px solid #eeeeee;
65
+ margin: 0px;
66
+ padding: 10px;
67
+ cursor: pointer;
68
+ border-bottom: 1px solid #eeeeee;
40
69
  }
41
70
 
42
71
  .database:last-child {
43
- border-bottom: none;
72
+ border-bottom: none;
44
73
  }
45
74
 
46
75
  .database:hover {
47
- background: #eee;
76
+ background: #eee;
48
77
  }
49
- </style>
50
- </head>
78
+ </style>
79
+ </head>
51
80
 
52
- <body>
53
- <h1><% config.name %> Databases</h1>
54
- <% config.database_configs.each do |database_config| %>
55
- <div class="database" onclick="window.location='<%= "#{database_config.url_path}/app" %>'">
56
- <h2 class='name'><%= database_config.display_name %></h2>
57
- <a class='query-link' href="<%= database_config.url_path %>/app">query</a>
58
- <a class='saved-link' href="<%= database_config.url_path %>/app?tab=saved">saved</a>
59
- <a class='structure-link' href="<%= database_config.url_path %>/app?tab=structure">structure</a>
60
- <p class='description'>
61
- <%= database_config.description %>
62
- </p>
63
- </div>
64
- <% end %>
65
- </body>
81
+ <body>
82
+ <div class="header-box">
83
+ <h1 class="header">SQLUI</h1>
84
+ <h1 class="server-name"><%= config.name %> Databases</h1>
85
+ </div>
86
+ <% config.database_configs.each do |database_config| %>
87
+ <div class="database" onclick="window.location='<%= "#{database_config.url_path}/app" %>'">
88
+ <h2 class='name'><%= database_config.display_name %></h2>
89
+ <a class='query-link' href="<%= database_config.url_path %>/app">query</a>
90
+ <a class='saved-link' href="<%= database_config.url_path %>/app?tab=saved">saved</a>
91
+ <a class='structure-link' href="<%= database_config.url_path %>/app?tab=structure">structure</a>
92
+ <p class='description'>
93
+ <%= database_config.description %>
94
+ </p>
95
+ </div>
96
+ <% end %>
97
+ </body>
66
98
  </html>
data/bin/sqlui CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative '../app/server'
4
+ require_relative '../app/sqlui'
5
+
6
+ Sqlui.from_command_line(ARGV).run