This commit is contained in:
Lizandro Guarnizo
2026-06-02 13:27:45 -05:00
parent 28d0eae715
commit c5603c51f8
2 changed files with 11 additions and 37 deletions
-35
View File
@@ -283,41 +283,6 @@
</div>
</div>
</div>
<div class="relative">
<textarea id="sql-editor" x-model="sqlText"
@input.debounce.150ms="onSqlInput()"
@keydown="onSqlKeydown($event)"
@keydown.ctrl.enter.prevent="runQuery()"
@keydown.meta.enter.prevent="runQuery()"
@scroll="closeAutocomplete()"
@click="closeAutocomplete()"
:placeholder="isMongo ? 'db.coleccion.find({})\n// Ctrl+Enter para ejecutar\n// db.coleccion.insertOne({campo: \'valor\'})' : isRedis ? '# Comandos Redis (uno por línea)\nKEYS *\nGET mi_clave\nHGETALL mi_hash\n# Ctrl+Enter para ejecutar' : '-- Escribe tu consulta SQL aquí\n-- Ctrl+Enter para ejecutar\nSELECT * FROM tabla LIMIT 100;'"
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;"></textarea>
<!-- Autocomplete dropdown -->
<div x-show="autocompleteVisible" x-cloak
x-ref="autocomplete"
:style="'position:absolute;left:'+autocompletePos.left+'px;top:'+autocompletePos.top+'px;z-index:100;'"
class="bg-white border border-gray-300 rounded-lg shadow-xl max-h-48 overflow-y-auto min-w-[160px]">
<template x-for="(item, i) in autocompleteItems" :key="i">
<div @click="selectAutocomplete(i)"
class="px-3 py-1.5 text-xs font-mono cursor-pointer flex items-center gap-2"
:class="i === autocompleteIdx ? 'bg-[#8eb02f] text-white' : 'hover:bg-gray-100 text-gray-700'">
<span x-text="item.label"></span>
<span class="ml-auto text-[9px] opacity-60" x-text="item.type"></span>
</div>
</template>
</div>
<!-- Typo suggestions -->
<div x-show="typoSuggestions.length > 0" x-cloak class="mt-1 flex flex-wrap gap-1">
<template x-for="(s, i) in typoSuggestions" :key="i">
<button @click="applyTypoFix(s)"
class="text-[10px] px-2 py-0.5 rounded bg-yellow-50 border border-yellow-200 text-yellow-700 hover:bg-yellow-100 transition font-mono">
¿Quisiste decir: <span class="font-semibold" x-text="s"></span>?
</button>
</template>
</div>
</div>
<!-- ─── Helpers SQL (solo MySQL/PostgreSQL, no Redis) ─── -->
<div x-show="!isMongo && !isRedis && selectedConxId" class="mt-1.5">
<!-- Chips rápidos -->
+11 -2
View File
@@ -298,8 +298,14 @@ func UpdateCellHandler(c *fiber.Ctx) error {
valueSQL = "'" + strings.ReplaceAll(body.Value, "'", "''") + "'"
}
sqlText := fmt.Sprintf("UPDATE %s SET %s = %s WHERE %s = '%s'",
qTable, qCol, valueSQL, qPkCol, strings.ReplaceAll(body.PkValue, "'", "''"))
// Determinar si pk_value es numérico para no entrecomillarlo
pkValueSQL := "'" + strings.ReplaceAll(body.PkValue, "'", "''") + "'"
if _, err := strconv.ParseFloat(body.PkValue, 64); err == nil {
pkValueSQL = body.PkValue
}
sqlText := fmt.Sprintf("UPDATE %s SET %s = %s WHERE %s = %s",
qTable, qCol, valueSQL, qPkCol, pkValueSQL)
result := services.ExecuteSQL(conx, body.Database, sqlText)
if result.Error != "" {
@@ -524,6 +530,9 @@ SQL original:
%s
SQL optimizado:`, sql)
case "nl2sql":
// El prompt ya viene construido desde NL2SQLHandler (incluye esquema + descripción)
prompt = sql
default:
prompt = fmt.Sprintf(`Eres un experto en SQL. Ayuda con esta consulta SQL. Devuelve SOLO el SQL resultante, sin explicaciones.