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

restify-curd

v1.0.8

Published

npm install restify-curd

Downloads

5

Readme

restify-curd

通用的collection操作,包含GET,POST,PATCH,DEL等。

TODO

  • 内嵌文档支持分页
  • 支持无限极内嵌文档
  • 支持更多的查询条件

更新

1.0.6

  • 使用了最新版本[email protected],固定package.json的依赖版本号
  • 修复了[email protected]修改的findOneAndUpdate第三个参数导致的更新数据失败bug
  • 修正README.md
  • 添加了集成测试

1.0.5

  • childs参数支持最多3级
  • put,patch内嵌文档时,因为mongodb问题,更新操作非原子操作。

1.0.4

  • 增加一个options参数childs,可以指定查询内嵌文档
  • 增加一个批量删除接口

1.0.3

  • 参数由原先的(server,db,modelName,schemaConfig,options)修改为(server,Model,options)
  • createAt和random字段由默认配置修改为schema动态添加
  • 如果传入的Model.schema中未设置createAt和random字段时,REST请求将无法获取这两个字段。
  • options参数增加一个字段path,标识路由路径,默认为Model.modelName,不需要加/

Installation

npm install restify-curd

使用

restify = require 'restify'
mongoose = require 'mongoose'
curd = require 'restify-curd'

server = restify.createServer()
db = mongoose.createConnection 'mongodb://localhost/restify-curd-test'
db.once 'open',->
    Model = db.model 'test',schema
    curd (server,Model,options)
    server.listen port,->
        console.log 'server start.'

参数

  • server object
  • Model mongoose Model
  • options object

options参数

  • list boolean 是否开放获取列表接口,默认开放
  • post boolean 是否开放新建接口,默认开放
  • get boolean 是否开放获取详情接口,默认开放
  • put boolean 是否开放修改接口,默认开放
  • patch boolean 是否开放修改接口,默认开放
  • del boolean 是否开放删除接口,默认开放
  • delAll boolean 是否开放批量删除接口,默认开放
  • path String 路由资源地址,默认为Model.modelName
  • childs Array/Object 指定一个内嵌文档字段和开放的接口

childs参数:

  • list post get put patch del delAll
  • path 内嵌文档的字段名称和路径

其他默认设置

  • 默认为schemaConfig添加createAt和random两个数字类型数字,一个标识创建资源的时间,一个为小于1的随机数字,用于获取随机数据。

GET /collection 获取列表

参数:

  • limit number
  • page number
  • sortby string 默认按createAt大小逆序排列
  • desc asc/desc
  • fields string 逗号分隔的字符串

返回:

  • count number
  • page number
  • limit number
  • sortby string
  • desc asc/desc
  • list array

POST /collection 新建

返回新建的记录

GET /collection/:id 查询指定id的记录

参数:

  • fields string 逗号分隔的字符串

PUT /collection/:id 更新指定id的记录

返回该记录信息

PATCH /collection/:id 修改指定id的记录

返回该记录信息

DELETE /collection/:id 删除指定id的记录

DELETE /collection 删除符合条件的记录

参数:

  • 所有条件作为queryString

内嵌文档

当options参数中指定了childs参数时,会自动为内嵌文档增加对应的路由

POST /collection/:id/child 新增一个内嵌文档

返回新建的记录。

GET /collection/:id/child 查询所有内嵌文档

注意该地址和父文档不同,不支持分页排序等,只会返回所有记录。

其他路由同父文档。