sqlui 0.1.8 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sqlui.rb +17 -6
- data/resources/sqlui.js +32 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43388f7bb405a390a4ae0e49650475dcc64c7a649df8d7333a0a7f278974817e
|
4
|
+
data.tar.gz: 43104948aec2eba3df960657cfc242092ef2587ce5bca6223102351462c56c17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9752cbb037aaececfb4d1025bdbd3a4f1da1da35815321570ff64955589876c9f73c8a5605d7c4e8b43fc705b2d124b82d8249a35908acc1b191282f370f60e
|
7
|
+
data.tar.gz: 75897a760e3f24f21b2853ca6a368a5375f364731de82bdc65e17f87af67385b03c1fa6970d80b861f1f2f5b2efd0279d430522faf743ac86433a23dea3ba219
|
data/lib/sqlui.rb
CHANGED
@@ -5,11 +5,12 @@ require 'set'
|
|
5
5
|
class SQLUI
|
6
6
|
MAX_ROWS = 1_000
|
7
7
|
|
8
|
-
def initialize(name:, saved_path:, max_rows: MAX_ROWS
|
8
|
+
def initialize(client:, table_schema: nil, name:, saved_path:, max_rows: MAX_ROWS)
|
9
|
+
@client = client
|
10
|
+
@table_schema = table_schema
|
9
11
|
@name = name
|
10
12
|
@saved_path = saved_path
|
11
13
|
@max_rows = max_rows
|
12
|
-
@queryer = block
|
13
14
|
@resources_dir = File.join(File.expand_path('..', File.dirname(__FILE__)), 'resources')
|
14
15
|
end
|
15
16
|
|
@@ -77,7 +78,12 @@ class SQLUI
|
|
77
78
|
end
|
78
79
|
|
79
80
|
def load_metadata
|
80
|
-
|
81
|
+
if @table_schema
|
82
|
+
where_clause = "where table_schema = '#{@table_schema}'"
|
83
|
+
else
|
84
|
+
where_clause = "where table_schema not in('mysql', 'sys')"
|
85
|
+
end
|
86
|
+
stats_result = @client.query(
|
81
87
|
<<~SQL
|
82
88
|
select
|
83
89
|
table_schema,
|
@@ -87,7 +93,7 @@ class SQLUI
|
|
87
93
|
non_unique,
|
88
94
|
column_name
|
89
95
|
from information_schema.statistics
|
90
|
-
|
96
|
+
#{where_clause}
|
91
97
|
order by table_schema, table_name, if(index_name = "PRIMARY", 0, index_name), seq_in_index;
|
92
98
|
SQL
|
93
99
|
)
|
@@ -131,7 +137,12 @@ class SQLUI
|
|
131
137
|
column[:column_name] = row['column_name']
|
132
138
|
end
|
133
139
|
|
134
|
-
|
140
|
+
if @table_schema
|
141
|
+
where_clause = "where table_schema = '#{@table_schema}'"
|
142
|
+
else
|
143
|
+
where_clause = "where table_schema not in('information_schema' 'mysql', 'performance_schema', 'sys')"
|
144
|
+
end
|
145
|
+
column_result = @client.query(
|
135
146
|
<<~SQL
|
136
147
|
select
|
137
148
|
table_schema,
|
@@ -173,7 +184,7 @@ class SQLUI
|
|
173
184
|
end
|
174
185
|
|
175
186
|
def execute_query(sql)
|
176
|
-
result = @
|
187
|
+
result = @client.query(sql)
|
177
188
|
rows = result.map { |row| row.values }
|
178
189
|
columns = result.first&.keys || []
|
179
190
|
column_types = columns.map { |_| 'string' }
|
data/resources/sqlui.js
CHANGED
@@ -23951,19 +23951,18 @@ var sqlui = (function (exports) {
|
|
23951
23951
|
}
|
23952
23952
|
|
23953
23953
|
const schemasElement = document.getElementById("schemas");
|
23954
|
-
const schemaNames = Object.keys(window.metadata["schemas"]);
|
23955
|
-
schemaNames.forEach(function(schemaName) {
|
23956
|
-
const optionElement = document.createElement("option");
|
23957
|
-
optionElement.value = schemaName;
|
23958
|
-
optionElement.innerText = schemaName;
|
23959
|
-
schemasElement.appendChild(optionElement);
|
23960
|
-
});
|
23961
23954
|
const tablesElement = document.getElementById("tables");
|
23962
|
-
|
23955
|
+
const columnsElement = document.getElementById("columns");
|
23956
|
+
const indexesElement = document.getElementById("indexes");
|
23957
|
+
|
23958
|
+
const schemaNames = Object.keys(window.metadata["schemas"]);
|
23959
|
+
if (schemaNames.length == 1) {
|
23960
|
+
schemasElement.style.display = 'none';
|
23961
|
+
// TODO: duplicate code
|
23963
23962
|
while(tablesElement.firstChild) {
|
23964
23963
|
tablesElement.removeChild(tablesElement.firstChild);
|
23965
23964
|
}
|
23966
|
-
const schemaName =
|
23965
|
+
const schemaName = schemaNames[0];
|
23967
23966
|
const schema = window.metadata["schemas"][schemaName];
|
23968
23967
|
const tableNames = Object.keys(schema["tables"]);
|
23969
23968
|
tableNames.forEach(function(tableName) {
|
@@ -23972,9 +23971,29 @@ var sqlui = (function (exports) {
|
|
23972
23971
|
optionElement.innerText = tableName;
|
23973
23972
|
tablesElement.appendChild(optionElement);
|
23974
23973
|
});
|
23975
|
-
}
|
23976
|
-
|
23977
|
-
|
23974
|
+
} else {
|
23975
|
+
schemasElement.style.display = 'flex';
|
23976
|
+
schemaNames.forEach(function(schemaName) {
|
23977
|
+
const optionElement = document.createElement("option");
|
23978
|
+
optionElement.value = schemaName;
|
23979
|
+
optionElement.innerText = schemaName;
|
23980
|
+
schemasElement.appendChild(optionElement);
|
23981
|
+
});
|
23982
|
+
schemasElement.addEventListener("change", function() {
|
23983
|
+
while(tablesElement.firstChild) {
|
23984
|
+
tablesElement.removeChild(tablesElement.firstChild);
|
23985
|
+
}
|
23986
|
+
const schemaName = schemasElement.value;
|
23987
|
+
const schema = window.metadata["schemas"][schemaName];
|
23988
|
+
const tableNames = Object.keys(schema["tables"]);
|
23989
|
+
tableNames.forEach(function(tableName) {
|
23990
|
+
const optionElement = document.createElement("option");
|
23991
|
+
optionElement.value = tableName;
|
23992
|
+
optionElement.innerText = tableName;
|
23993
|
+
tablesElement.appendChild(optionElement);
|
23994
|
+
});
|
23995
|
+
});
|
23996
|
+
}
|
23978
23997
|
tablesElement.addEventListener("change", function() {
|
23979
23998
|
while(columnsElement.firstChild) {
|
23980
23999
|
columnsElement.removeChild(columnsElement.firstChild);
|
@@ -23982,7 +24001,7 @@ var sqlui = (function (exports) {
|
|
23982
24001
|
while(indexesElement.firstChild) {
|
23983
24002
|
indexesElement.removeChild(indexesElement.firstChild);
|
23984
24003
|
}
|
23985
|
-
const schemaName = schemasElement.value;
|
24004
|
+
const schemaName = schemaNames.length == 1 ? schemaNames[0] : schemasElement.value;
|
23986
24005
|
const tableName = tablesElement.value;
|
23987
24006
|
const table = window.metadata["schemas"][schemaName]["tables"][tableName];
|
23988
24007
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sqlui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Dower
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-core
|