3 个版本
0.202107.4 | 2021 年 7 月 14 日 |
---|---|
0.202107.3 | 2021 年 7 月 14 日 |
0.202107.2 | 2021 年 7 月 8 日 |
1803 在 解析实现
2.5MB
4.5K SLoC

文档(进行中)
[tests.hello]
script = '''
cat<<EOS | pq -q "SELECT NAME, LOGNAME" -t json
{
"SHELL": "/bin/bash",
"NAME": "my machine name",
"PWD": "/home/fuyutarow/piqel",
"LOGNAME": "fuyutarow",
"HOME": "/home/fuyutarow",
"LANG": "C.UTF-8",
"USER": "fuyutarow",
"HOSTTYPE": "x86_64",
"_": "/usr/bin/env"
}
EOS
'''
tobe = '''
[
{
"NAME": "my machine name",
"LOGNAME": "fuyutarow"
}
]
'''
系列
内容 | 语言 | 包 |
---|---|---|
pq | 命令行界面(brew,scoop) | |
piqel | Rust(cargo) | https://crates.io/crates/piqel |
piqel-js | JavaScript(npm) | https://npmjs.net.cn/package/piqel |
piqel-py | Python(pip) | https://pypi.ac.cn/project/piqel |
常数表
功能
动机
什么是 PartiQL?
用法
美化打印
选项 | 描述 |
---|---|
-c, --compact | 紧凑格式而不是美化打印输出,仅当输出为 JSON 时 |
-S, --sort-keys | 对输出对象上的键进行排序。当 --to 选项为 json 时有效,目前 |
curl -s "https://api.github.com/repos/fuyutarow/piqel/commits?per_page=1" | pq
转换文件格式
选项 | 描述 |
---|---|
-f, --from | 目标配置文件 [可能值:csv,json,toml,yaml,xml] |
-t, --to | 目标配置文件 [可能值:csv,json,toml,yaml,xml] |
使用 -t
选项 c 将 Json、Yaml、Toml 和 XML 转换为彼此。
cat pokemon.json | pq -t yaml
cat pokemon.json | pq -t yaml | pq -t toml
与现有命令 yj 的比较
格式 | pq | yj |
---|---|---|
JSON | ✅ | ✅ |
TOML | ✅ | ⚠️*1 |
YAML | ✅ | ✅ |
XML | ✅ | ✅ |
CSV | ✅ | ❌ |
*1 下述格式的 TOML 无法用 yj
序列化,但可以通过相应地替换字段用 pq
序列化。
{
"name": "partiql-pokemon",
"dependencies": {
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"license": "MIT"
}
选项 | 描述 |
---|---|
-q |
查询 |
query | 描述 |
---|---|
SELECT <field_path> |
|
SELECT <field_path> AS <alias_path> |
计算 BMI
- 下载文件并在本地计算 BMI。
curl -s https://raw.githubusercontent.com/fuyutarow/pokemon.json/master/en/pokemon.json | pq -q "SELECT name, weight/height/height AS bmi ORDER BY bmi DESC LIMIT 20"
- 在终端,向服务器发送查询以在远程计算 BMI。
curl https://partiql-pokemon.vercel.app/api/pokemon/ja -G --data-urlencode "q= SELECT name, weight/height/height AS bmi ORDER BY bmi DESC LIMIT 20"
- 在网页浏览器中,向服务器发送查询以在远程计算 BMI。
安装
brew install fuyutarow/tap/pq
pq -h
scoop install pq
pq -h
转换数据
env | jo | pq "SELECT NAME AS name, USER AS user"
ip
命令仅在 Linux 和 WSL 中可用,不在 Mac 中。
ip -j -p | pq "$(cat<<EOS
SELECT
address,
info.family AS inet,
info.local
FROM addr_info AS info
WHERE inet LIKE 'inet%'
EOS
)"
- [x] SELECT
- [x] FROM
- [x] LEFT JOIN
- [x] WHERE
- [x] LIKE
- [x] ORDER BY
- [x] LIMIT
测试
使用 tests-make 测试 CLI pq
。
brew install fuyutarow/tap/tests-make
tests-make tests-make/index.toml
或
makers test:pq
内容 | 测试 | 命令 |
---|---|---|
pq | 测试 | 制造测试:pq |
piqel | 测试 | 制造测试:库 |
piqel-js | 测试 | 制造测试:js |
piqel-py | 测试 | makres测试:py |
全部 | 制造测试 |
代码覆盖率
cargo install cargo-kcov
cargo kcov
或
makers cov
准备
makers install-dev
构建
makers build
makers build:pq ;: for pq commnad
LICENCE
附录
可提取字段的工具比较
jq方法
curl -s "https://api.github.com/repos/fuyutarow/piqel/commits?per_page=1" | jq ".[].commit.author"
gron方法
curl -s "https://api.github.com/repos/fuyutarow/piqel/commits?per_page=1" | gron | grep "commit.author" | gron -u
nusehll方法
curl -s "https://api.github.com/repos/fuyutarow/piqel/commits?per_page=1" | from json | get commit.author | to json
pq方法
curl -s "https://api.github.com/repos/fuyutarow/piqel/commits?per_page=1" | pq -q "SELECT commit.author"
utils
- makers
https://github.com/sagiegurari/cargo-make … 运行
cargo install cargo-make
以使用makers
命令。 ↩︎
依赖项
~12–24MB
~354K SLoC