临时看一个 SQLite 文件时,直接 select * 的输出经常挤在一起。SQLite 自带的命令行可以先设 .headers on 和 .mode box,字段边界会清楚很多。
环境:SQLite 3.33+。建个最小例子:
printf "create table task(id integer, name text, done integer); insert into task values (1, 'build', 0), (2, 'test', 1);" | sqlite3 demo.db
printf ".headers on\n.mode box\nselect * from task;" | sqlite3 demo.db
第二条命令会按带边框的表格打印列名和内容。只想给脚本消费时,再切回 .mode csv 或 .mode json,别把格式化输出当接口数据。
临时数据库看完可以删掉 demo.db,项目里的数据库文件还是按自己的备份和版本管理规则来。