solid_litequeen 0.6.2 → 0.8.0
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/app/controllers/solid_litequeen/databases_controller.rb +35 -3
- data/app/helpers/solid_litequeen/application_helper.rb +5 -0
- data/app/views/layouts/solid_litequeen/application.html.erb +4 -3
- data/app/views/solid_litequeen/_database-selector.html.erb +25 -0
- data/app/views/solid_litequeen/databases/index.html.erb +5 -4
- data/app/views/solid_litequeen/databases/table_rows.html.erb +13 -1
- data/lib/solid_litequeen/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce04a632e602957b48d2bd64d2ad207621e8da3e20de6dc9fe7f3cb831b343d9
|
4
|
+
data.tar.gz: 0dd4d0ca3fc6a0c152a406568f8e0836734b42c456ed83f82824547bfe8661c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7bd81c0a47b0ae3d06c1442a6a0459fa73a5b8eacc3814fdb6d97935f8c64194cdb9ea1a4044504293b33a729d49c1de348aed15f267ac158368f857240fece
|
7
|
+
data.tar.gz: a46276c2d8128c73f58db823b7e3b723a72a3a09fab87742a2c4686ffbddc51f014a181b484390fcac1a51273e9a57b316ae6a8bd1e8fabeba6d824b409874d3
|
@@ -29,17 +29,49 @@ module SolidLitequeen
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def table_rows
|
32
|
-
database_id = params.expect(:database_id)
|
32
|
+
@database_id = params.expect(:database_id)
|
33
33
|
@table_name = params.expect(:table)
|
34
34
|
|
35
|
-
|
35
|
+
# Create a unique key for this table's sort preferences
|
36
|
+
sort_key = "#{@database_id}_#{@table_name}_sort"
|
37
|
+
|
38
|
+
# Update session if new sort params are provided
|
39
|
+
if params[:sort_column].present?
|
40
|
+
session[sort_key] = {
|
41
|
+
sort_column: params[:sort_column].to_s,
|
42
|
+
sort_direction: (params[:sort_direction]&.upcase == "DESC" ? "DESC" : "ASC")
|
43
|
+
}.stringify_keys # Ensure all keys are strings in session
|
44
|
+
end
|
45
|
+
|
46
|
+
# Get sort preferences from session or set defaults with string keys
|
47
|
+
sort_prefs = session[sort_key]&.with_indifferent_access || {
|
48
|
+
"sort_column" => nil,
|
49
|
+
"sort_direction" => "ASC"
|
50
|
+
}
|
51
|
+
|
52
|
+
@sort_column = sort_prefs["sort_column"]
|
53
|
+
@sort_direction = sort_prefs["sort_direction"]
|
54
|
+
|
55
|
+
@database_location = Base64.urlsafe_decode64(@database_id)
|
36
56
|
|
37
57
|
DynamicDatabase.establish_connection(
|
38
58
|
adapter: "sqlite3",
|
39
59
|
database: @database_location
|
40
60
|
)
|
41
61
|
|
42
|
-
|
62
|
+
# Verify the sort column exists in the table to prevent SQL injection
|
63
|
+
valid_columns = DynamicDatabase.connection.columns(@table_name).map(&:name)
|
64
|
+
|
65
|
+
order_clause = if @sort_column.present? && valid_columns.include?(@sort_column)
|
66
|
+
"#{DynamicDatabase.connection.quote_column_name(@sort_column)} #{@sort_direction}"
|
67
|
+
end
|
68
|
+
|
69
|
+
sql = [ "SELECT * FROM #{@table_name}" ]
|
70
|
+
sql << "ORDER BY #{order_clause}" if order_clause
|
71
|
+
sql << "LIMIT 50"
|
72
|
+
|
73
|
+
|
74
|
+
@data = DynamicDatabase.connection.select_all(sql.join(" "))
|
43
75
|
@row_count = row_count = DynamicDatabase.connection.select_value("SELECT COUNT(*) FROM #{@table_name}").to_i
|
44
76
|
end
|
45
77
|
|
@@ -1,4 +1,9 @@
|
|
1
1
|
module SolidLitequeen
|
2
2
|
module ApplicationHelper
|
3
|
+
def available_databases
|
4
|
+
@available_databases ||= ActiveRecord::Base.configurations.configurations.select do |config|
|
5
|
+
config.adapter == "sqlite3" && config.env_name == Rails.env && config.database.present?
|
6
|
+
end
|
7
|
+
end
|
3
8
|
end
|
4
9
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
<% if controller.controller_name == "databases" && action_name.in?([ "show", "table_rows"]) %>
|
3
|
+
<div class="w-86">
|
4
|
+
<div class="database-selector p-4">
|
5
|
+
<select id="database-select" class="block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500">
|
6
|
+
<option value="">Select a database...</option>
|
7
|
+
<% available_databases.each do |db| %>
|
8
|
+
<option value="<%= Base64.urlsafe_encode64(db.database) %>" <%= 'selected' if defined?(@database_id) && @database_id == Base64.urlsafe_encode64(db.database) %>>
|
9
|
+
<%= db.database %>
|
10
|
+
</option>
|
11
|
+
<% end %>
|
12
|
+
</select>
|
13
|
+
|
14
|
+
<script>
|
15
|
+
document.getElementById('database-select').addEventListener('change', function() {
|
16
|
+
if (this.value) {
|
17
|
+
window.location.href = '<%= database_path("") %>' + this.value;
|
18
|
+
}
|
19
|
+
});
|
20
|
+
</script>
|
21
|
+
</div>
|
22
|
+
|
23
|
+
</div>
|
24
|
+
<% end %>
|
25
|
+
|
@@ -3,12 +3,12 @@
|
|
3
3
|
<h1 class="text-3xl font-bold text-gray-900 mb-6">Solid Lite Queen</h1>
|
4
4
|
|
5
5
|
<div class="mb-6">
|
6
|
-
<p class="text-gray-600"><%= pluralize(
|
6
|
+
<p class="text-gray-600"><%= pluralize(available_databases.count, "SQLite database") %> found</p>
|
7
7
|
</div>
|
8
8
|
|
9
|
-
<% if
|
9
|
+
<% if available_databases.any? %>
|
10
10
|
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
|
11
|
-
<%
|
11
|
+
<% available_databases.each do |db| %>
|
12
12
|
<a href="<%= database_path(Base64.urlsafe_encode64(db.database)) %>" class="block bg-white rounded-lg shadow-sm border border-gray-200 hover:shadow-md transition duration-150 overflow-hidden">
|
13
13
|
<div class="p-5">
|
14
14
|
<div class="flex items-center justify-between mb-2">
|
@@ -34,4 +34,5 @@
|
|
34
34
|
</div>
|
35
35
|
<% end %>
|
36
36
|
|
37
|
-
</div>
|
37
|
+
</div>
|
38
|
+
|
@@ -21,7 +21,19 @@
|
|
21
21
|
<thead class="">
|
22
22
|
<tr class="bg-gray-100 border-b border-gray-200">
|
23
23
|
<% @data.columns.each do |column| %>
|
24
|
-
<th class="px-6 py-3 text-left text-sm font-medium text-gray-700 whitespace-nowrap"
|
24
|
+
<th class="px-6 py-3 text-left text-sm font-medium text-gray-700 whitespace-nowrap">
|
25
|
+
<%#= column %>
|
26
|
+
|
27
|
+
<%= link_to column,
|
28
|
+
database_table_rows_path(
|
29
|
+
database_id: @database_id,
|
30
|
+
table: @table_name,
|
31
|
+
sort_column: column,
|
32
|
+
sort_direction: (@sort_column == column && @sort_direction == 'ASC') ? 'DESC' : 'ASC'
|
33
|
+
) %>
|
34
|
+
<%= '▼' if @sort_column == column && @sort_direction == 'DESC' %>
|
35
|
+
<%= '▲' if @sort_column == column && @sort_direction == 'ASC' %>
|
36
|
+
</th>
|
25
37
|
<% end %>
|
26
38
|
</tr>
|
27
39
|
</thead>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solid_litequeen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vik Borges
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-03-
|
11
|
+
date: 2025-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -165,6 +165,7 @@ files:
|
|
165
165
|
- app/mailers/solid_litequeen/application_mailer.rb
|
166
166
|
- app/models/solid_litequeen/application_record.rb
|
167
167
|
- app/views/layouts/solid_litequeen/application.html.erb
|
168
|
+
- app/views/solid_litequeen/_database-selector.html.erb
|
168
169
|
- app/views/solid_litequeen/databases/index.html.erb
|
169
170
|
- app/views/solid_litequeen/databases/show.html.erb
|
170
171
|
- app/views/solid_litequeen/databases/table_rows.html.erb
|