sqlui 0.1.19 → 0.1.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.version +1 -1
- data/app/args.rb +33 -0
- data/app/database_config.rb +7 -7
- data/app/database_metadata.rb +116 -0
- data/app/deep.rb +58 -0
- data/app/mysql_types.rb +33 -0
- data/app/server.rb +125 -217
- data/app/sqlui.rb +36 -0
- data/app/sqlui_config.rb +11 -16
- data/app/views/databases.erb +70 -38
- data/bin/sqlui +3 -1
- data/client/resources/sqlui.css +288 -242
- data/client/resources/sqlui.html +8 -5
- data/client/resources/sqlui.js +168 -82
- metadata +7 -2
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
|
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 }
|
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
|
data/app/views/databases.erb
CHANGED
@@ -1,66 +1,98 @@
|
|
1
1
|
<html>
|
2
|
-
|
3
|
-
|
2
|
+
<head>
|
3
|
+
<title>Databases</title>
|
4
4
|
|
5
|
-
|
5
|
+
<style>
|
6
6
|
body {
|
7
|
-
|
8
|
-
|
7
|
+
font-family: Helvetica;
|
8
|
+
margin: 0px;
|
9
9
|
}
|
10
10
|
|
11
11
|
h1 {
|
12
|
-
|
13
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
50
|
+
margin-right: 10px;
|
51
|
+
color: darkblue;
|
52
|
+
font-size: 16px
|
21
53
|
}
|
22
54
|
|
23
55
|
.database h2 {
|
24
|
-
|
25
|
-
font-size: 20px;
|
26
|
-
font-weight: bold;
|
56
|
+
margin: 0px;
|
27
57
|
}
|
28
58
|
|
29
59
|
.database p {
|
30
|
-
|
31
|
-
|
32
|
-
font-size: 16px;
|
60
|
+
margin: 0px;
|
61
|
+
margin-top: 10px;
|
33
62
|
}
|
34
63
|
|
35
64
|
.database {
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
-
|
72
|
+
border-bottom: none;
|
44
73
|
}
|
45
74
|
|
46
75
|
.database:hover {
|
47
|
-
|
76
|
+
background: #eee;
|
48
77
|
}
|
49
|
-
|
50
|
-
|
78
|
+
</style>
|
79
|
+
</head>
|
51
80
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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>
|