
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
@axolo/leosql
Advanced tools
将HTTP的querystring或body转换为存储引擎(比如MySQL)能够理解和执行的格式,
同时确保存储安全,不被恶意注入攻击,是一项不小的挑战。常规的检索数据方法有:
WHERE)
_eq)_ne)_gt)_lt)_gte)_lte)_have)_start)_end)_logic)
AND)OR)ORDER BY)
_asc)_desc)LIMIT)
_page)_limit)FULLTEXT)
_q)| 请求 | 类型 | 值 |
|---|---|---|
_method | 字符串或数组 | 方法,尽量由程序生成 |
_table | 字符串或数组 | 表,尽量由程序生成 |
_column | 字符串或数组 | 列,尽量由程序生成 |
_value | 字符串或数组 | 值,用于匹配INSERT和UPDATE时的_column |
*_eq | 字符串或数组 | 等于,* 表示字段名 |
*_ne | 字符串或数组 | 不等于,* 表示字段名 |
*_gt | 字符串 | 大于,* 表示字段名 |
*_lt | 字符串 | 小于,* 表示字段名 |
*_gte | 字符串 | 大于等于(不小于),* 表示字段名 |
*_lte | 字符串 | 小于等于(不大于),* 表示字段名 |
*_have | 字符串 | 含有,* 表示字段名 |
*_start | 字符串 | 开头含有,* 表示字段名 |
*_end | 字符串 | 结尾含有,* 表示字段名 |
_logic | 字符串或数组 | 条件之间的逻辑关系,默认为AND。 |
_asc | 字符串或数组 | 顺序 |
_desc | 字符串或数组 | 逆序 |
_page | 正整数 | 分页的页码 |
_limit | 正整数 | 分页的单页记录数 |
_q | 字符串 | 全文检索,对表进行全文搜索,建议独立使用(未实现) |
其中_logic有string和array两种类型,类型不同解析方法也不同,具体如下:
string
统一为各个条件匹配指定的关系。比如_logic=or,则所有条件之间的关系均为OR。
array
按_logic数组顺序逐一为各个条件匹配关系,条件结束匹配完成,数组超出的部分直接丢弃。
数组长度不足时,后续未匹配到的条件关系均默认为AND。
npm install @axolo/leosql
参见LeoSQL文档
const qs = require('qs')
const sqlFormatter = require('sql-formatter')
const leosql = require('../src')
const query = `_table=user\
&_column=id&_column=name&_column=mail\
&_value=ID&_value=NAME&_value=MAIL\
&spawned_gte=20190101&spawned_lte=20190105\
&name=guest&name_ne=admin&name_ne=root\
&destroied_eq=true&destroied_eq=false\
&mail_end=%40mail.com\
&_logic=and&_logic=and&_logic=or\
&_desc=spawned&_desc=modified&_asc=mail\
&_limit=20&_page=3`
const leo = leosql(qs.parse(query))
console.log(sqlFormatter.format(leo.select))
相当于生成如下 MySQL 语句
SELECT
`id`,
`name`,
`mail`
FROM
`user`
WHERE
(
`name` IN ('guest')
OR `name` NOT IN ('admin', 'root')
)
AND `spawned` >= '20190101'
AND `spawned` <= '20190105'
AND `destroied` IN ('true', 'false')
AND `mail` like '%@mail.com'
ORDER BY
`mail` ASC,
`spawned` DESC,
`modified` DESC
LIMIT
40, 20
yarn test
精简NPM发布内容。
组合处理逻辑关系OR。
调整版本号。
方法改为属性。
接受无需转义的请求。
更新引入方式,符合用户习惯。
更新LIMIT逻辑,避免LIMIT 0, 0。
重构,且不兼容0.0.x。
历史版本,不再维护。
FAQs
Generate MySQL from qs.parse(Querystring).
The npm package @axolo/leosql receives a total of 3 weekly downloads. As such, @axolo/leosql popularity was classified as not popular.
We found that @axolo/leosql demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.