Enhance SQL execution and visualization with multiple data sources#81
Merged
Conversation
- SQL 插件改用 sqlite3 -json 输出,console_type=sqltable - 新增 SqlTableView:解析 sqlite3 -json 输出(支持多结果集),渲染为表格,可切换原始输出,无 SELECT 输出时提示「无结果集」,渲染防抖 - 配置页输出类型增加「SQL 表格」;App 按 consoleType==='sqltable' 渲染
- 新增 run_sql 命令(rusqlite):逐条执行(UTF-8 安全的语句切分),查询返回结构化结果集,失败返回错误信息,支持指定数据库文件(空=内存) - App 对 SQL 走专用 runSql 路径(不再依赖外部 sqlite3 CLI) - SqlTableView:渲染错误框 + 非查询消息 + 多结果集表格(NULL 斜体),头部可选择/重置数据库文件(存 kv: sql-db-path) - SQL 插件标记为无需外部环境(始终可运行)
- 后端 run_sql 接收 DataSource(memory/sqlite/mysql),新增 MySQL 执行(mysql crate,rustls,逐语句执行返回结果集/错误);固定 mysql_common 构建依赖 subprocess=0.2.9 兼容当前 Rust - 设置新增「数据库」标签页(Database.vue):管理 MySQL/SQLite 连接(名称/主机/端口/账号/密码/库/文件),存数据库 - useDbConnections:连接列表 + 当前数据源引用(memory/conn:id/file) - SQL 结果区改为数据源下拉(内存/已配置连接/临时 SQLite 文件),运行时按所选数据源执行
- 新增 src-tauri/src/db/:mod.rs(共享 DataSource/SqlRunResult/split_sql + DbExecutor trait + 注册 + run_sql 命令),sqlite.rs / mysql.rs 各实现一个执行器 - 新增数据库类型只需加一个文件实现 DbExecutor 并在 executors() 注册一行 - 移除单文件 sql_exec.rs;main.rs 改用 crate::db::run_sql
抽出 SqlSourceSelect 组件;打开 .sql 文件时编辑器头部即显示数据源下拉(内存/已配置连接/临时 SQLite 文件),不必等运行后在输出面板里选。SqlTableView 复用同一组件
useDbConnections 在模块顶层读 KV,而该模块在 main.ts loadKvStore() 之前就被 import,缓存为空导致 connections 永远是空,再保存会覆盖掉库里的旧数据。改为首次调用 useDbConnections() 时(组件 setup,已在 loadKvStore 之后)才从缓存载入
- SqlSourceSelect 传 buttonClasses 缩小内边距(编辑器头/SQL结果头更紧凑) - Database 设置的类型选择由原生 select 改为 ui/Select 组件 - MarkdownView 清空按钮由文字改为 Trash2 图标
run_sql 执行后写入一条执行历史(code=SQL、stdout=结果集/消息摘要、stderr=错误、耗时、language=sql),与其它语言一致;ExecutionHistory::insert 开放为 pub(crate)。历史面板可见,恢复/重跑(走 runSql)正常
- run_sql 历史记录的 stdout 改存完整结果 JSON(而非文字摘要) - 抽出 SqlResultTable(纯表格渲染,无头部),SqlTableView 与执行历史详情共用 - 执行历史详情对 language=sql 用 SqlResultTable 渲染表格/错误,其它语言仍按文本
- 引入 echarts(按需模块化引入) - 新增可复用图表组件 charts/(与数据源解耦,后续 CSV 等可复用): - shape.ts: 表格数据按维度聚合(求和/计数/平均/最大/最小) - ChartPanel.vue: 拖拽字段到维度/指标配置图表,数值列自动识别 - BarChart.vue: echarts 柱状图渲染,支持横向/堆叠,配色跟随主题 - SqlTableView 增加 表格/图表 视图切换,图表基于首个结果集
- 维度改为多选: 首个作分类轴, 其余作分组维度(透视拆分系列) - 多指标 × 多分组自动组合为多条系列 - 新增聚合后排序(升/降序按指标合计)、显示前 N 项、数值标签开关 - shape.ts 用通用 pivot + sortAndLimit 替换单维度聚合
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.