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

duzq-quick-mongo

v1.3.13

Published

# quick-mongo nodejs+mongodb+express API快速生成 ## 使用说明 安装 `$ npm install duzq-quick-mongo` 建立mongodb数据模型 ```js const mongoose = require("../utils/mongodb") const dayjs = require("dayjs") // User模型 const UserSchema = new mongoose.Schema({ id:{type:

Downloads

11

Readme

quick-mongo

nodejs+mongodb+express API快速生成

使用说明

安装

$ npm install duzq-quick-mongo

建立mongodb数据模型

const mongoose = require("../utils/mongodb")
const dayjs = require("dayjs")

// User模型
const UserSchema = new mongoose.Schema({
    id:{type:String, default: dayjs().unix()},
    name:String,
    pwd:{type: String,required:true,
        set(val){ // 密码加密
            return require("bcrypt").hashSync(val,10)
        }},
    mobile:{type: String, required:true},
    createTime:String,
    updateTime:String,
},{
    timestamps: { createdAt: 'createTime', updatedAt: 'updateTime' }
})
const User = mongoose.model("User",UserSchema)
// export
module.exports = User;

初始化控制器

const {Controller} = require("duzq-quick-mongo")
const user = new Controller( require("../models/User"))

添加路由

router.post("/add", user.add)
router.post("/getItem", user.getItem)
router.post("/delete", user.delete)
router.post("/update", user.update)
router.post("/list", user.list)
router.post("/search", user.search)

恭喜你。

实现了User模块的增删改查的功能。

接口使用

添加数据

请求参数

{
	"name": "dzq",
	"mobile": "13800138000",
	"pwd": "123456"
}

返回结果

{
	"code": 200,
	"msg": "success",
	"data": {
		"id": "1608954581",
		"_id": "5fe6b2f1eb030db3f5d4c1bd",
		"name": "dzq",
		"mobile": "13800138000",
		"pwd": "$2b$10$VMgVXPNSI7TuHtIYo0vY0ufi6PgsCEc.sv1VkSl0KKkd9Hv3u4gOO",
		"createTime": "Sat Dec 26 2020 11:50:10 GMT+0800 (China Standard Time)",
		"updateTime": "Sat Dec 26 2020 11:50:10 GMT+0800 (China Standard Time)",
		"__v": 0
	}
}

获取数据

请求参数

{
	"id": "1608954581"
}

返回结果

{
	"code": 200,
	"msg": "success",
	"data": {
		"id": "1608954581",
		"_id": "5fe6b2f1eb030db3f5d4c1bd",
		"name": "dzq",
		"mobile": "13800138000",
		"pwd": "$2b$10$VMgVXPNSI7TuHtIYo0vY0ufi6PgsCEc.sv1VkSl0KKkd9Hv3u4gOO",
		"createTime": "Sat Dec 26 2020 11:50:10 GMT+0800 (China Standard Time)",
		"updateTime": "Sat Dec 26 2020 11:50:10 GMT+0800 (China Standard Time)",
		"__v": 0
	}
}

删除数据

请求参数

{
	"id": "1608954581"
}

返回结果

{
	"code": 200,
	"msg": "success",
	"data": {
		"id": "1608954581",
		"_id": "5fe6b2f1eb030db3f5d4c1bd",
		"name": "dzq",
		"mobile": "13800138000",
		"pwd": "$2b$10$VMgVXPNSI7TuHtIYo0vY0ufi6PgsCEc.sv1VkSl0KKkd9Hv3u4gOO",
		"createTime": "Sat Dec 26 2020 11:50:10 GMT+0800 (China Standard Time)",
		"updateTime": "Sat Dec 26 2020 11:50:10 GMT+0800 (China Standard Time)",
		"__v": 0
	}
}

错误结果

{
	"code": 301,
	"msg": "failed"
}

更新数据

请求参数

{
	"id": "1608954581",
	"updateData": {
		"mobile": 13800138099,
		"pwd": "666666"
	}
}

获取数据列表

请求参数

{
	"pageSize": 10,
	"page": 1
}

返回结果

{
	"code": 200,
	"msg": "success",
	"data": {
		"pageSize": 10,
		"page": 1,
		"total": 1,
		"data": [
			{
				"id": "1608954581",
				"name": "dzq",
				"mobile": "13800138000",
				"pwd": "$2b$10$4otU4K9W08whZ3DFJyflBeXgxzRGrHpxlHKT940gDvvvgLmCBYT4a",
				"createTime": "Sat Dec 26 2020 11:57:19 GMT+0800 (China Standard Time)",
				"updateTime": "Sat Dec 26 2020 11:57:19 GMT+0800 (China Standard Time)"
			}
		]
	}
}

查找数据

请求参数

默认查询条件为与操作,条件满足其中一条需要设置operator为or

{
	"pageSize": 10,
	"page": 1,
	"conditions": {
		"name": "dzq",
		"mobile": "18518318421"
	},
	"operator": "or"
}

返回结果

{
	"code": 200,
	"msg": "success",
	"data": {
		"pageSize": 10,
		"page": 1,
		"total": 1,
		"data": [
			{
				"id": "1608954581",
				"name": "dzq",
				"mobile": "13800138000",
				"pwd": "$2b$10$4otU4K9W08whZ3DFJyflBeXgxzRGrHpxlHKT940gDvvvgLmCBYT4a",
				"createTime": "Sat Dec 26 2020 11:57:19 GMT+0800 (China Standard Time)",
				"updateTime": "Sat Dec 26 2020 11:57:19 GMT+0800 (China Standard Time)"
			}
		]
	}
}

高级应用

插件提供了一下高级自定义功能

const {Controller} = require("duzq-quick-mongo")
const user = new Controller( require("../models/User"))
// 设置数据查询字段
user.projection = {"__v":0,"pwd":0,"updateTime":0,"createTime":0}
// 设置成功编号
user.CODE_OK = 200
// 设置成功消息
user.MSG_OK = "请求成功"
// 设置失败编号
user.CODE_ERROR = 201
// 设置失败消息
user.MSG_ERROR = "请求错误"

自定义前返回数据

{
	"code": 200,
	"msg": "success",
	"data": {
		"id": "1608954581",
		"_id": "5fe6b2f1eb030db3f5d4c1bd",
		"name": "dzq",
		"mobile": "13800138000",
		"pwd": "$2b$10$VMgVXPNSI7TuHtIYo0vY0ufi6PgsCEc.sv1VkSl0KKkd9Hv3u4gOO",
		"createTime": "Sat Dec 26 2020 11:50:10 GMT+0800 (China Standard Time)",
		"updateTime": "Sat Dec 26 2020 11:50:10 GMT+0800 (China Standard Time)",
		"__v": 0
	}
}

自定义后获取数据

{
	"code": 200,
	"msg": "请求成功",
	"data": {
		"id": "1608954581",
		"_id": "5fe6b49feb030db3f5d4c1be",
		"name": "dzq",
		"mobile": "13800138000"
	}
}

示例代码:https://github.com/dzq/quick-mongo-simple

更加功能需求请提交issue: https://github.com/dzq/quick-mongo