feat: Query Runner — editor SQL con historial, exportar CSV/JSON, árbol de tablas

This commit is contained in:
Lizandro Guarnizo
2026-05-01 11:14:09 -05:00
parent 357bdc7397
commit 1731855df8
11 changed files with 1781 additions and 1 deletions
+45
View File
@@ -0,0 +1,45 @@
package models
import (
"time"
"github.com/sujit-baniya/fiber-boilerplate/app"
"gorm.io/gorm"
)
// QueryHistory almacena el historial de consultas ejecutadas por los usuarios.
type QueryHistory struct {
gorm.Model
ConxDbID uint `json:"conx_db_id" gorm:"column:conx_db_id;index"`
ConxDb ConxDb `json:"conx_db" gorm:"foreignKey:ConxDbID"`
SQL string `json:"sql" gorm:"column:sql;type:text"`
Status string `json:"status" gorm:"column:status"` // ok | error
ErrorMsg string `json:"error_msg" gorm:"column:error_msg;type:text"`
RowsAffect int64 `json:"rows_affect" gorm:"column:rows_affect"`
DurationMs int64 `json:"duration_ms" gorm:"column:duration_ms"`
ExecutedAt time.Time `json:"executed_at" gorm:"column:executed_at;autoCreateTime"`
}
func (QueryHistory) TableName() string {
return "query_history"
}
// SaveQueryHistory guarda una entrada en el historial.
func SaveQueryHistory(h QueryHistory) error {
return app.Http.Database.DB.Create(&h).Error
}
// GetQueryHistory devuelve el historial de una conexión con paginación.
func GetQueryHistory(conxDbID uint, limit, offset int) ([]QueryHistory, int64, error) {
var items []QueryHistory
var total int64
db := app.Http.Database.DB.Model(&QueryHistory{}).Where("conx_db_id = ?", conxDbID)
db.Count(&total)
err := db.Order("executed_at DESC").Limit(limit).Offset(offset).Find(&items).Error
return items, total, err
}
// DeleteQueryHistory elimina todo el historial de una conexión.
func DeleteQueryHistory(conxDbID uint) error {
return app.Http.Database.DB.Where("conx_db_id = ?", conxDbID).Delete(&QueryHistory{}).Error
}