Skip to content

Module: DB Manager

Claude edited this page Oct 23, 2026 · 5 revisions

Module: DB Manager

The DB Manager module provides a web interface for executing SQL queries directly against the database with query history tracking.

Overview

This module allows administrators to:

  • Execute arbitrary SQL queries against the database
  • View query results in a tabular format
  • Track query execution history with timing and row count metrics
  • Re-run previous queries from history

Features

  • Support for SELECT, INSERT, UPDATE, DELETE, PRAGMA, EXPLAIN, and WITH statements
  • Tabular display of SELECT query results
  • Row count and execution time metrics
  • Results capped at 1,000 rows (larger results are flagged as truncated, in the result and in the history) and a 10-second statement timeout reported as "query cancelled after 10s"
  • Query history with click-to-reload functionality
  • Keyboard shortcut (Ctrl+Enter) for quick execution

Admin Interface

Access at Admin > Modules > DB Manager or /admin/dbmanager.

Query Execution

  1. Enter your SQL query in the textarea
  2. Click Execute Query or press Ctrl+Enter
  3. View results below the query form

For SELECT queries, results are displayed in a table. For DML statements, the number of affected rows is shown.

Query History

The module maintains a history showing:

Column Description
Query The SQL statement (truncated preview)
Time When the query was executed
Duration Execution time in milliseconds
Rows Number of rows returned/affected
Status Success or Failed

Click any history row to reload that query into the editor.

Routes

Method Path Description
GET /admin/dbmanager Dashboard with query form and history
POST /admin/dbmanager/execute Execute a SQL query

Example Queries

View table structure

PRAGMA table_info(pages);

List all tables

SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;

Count records

SELECT COUNT(*) as total FROM pages WHERE status = 'published';

View recent pages

SELECT id, title, slug, status, created_at
FROM pages ORDER BY created_at DESC LIMIT 10;

Best Practices

  1. Backup before modifications — Always backup before running UPDATE or DELETE
  2. Test queries first — Use SELECT to verify WHERE clauses before modifying data
  3. Use transactions — For complex modifications, wrap in transactions
  4. Review history — Check query history to audit database operations

Security

  • Protected by admin authentication middleware (admin users only)
  • CSRF validation on POST requests
  • Complete query history logging for audit purposes
  • Inactive by default on new installs; enable it from Admin > Modules only while it is needed
  • Activating it asks for the administrator's current password (wrong attempts count toward the login lockout); once active, queries need none, so switch it off when done
  • Results are capped at 1,000 rows and each statement is cancelled after 10 seconds
  • Query execution is refused in demo mode (the history stays visible)

Clone this wiki locally