From c29166f24e183615ff6f5e22ff3f357bbd9004b8 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Sat, 2 May 2026 08:18:20 -0500 Subject: [PATCH] Update query_runner.html --- resources/views/query_runner.html | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/resources/views/query_runner.html b/resources/views/query_runner.html index 5164df9..b46b17b 100644 --- a/resources/views/query_runner.html +++ b/resources/views/query_runner.html @@ -229,8 +229,11 @@ +

+ Los strings se auto-encierran en comillas. Para JSON explícito usa "valor", 123, true, {}. +

El campo será eliminado del documento.
@@ -568,14 +571,32 @@ document.addEventListener('alpine:init', () => { document.getElementById('sql-editor')?.focus(); }, + // Convierte un valor crudo ingresado por el usuario a JSON válido. + // Si ya es un literal JSON (num, bool, null, string entre comillas, objeto/array) + // lo deja intacto; de lo contrario lo trata como string y lo envuelve en comillas. + toJsonValue(raw) { + const s = (raw || '').trim(); + if (s === '') return '""'; + // Ya es string JSON, número, bool, null, objeto o array + if (/^".*"$/.test(s)) return s; + if (s === 'true' || s === 'false' || s === 'null') return s; + if (/^-?\d+(\.\d+)?([eE][+-]?\d+)?$/.test(s)) return s; + if ((s.startsWith('{') && s.endsWith('}')) || (s.startsWith('[') && s.endsWith(']'))) return s; + // Bare string → escapar y envolver en comillas + const escaped = s.replace(/\\/g, '\\\\').replace(/"/g, '\\"'); + return `"${escaped}"`; + }, + generateUpdate() { const col = this.updateBuilder.collection || this.selectedCollection || 'coleccion'; const field = this.updateBuilder.field || 'campo'; - const value = this.updateBuilder.value || '"nuevo_valor"'; + const rawValue = this.updateBuilder.value || '"nuevo_valor"'; const filterField = this.updateBuilder.filterField || '_id'; - const filterValue = this.updateBuilder.filterValue || '""'; + const rawFilter = this.updateBuilder.filterValue || '""'; const op = this.updateBuilder.op || '$set'; const method = this.updateBuilder.multi === 'many' ? 'updateMany' : 'updateOne'; + const value = this.toJsonValue(rawValue); + const filterValue = this.toJsonValue(rawFilter); let updateDoc; if (op === '$unset') updateDoc = `{ "${field}": "" }`; else updateDoc = `{ "${field}": ${value} }`;