npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

ioa-rest

v6.0.0-alpha.3

Published

客户端查询数据库通用Rest Aip组件

Downloads

3

Readme

ioa-rest

客户端远程操作数据库通用API组件,包含角色管理、权限控制、ORM模型、数据校验、及REST API。

借鉴于postgrest简约的url查询表达式,ioa-rest使用了更加扁平化、更简洁、更易于读写的函数链表达式替换原来臃肿的json方案。

查询示例

and多字段

http://localhost:9900/model/user?where=name.eq(Wilburn);email.eq([email protected]);age.eq(94580)

and单字段

http://localhost:9900/model/user?where=email.eq([email protected])
http://localhost:9900/model/user?where=email.gte(12).lt(100)

or多字段

http://localhost:9900/model/user?where=name.eq(12)||email.scope(1,45)

or单字段

http://localhost:9900/model/user?where=email.eq(8)|scope(1,45)|max(99)

组件依赖

  • ioa-db

  • ioa-auth

逻辑运算符

  • ';' 分号,多字段分隔符,功能等同于and

  • '.' 点,单字段and条件,功能等同于and

  • '||' 双或,多字段or条件

  • '|' 单或,单字段or条件

ormv库运算符

ioa-rest支持ormv中的所有运算符

编码转换

由于url参数存在保留关键字限制,当输入参数值中包含类似于&=()的保留关键字时需要使用encodeURIComponent()进行编码转换

(:%28

):%29

示例

// 错误,赋值中包含非法的保留字()
http://localhost:9900/model/user?where=phone.eq((559)-150-5961)

// 正确,()被转换为对应的url编码
http://localhost:9900/model/user?where=phone.eq(%28559%29-150-5961)

联表查询

由于项目是基于Ormv预定义的关系模型,受Ormv模型限制,ioa-rest不支持url动态联表。

http://localhost:9900/model/user?leftJoin=shop(a,b,c);id.eq(15);mid.get(15);title.lt(15);

角色

当允许客户端通过api直接操作数据库时会涉及到很多安全问题,因此角色、权限的控制必不可少。

ioa-rest中的角色是针对数据库的操作权限分组,并非常规的按照路由进行角色权限分组概念。

角色权限配置文件

ioa-rest为每个组件扩展了rests目录,以角色名作为目录进行分组,每个配置文件名都需要有对应的数据模型。

  • method Array 操作类型,可选值:GET、POST、PUT、DELETE

  • select Array 选择字段组

    • $fieldName String 可访问的字段名
  • prevent Array 禁止使用受保护的字段

    • $fieldName String 不可访问的字段名,用于排除敏感字段
  • where Object 对应sql中的where查询强制约束字段

    • $fieldName String 约束字段,可通过path表达式从ctx中取值,如'auth.uid'可获取ctx.auth.uid的值
  • set Object 创建、更新数据时预设的强制填充字段,可通过path表达式从ctx中取值

    • $fieldName String 赋值字段,可通过path表达式从ctx中取值,如'auth.uid'可获取ctx.auth.uid的值

配置示例

{
   'method': ['GET', 'PUT', 'DELETE'],
   'prevent': ['password'],
   'where': {
      'uid': 'auth.uid',
   },
   'set': {
      'uid': 'auth.uid',
   }
}

query查询参数

支持Ormv中的所有运算符和查询语句。除此之外ioa-rest还扩展了一部分专用选项,用于简化查询语句。以下凡标注为“扩展参数”的选项均为ioa-rest私有。

通用参数

  • where 数据过滤表达式

    • . and匹配,where=name.eq(lala);name.eq(lala);

    • | or匹配,where=name.eq(lala)|.neq(dudu);

select专用参数

  • select 选择字段,select=name,title,email

  • select! 反选字段,select!=uid,password

select查询列表专用参数

  • order 限定排序条件,order=name.desc;title.desc;

  • offset 起始位置

  • page 限定当前第几页

  • limit 限制单页最大条数

  • total 是否显示总量