4 releases (2 breaking)

0.202107.0 Jul 7, 2021
0.202106.4 Jun 10, 2021
0.202106.3 Jun 8, 2021
0.202105.8 May 23, 2021

#1324 in Parser implementations

MIT and maybe LGPL-3.0-or-later

595KB
4K SLoC

partiql-rs

An implementation of PartiQL written in Rust

Document(WIP)

[tests.hello]
script = '''
cat<<EOS | pq -q "SELECT NAME, LOGNAME" -t json
{
  "SHELL": "/bin/bash",
  "NAME": "my machine name",
  "PWD": "/home/fuyutarow/partiql-rs",
  "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"
  }
]
'''

Familiy

content lang package
pq CLI (brew, scoop)
partiql-rs Rust (cargo) https://crates.io/crates/partiql-rs
partiql-js JavaScript (npm) https://www.npmjs.com/package/partiql-js
partiql-py Python (pip) https://pypi.org/project/partiql

Table of Contants

Features

Motivation

What’s PartiQL?

Usage

pretty print

option description
-c, --compact compact instead of pretty-printed output, only when outputting in JSON
-S, --sort-keys sort keys of objects on output. it on works when --to option is json, currently
curl -s "https://api.github.com/repos/fuyutarow/partiql-rs/commits?per_page=1" | pq

convert file format

option description
-f, --from target config file [possible values: csv, json, toml, yaml, xml]
-t, --to target config file [possible values: csv, json, toml, yaml, xml]

use -t option c to convert Json, Yaml, Toml, and XML to each other.

cat pokemon.json | pq -t yaml
cat pokemon.json | pq -t yaml | pq -t toml

Comparison with existing command yj

format pq yj
JSON
TOML ⚠️*1
YAML
XML
CSV

*1 TOML of the following format cannot be serialized with yj, but it can be serialized with pq by replacing the fields accordingly.

{
  "name": "partiql-pokemon",
  "dependencies": {
    "react": "^16.13.1",
    "react-dom": "^16.13.1"
  },
  "license": "MIT"
}
option description
-q クエリ
query description
SELECT <field_path>
SELECT <field_path> AS <alias_path>

Calculate BMI

  1. Download the file and then calculate BMI in local.
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"
  1. In terminal, send a query to the server to calculate BMI in remote.
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"
  1. In web browser, send a query to the server to calculate BMI in remote.

[“https://partiql-pokemon.vercel.app/api/pokemon/en?q= SELECT name, weight/height/height AS bmi ORDER BY bmi DESC LIMIT 20”] (https://partiql-pokemon.vercel.app/api/pokemon/ja?q= SELECT name, weight/height/height AS bmi ORDER BY bmi DESC LIMIT 20)

partiql-pokemon.vercel.app/api/pokemon/en?q= SELECT name, weight/height/height AS bmi ORDER BY bmi DESC LIMIT 20

[partiql-pokemon.vercel.app/api/pokemon/en?q= SELECT name, weight/height/height AS bmi ORDER BY bmi DESC LIMIT 20] (https://partiql-pokemon.vercel.app/api/pokemon/ja?q= SELECT name, weight/height/height AS bmi ORDER BY bmi DESC LIMIT 20)

https://partiql-pokemon.vercel.app/api/pokemon/ja?q= SELECT name, weight/height/height AS bmi ORDER BY bmi DESC LIMIT 20

Installation

brew install fuyutarow/tap/pq
pq -h
scoop install pq
pq -h

Convert data

env | jo | pq "SELECT NAME AS name, USER AS user"

ip command is only available in Linux and WSL, not in 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

more examples

Test

Use tests-make to test CLI pq.

brew install fuyutarow/tap/tests-make
tests-make tests-make/index.toml

or

makers test:pq
content test command
pq test makers test:pq
partiql-rs test makers test:lib
partiql-js test makers test:js
partiql-py test makres test:py
all makers test

code coverage

cargo install cargo-kcov
cargo kcov

or

makers cov

Preparation

makers install-dev

build

makers build
makers build:pq ;: for pq commnad

LICENCE

Appendix

Comparison of tools that can extract fields

jq approach

curl -s "https://api.github.com/repos/fuyutarow/partiql-rs/commits?per_page=1" | jq  ".[].commit.author"

gron approach

curl -s "https://api.github.com/repos/fuyutarow/partiql-rs/commits?per_page=1" | gron | grep "commit.author" | gron -u

nusehll approach

curl -s "https://api.github.com/repos/fuyutarow/partiql-rs/commits?per_page=1" | from json | get commit.author | to json

pq approach

curl -s "https://api.github.com/repos/fuyutarow/partiql-rs/commits?per_page=1" | pq -q "SELECT commit.author"

utils

  • makers

  1. https://github.com/sclevine/yj ↩︎

  2. https://github.com/stedolan/jq ↩︎

  3. https://github.com/tomnomnom/gron ↩︎

  4. https://github.com/nushell/nushell ↩︎

  5. https://github.com/fuyutarow/partiql-rs ↩︎

  6. https://github.com/sagiegurari/cargo-make … Run cargo install cargo-make to use makers commnad. ↩︎

Dependencies

~17–35MB
~563K SLoC