sqlui 0.1.29 → 0.1.30
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 +4 -4
- data/.version +1 -1
- data/app/server.rb +4 -0
- data/client/resources/sqlui.css +1 -1
- data/client/resources/sqlui.js +26 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a936a2e2476462ad9d92ed315bc02bee65b7c84171d5934e9728241f7a28ba1c
|
4
|
+
data.tar.gz: 2cf060fb96f672ebaf6b7fd9be602652e1a30841ded45c28415d7cc3dabc03e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: addfac3cd62b75320dfcd2a437dac79db358b69391782f008e49be816241c1dad40d641accd078735c46de1d855eaf162956cc2a16370c297a72175e8b0bb7a2
|
7
|
+
data.tar.gz: 2a215084e23ac9b7c11d44f325fc27c77a597d3c9ed6f5e1ded238aa7223d82936f6d475674cb777406d491f4699f2a782cafabaf7c36d24be83d72e3eb998e8
|
data/.version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.30
|
data/app/server.rb
CHANGED
@@ -86,6 +86,7 @@ class Server < Sinatra::Base
|
|
86
86
|
|
87
87
|
full_sql = params[:sql]
|
88
88
|
sql = params[:sql]
|
89
|
+
variables = params[:variables] || {}
|
89
90
|
if params[:selection]
|
90
91
|
selection = params[:selection]
|
91
92
|
if selection.include?('-')
|
@@ -106,6 +107,9 @@ class Server < Sinatra::Base
|
|
106
107
|
end
|
107
108
|
|
108
109
|
result = database.with_client do |client|
|
110
|
+
variables.each do |name, value|
|
111
|
+
client.query("SET @#{name} = #{value};")
|
112
|
+
end
|
109
113
|
execute_query(client, sql)
|
110
114
|
end
|
111
115
|
|
data/client/resources/sqlui.css
CHANGED
data/client/resources/sqlui.js
CHANGED
@@ -24369,7 +24369,8 @@
|
|
24369
24369
|
method: 'POST',
|
24370
24370
|
body: JSON.stringify({
|
24371
24371
|
sql: sqlFetch.sql,
|
24372
|
-
selection: sqlFetch.selection
|
24372
|
+
selection: sqlFetch.selection,
|
24373
|
+
variables: sqlFetch.variables
|
24373
24374
|
}),
|
24374
24375
|
signal: sqlFetch.fetchController.signal
|
24375
24376
|
})
|
@@ -24413,6 +24414,16 @@
|
|
24413
24414
|
});
|
24414
24415
|
}
|
24415
24416
|
|
24417
|
+
function parseSqlVariables (params) {
|
24418
|
+
return Object.fromEntries(
|
24419
|
+
Array.from(params).filter(([key]) => {
|
24420
|
+
return key.match(/^_.+/)
|
24421
|
+
}).map(([key, value]) => {
|
24422
|
+
return [key.replace(/^_/, ''), value]
|
24423
|
+
})
|
24424
|
+
)
|
24425
|
+
}
|
24426
|
+
|
24416
24427
|
function maybeFetchResult (internal) {
|
24417
24428
|
const url = new URL(window.location);
|
24418
24429
|
const params = url.searchParams;
|
@@ -24420,6 +24431,7 @@
|
|
24420
24431
|
const file = params.get('file');
|
24421
24432
|
const selection = params.get('selection');
|
24422
24433
|
const hasSqluiReferrer = document.referrer && new URL(document.referrer).origin === url.origin;
|
24434
|
+
const variables = parseSqlVariables(params);
|
24423
24435
|
|
24424
24436
|
// Only allow auto-run if coming from another SQLUI page. The idea here is to let the app link to URLs with run=true
|
24425
24437
|
// but not other apps. This allows meta/shift-clicking to run a query.
|
@@ -24440,8 +24452,9 @@
|
|
24440
24452
|
const selectionMatches = selection === existingRequest.selection;
|
24441
24453
|
const sqlMatches = params.has('sql') && sql === existingRequest.sql;
|
24442
24454
|
const fileMatches = params.has('file') && file === existingRequest.file;
|
24455
|
+
const variablesMatch = JSON.stringify(variables) === JSON.stringify(existingRequest.variables);
|
24443
24456
|
const queryMatches = sqlMatches || fileMatches;
|
24444
|
-
if (selectionMatches && queryMatches) {
|
24457
|
+
if (selectionMatches && queryMatches && variablesMatch) {
|
24445
24458
|
displaySqlFetch(existingRequest);
|
24446
24459
|
if (params.has('selection')) {
|
24447
24460
|
focus();
|
@@ -24453,7 +24466,7 @@
|
|
24453
24466
|
|
24454
24467
|
clearResult();
|
24455
24468
|
|
24456
|
-
const sqlFetch = buildSqlFetch(sql, file, selection);
|
24469
|
+
const sqlFetch = buildSqlFetch(sql, file, variables, selection);
|
24457
24470
|
if (params.has('sql') || params.has('file')) {
|
24458
24471
|
setValue(sqlFetch.sql);
|
24459
24472
|
if (run) {
|
@@ -24466,7 +24479,7 @@
|
|
24466
24479
|
}
|
24467
24480
|
}
|
24468
24481
|
|
24469
|
-
function buildSqlFetch (sql, file, selection) {
|
24482
|
+
function buildSqlFetch (sql, file, variables, selection) {
|
24470
24483
|
const sqlFetch = {
|
24471
24484
|
fetchController: new AbortController(),
|
24472
24485
|
state: 'pending',
|
@@ -24475,7 +24488,8 @@
|
|
24475
24488
|
finished: null,
|
24476
24489
|
sql,
|
24477
24490
|
file,
|
24478
|
-
selection
|
24491
|
+
selection,
|
24492
|
+
variables
|
24479
24493
|
};
|
24480
24494
|
|
24481
24495
|
if (file) {
|
@@ -24531,7 +24545,7 @@
|
|
24531
24545
|
}
|
24532
24546
|
|
24533
24547
|
clearResultBox();
|
24534
|
-
displaySqlFetchResultStatus('result-status', fetch
|
24548
|
+
displaySqlFetchResultStatus('result-status', fetch);
|
24535
24549
|
|
24536
24550
|
const tableElement = document.createElement('table');
|
24537
24551
|
tableElement.id = 'result-table';
|
@@ -24647,7 +24661,7 @@
|
|
24647
24661
|
throw new Error(`unexpected fetch sql request status: ${fetch.status}`)
|
24648
24662
|
}
|
24649
24663
|
clearGraphBox();
|
24650
|
-
displaySqlFetchResultStatus('graph-status', fetch
|
24664
|
+
displaySqlFetchResultStatus('graph-status', fetch);
|
24651
24665
|
|
24652
24666
|
if (!fetch.result.rows) {
|
24653
24667
|
return
|
@@ -24686,13 +24700,15 @@
|
|
24686
24700
|
chart.draw(dataTable, options);
|
24687
24701
|
}
|
24688
24702
|
|
24689
|
-
function displaySqlFetchResultStatus (statusElementId,
|
24703
|
+
function displaySqlFetchResultStatus (statusElementId, sqlFetch) {
|
24704
|
+
const result = sqlFetch.result;
|
24690
24705
|
const statusElement = document.getElementById(statusElementId);
|
24706
|
+
const elapsed = Math.round(100 * (window.performance.now() - sqlFetch.startedAt) / 1000.0) / 100;
|
24691
24707
|
|
24692
24708
|
if (result.total_rows === 1) {
|
24693
|
-
statusElement.innerText = `${result.total_rows} row`;
|
24709
|
+
statusElement.innerText = `${result.total_rows} row (${elapsed}s)`;
|
24694
24710
|
} else {
|
24695
|
-
statusElement.innerText = `${result.total_rows} rows`;
|
24711
|
+
statusElement.innerText = `${result.total_rows} rows (${elapsed}s)`;
|
24696
24712
|
}
|
24697
24713
|
|
24698
24714
|
if (result.total_rows > result.rows.length) {
|