# TsvSqlViewer **Repository Path**: serious_Sam/tsv-sql-viewer ## Basic Information - **Project Name**: TsvSqlViewer - **Description**: Query and modify Tsv file via SQL - **Primary Language**: JavaScript - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-05-20 - **Last Updated**: 2026-05-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # TSV SQL Viewer An experimental VS Code extension for querying and updating `TSV` files with DuckDB SQL. A VS Code extension prototype for querying and updating `TSV` files with DuckDB SQL. 一个使用 DuckDB SQL 查询和更新 `TSV` 文件的 VS Code 扩展原型。 ## English ### Features - `*.tsv` files still open as normal text files by default - You can switch to the TSV Query view from the editor title action - Uses DuckDB (`@duckdb/node-api`) to run `SELECT / UPDATE / DELETE / INSERT` - Updates are first applied in the current session, then written back to the original TSV file - Automatically maps raw TSV headers to safe SQL column names and shows the mapping in the UI - Query results are previewed with a 200-row cap to avoid rendering very large result sets at once - Includes basic column type inference for `BOOLEAN / BIGINT / DOUBLE / TEXT` ### Development ```bash npm install npm run build ``` Then run the extension development host in VS Code: 1. Open this project in VS Code 2. Start `Run Extension` 3. Open any `*.tsv` file in the new window 4. Click `Open TSV Query View` in the editor title area ### Usage The table name is fixed as: ```sql tsv_data ``` Example query: ```sql SELECT * FROM tsv_data ORDER BY name DESC LIMIT 200; ``` Example update: ```sql UPDATE tsv_data SET status = 'done' WHERE owner = 'sam'; ``` After running an update, click `Write Back TSV` in the query view to persist the changes back to the TSV file. ### Current Limitations - The current version still relies on `CustomTextEditor`, so VS Code reads the whole TSV file as text first - Writing changes back still requires exporting the current in-memory result to a full TSV file - The result preview is capped at 200 rendered rows - Type inference is conservative and falls back to `TEXT` when a column contains mixed formats - The next major step should be moving to a true large-file document model instead of relying on the text editor pipeline ## 中文 ### 当前能力 - `*.tsv` 默认仍按普通文本打开 - 可通过编辑器右上角的 `Open TSV Query View` 入口切换到 TSV Query 视图 - 内置 DuckDB(`@duckdb/node-api`)执行 `SELECT / UPDATE / DELETE / INSERT` - 更新先作用于当前会话,点击 `Write Back TSV` 后覆盖原文件 - 自动把原始表头映射成安全的 SQL 列名,并在界面里展示映射关系 - 查询结果只预读前 200 行,避免一次性把大结果集全量拉进界面 - 支持基础列类型推断,目前会识别 `BOOLEAN / BIGINT / DOUBLE / TEXT` ### 开发 ```bash npm install npm run build ``` 然后在 VS Code 中运行扩展开发宿主: 1. 打开本项目 2. 执行 `Run Extension` 3. 在新窗口中打开任意 `*.tsv` 文件 4. 点击编辑器右上角的 `Open TSV Query View` ### 使用方式 表名固定为: ```sql tsv_data ``` 示例查询: ```sql SELECT * FROM tsv_data ORDER BY name DESC LIMIT 200; ``` 示例更新: ```sql UPDATE tsv_data SET status = 'done' WHERE owner = 'sam'; ``` 执行更新后,点击界面中的 `Write Back TSV` 即可持久化。 ### 当前限制 - 当前版本仍基于 `CustomTextEditor`,VS Code 打开文件时依然会先把整个 TSV 作为文本载入 - 写回 TSV 时仍需要把当前结果完整导出一次 - 查询结果展示最多渲染前 200 行 - 列类型推断是保守策略,遇到混合格式会自动降级成 `TEXT` - 下一步应该把文档模型改成真正面向大文件的自定义文档,而不是直接依赖文本编辑器