背景
都知道xls的表格编辑功能无与伦比,但是编辑好excel之后与系统对接却很恶心,现在安利一个小工具,非常方便的将excel文件与系统进行对接
csv.aok
源码地址: csv.aok
下面一步一步教如何使用:
- 安装node环境
- xls, 另存为 如 test.csv
- 直接运行,如下:
#安装aok.js
npm i -g aok.js
#做运行目录
mkdir test
# 拷贝test.csv 到test
cp -f test.csv test/
# 安装csv.aok插件
cd test
npm i csv.aok
# 直接运行
aok . -x -p 10000
- 浏览器访问 : /test
- 现在接口已经完成添加
接口支持方法
get 获取数据接口
curl http://localhost:10000/test
curl http://localhost:10000/test?name=aa
curl http://localhost:10000/test?name=/l.*/
curl "http://localhost:10000/test?page=1&pageSize=2"
curl http://localhost:10000/test?order=age%20asc
# default page =0 pageSize =10 limit is null
curl http://localhost:10000/test?name=/1.*/&limit=1
其中test即文件名称
- 可以根据csv中的列名,做条件查询,如: name=aa
- 支持正则匹配方式查询 如: name=/l.*/
- 支持多条件查询 如: name=lily&age=32
- 支持多个常用关键词:
order: name desc,age asc
page : 分页index ,默认为0,第一页
pageSize ,分页大小,默认为10
limit : 限制条数, 默认为空
index : 每一行数据自动生成的行号,直接可以用
post 新增接口
curl -H "Content-Type: application/json" -X POST -d "{\"name\":\"LiSA\",\"age\":32}" http://localhost:10000/test
curl -H "Content-Type: application/json" -X POST -d "{\"name\":\"aoer\",\"age\":30}" http://localhost:10000/test
curl -H "Content-Type: application/json" -X POST -d "{\"name\":\"luna\",\"age\":28}" http://localhost:10000/test
curl -H "Content-Type: application/json" -X POST -d "{\"name\":\"lily\",\"age\":7}" http://localhost:10000/test
默认json方式提交,当然也支持form方式,直接提交即可
put 修改数据接口
curl -H "Content-Type: application/json" -X PUT -d "{\"remark\":\"update\"}" http://localhost:11540/test?index=2
curl -X PUT -d "remark=update" http://localhost:11540/test?index=2
query 方式作为查询条件,body数据作为修改的值,同时支持json和form方式
delete 删除接口
curl -H "Content-Type: application/json" -X DELETE http://localhost:11540/test?index=2
curl -H "Content-Type: application/json" -X DELETE http://localhost:11540/test
特殊点
- csv支持在线编辑,不要文档方式编辑,如需要文档编辑,请关闭服务
- 数据采用no schema方式设计,字段不需要预定义
- 暂时不支持集群方式部署,如有人需要请issue me