Current collected state Current
Observed since 20 Oct, 18:07 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
nodejs工具包
1用于nodejs,混合工具包。
const toolKit = require("test-tool-kit");
global.toolKit = toolKit;
toolKit.download(url, path)
下载文件
@param {*} url 下载文件接口
@param {*} path 保存本地地址
toolKit.sql
mongodb 增删改查
| 方法 | 描述 | 代码 | 属性 | 属性类型 | 说明 |
|---|---|---|---|---|---|
| insert | 增 | insert({colName, data}) | colName | Function | 数据库集合 |
| data | Object | 插入数据 | |||
| remove | 删 | remove({colName, where={}, num=1}) | colName | Function | 数据库集合 |
| where | Object | 删除条件 | |||
| num | Number | 删除数量 | |||
| update | 改 | update({colName, where, data, num=1}) | colName | Function | 数据库集合 |
| where | Object | 修改条件 | |||
| data | Object | 修改数据 | |||
| num | Number | 修改数量 | |||
| get | 根据指定条件查 | get({colName, where={},}) | colName | Function | 数据库集合 |
| where | Object | 查找条件 | |||
| getPage | 查分页 | getPage({colName, where={}, index=0, num=10}) | colName | Function | 数据库集合 |
| where | Object | 查找条件 | |||
| index | Number | 查找页码 | |||
| num | Number | 查找数量 | |||
| getSort | 排序查 | getSort({colName, where={}, sort={},}) | colName | Function | 数据库集合 |
| where | Object | 查找条件 | |||
| sort | Object | 1为升序,-1为降序 | |||
| getMold | 查分类 | getMold({colName, keyWord}) | colName | Function | 数据库集合 |
| keyWord | String | 查找字段 | |||
| getLen | 查数量 | getLen({colName, keyWord}) | colName | Function | 数据库集合 |
测试代码演示
server.js
const express = require("express");
const bodyParser = require('body-parser');
const cors = require("cors");
const toolKit = require("test-tool-kit");
global.toolKit = toolKit;
const test = require("./www/sql/test");
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cors());
app.use(test);
app.listen(3000);
db.js
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/test',{
useNewUrlParser: true,
useUnifiedTopology: true
}).then(() => console.log('数据库连接成功!'))
.catch(() => console.log('数据库连接失败!'));
module.exports = mongoose
user.js
const db = require("./db");
var userObj = new db.Schema({
name: String,
});
module.exports = db.model("user", userObj, "user");
test.js
const express = require("express");
const user = require("./user");
const router = express();
router.post('/insert', (req, res) => {
const { body: { data } } = req
toolKit.sql.insert({
colName: user,
data: JSON.parse(data)
}).then(val => {
console.log(val)
res.status(200).json(val);
})
})
module.exports = router
version 1.0.1
version 1.0.2
version 1.0.3
version 1.0.4
Download counts and popularity will appear here as the collector receives them.
This describes our collected data; it is not a security assessment.
Observed since 20 Oct, 18:07 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:e72abb69f7607e9a94942488b5b6eb316197c0a3e0c5323f69f67fab7e4d34a7