LibrePortal/scripts/database/tables/db_display_tables.sh
librelad 875a60f90f LibrePortal v0.1.0 — initial release
A free, open, self-hosted app platform (GNU AGPLv3): one-click app deploys,
Traefik reverse proxy with automatic SSL, rootless Docker support, gluetun
VPN routing, and a web dashboard to manage it all.

Free & open forever to self-host; optional paid hosted services fund it.
See PROMISE.md.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

Signed-off-by: librelad <librelad@digitalangels.vip>
2026-05-21 20:37:54 +01:00

61 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
databaseDisplayTables()
{
if [[ "$toollistalltables" == [yY] ]]; then
local table_number=0
local selected_table=""
local sorted_tables=()
isHeader "View Database Table Data"
while true; do
# Check if sqlite3 is available
if ! command -v sudo sqlite3 &> /dev/null; then
isNotice "sqlite3 command not found. Make sure it's installed."
fi
# Ensure the database file exists
if [ ! -f "$docker_dir/$db_file" ]; then
isNotice "Database file not found: $docker_dir/$db_file"
fi
# Get a list of existing tables in the database
local tables_list=($(sudo sqlite3 "$docker_dir/$db_file" ".tables"))
# Sort the tables alphabetically
sorted_tables=($(printf "%s\n" "${tables_list[@]}" | sort))
# Check if there are any tables in the database
if [ "${#sorted_tables[@]}" -eq 0 ]; then
isError "No tables found in the database."
fi
table_number=0
for table_name in "${sorted_tables[@]}"; do
table_number=$((table_number+1))
echo "$table_number. $table_name"
done
echo ""
isQuestion "Enter the number of the table to view data (x to exit): "
read -p "" selected_table
if [[ "$selected_table" == "x" ]]; then
echo ""
echo "Exiting."
elif [[ "$selected_table" =~ ^[0-9]+$ ]] && ((selected_table >= 1)) && ((selected_table <= "${#sorted_tables[@]}")); then
selected_table="${sorted_tables[$((selected_table-1))]}"
# Display all data for the selected table with formatted output
isHeader "Displaying $selected_table Table Data"
sudo sqlite3 -column -header "$docker_dir/$db_file" "SELECT * FROM $selected_table;"
echo ""
isQuestion "Press Enter to continue..."
read -p "" input
else
isNotice "Invalid table number. Please try again."
fi
done
fi
}