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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ioa/rmodel

v9.7.4

Published

数据库查询通用rest api组件

Downloads

4

Readme

@ioa/rmodel

路由模型组件,集成角色、模型、字段级的权限管理,数据类型校验REST API。

在api开发过程中,经常需要向客户端提供一些纯数据库操作的CRUD接口,这些接口的共同特征是除访问权限外的其它业务逻辑几乎是相同的。为了避免编写重复的接口代码,减少接口数量,@ioa/rmodel通过在数据模型与用户api之间加入权限控制中间件,实现安全、快捷的抽象api。

api设计借鉴于postgrest简约的url查询表达式,@ioa/rmodel废除了原来臃肿的json方案,使用更为扁平化、更简洁、更易于读写的函数表达式替换。

查询示例

select

http://localhost:9900/@user?select=title,age,name

select! 反选

http://localhost:9900/@user?select!=title,age,name

where

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

逻辑分隔符

“;”字段分隔符

用于隔离多个字段,字段之间是and关系

where=name.eq(Wilburn);email.eq([email protected])

“|”字段分隔符

竖线表示逻辑or,匹配多个条件中的一个即可

name.eq(a)|name.eq(b)

ormv库运算符

@ioa/rmodel支持ormv中的所有运算符

参考链接:https://github.com/xiangle/ormv

编码转换

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

(:%28

):%29

示例

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

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

角色

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

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

query查询参数

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

通用参数

  • where 逻辑条件过滤表达式

查列表可用参数

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

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

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

  • offset 起始位置

  • page 限定当前第几页

  • limit 限制单页最大条数

  • total 是否显示总量

查详情可用参数

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

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