From 34f2c3e582e47aa41bcf380859ca0daf27050b98 Mon Sep 17 00:00:00 2001
From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com>
Date: Wed, 20 May 2026 11:14:11 -0500
Subject: [PATCH] feat(query-runner): helpers DBA para conexiones SQL
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- Chips rápidos: SHOW DATABASES, SHOW TABLES, SHOW USERS, SHOW GRANTS,
SHOW PROCESSLIST, SHOW CREATE TABLE, DESCRIBE, info_schema engine/charset
- Generador DBA (collapsible): form con BD, usuario, host y contraseña
Operaciones: Setup completo | CREATE DATABASE | CREATE USER | GRANT ALL |
REVOKE | SHOW GRANTS | DROP USER | DROP DATABASE
- Setup completo genera las 3 sentencias en bloque con comentarios
- Visible só
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
resources/views/query_runner.html | 120 ++++++++++++++++++++++++++++++
1 file changed, 120 insertions(+)
diff --git a/resources/views/query_runner.html b/resources/views/query_runner.html
index b46b17b..5ed0631 100644
--- a/resources/views/query_runner.html
+++ b/resources/views/query_runner.html
@@ -174,6 +174,83 @@
class="w-full bg-gray-900 text-gray-100 font-mono text-sm p-4 resize-none outline-none leading-relaxed"
style="height:180px; tab-size:2;">
+
+
@@ -369,6 +446,20 @@ document.addEventListener('alpine:init', () => {
loadingFields: false,
showUpdateBuilder: false,
updateBuilder: { collection: '', field: '', value: '', filterField: '_id', filterValue: '""', op: '$set', multi: 'one' },
+
+ // SQL DBA helpers
+ showDbHelper: false,
+ dbHelper: { db: '', user: '', pass: '', host: '%', op: 'full_setup' },
+ sqlHelpers: [
+ { label: 'SHOW DATABASES', cmd: 'SHOW DATABASES;' },
+ { label: 'SHOW TABLES', cmd: 'SHOW TABLES;' },
+ { label: 'SHOW USERS', cmd: "SELECT User, Host, plugin FROM mysql.user ORDER BY User;" },
+ { label: 'SHOW GRANTS (actual)',cmd: 'SHOW GRANTS FOR CURRENT_USER;' },
+ { label: 'SHOW PROCESSLIST', cmd: 'SHOW FULL PROCESSLIST;' },
+ { label: 'SHOW CREATE TABLE', cmd: 'SHOW CREATE TABLE nombre_tabla;' },
+ { label: 'DESC tabla', cmd: 'DESCRIBE nombre_tabla;' },
+ { label: 'ENGINE/CHARSET', cmd: "SELECT table_name, engine, table_collation FROM information_schema.tables WHERE table_schema = DATABASE();" },
+ ],
mongoExamples: [
{ label: 'find()', cmd: 'db.coleccion.find({})' },
{ label: 'findOne()', cmd: 'db.coleccion.findOne({})' },
@@ -603,6 +694,35 @@ document.addEventListener('alpine:init', () => {
this.sqlText = `db.${col}.${method}(\n { "${filterField}": ${filterValue} },\n { "${op}": ${updateDoc} }\n)`;
},
+ generateDbHelper() {
+ const db = this.dbHelper.db || 'nombre_bd';
+ const user = this.dbHelper.user || 'usuario_app';
+ const host = this.dbHelper.host || '%';
+ const pass = this.dbHelper.pass || 'Contraseña123!';
+
+ const createDb = `CREATE DATABASE IF NOT EXISTS \`${db}\`\n CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;`;
+ const createUser = `CREATE USER IF NOT EXISTS '${user}'@'${host}' IDENTIFIED BY '${pass}';`;
+ const grant = `GRANT ALL PRIVILEGES ON \`${db}\`.* TO '${user}'@'${host}';\nFLUSH PRIVILEGES;`;
+ const revoke = `REVOKE ALL PRIVILEGES ON \`${db}\`.* FROM '${user}'@'${host}';\nFLUSH PRIVILEGES;`;
+ const showGrants = `SHOW GRANTS FOR '${user}'@'${host}';`;
+ const dropUser = `DROP USER IF EXISTS '${user}'@'${host}';\nFLUSH PRIVILEGES;`;
+ const dropDb = `DROP DATABASE IF EXISTS \`${db}\`;`;
+
+ const map = {
+ full_setup: `-- 1. Crear base de datos\n${createDb}\n\n-- 2. Crear usuario\n${createUser}\n\n-- 3. Dar permisos totales\n${grant}`,
+ create_db: createDb,
+ create_user: createUser,
+ grant: grant,
+ revoke: revoke,
+ show_grants: showGrants,
+ drop_user: dropUser,
+ drop_db: dropDb,
+ };
+
+ this.sqlText = map[this.dbHelper.op] || '';
+ document.getElementById('sql-editor')?.focus();
+ },
+
clearEditor() { this.sqlText = ''; this.results = []; this.columns = []; this.statusMsg = ''; },
nullStr(v) { return v === null || v === undefined ? 'NULL' : String(v); },