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;"> + +
+ +
+ +
+ + +
+ +
+
+
+ + + + + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +

Se insertará tal cual en el SQL generado.

+
+
+
+ +
+
+
+
+
@@ -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); },