Ai
2 Star 0 Fork 0

hashplus/ACdream

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ids.js 689 Bytes
一键复制 编辑 原始数据 按行查看 历史
kidx 提交于 2014-06-06 11:07 +08:00 . models代码规范化
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var OE = require('../settings').outputErr;
function IDs (ids){
this.name = ids.name;
this.id = ids.id;
}
module.exports = IDs;
var idsObj = new Schema({
name: {type: String, index: {unique: true}},
id: Number
});
mongoose.model('idss', idsObj);
var idss = mongoose.model('idss');
IDs.get = function(idname, callback) {
idss.findOneAndUpdate({name: idname}, {$inc:{'id':1}}, function(err, doc) {
if (err) {
OE('IDs.get failed!');
return callback (err, null);
}
if (!doc) {
err = 'You should init the ids first!';
throw err;
}
return callback(err, doc.id);
});
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hashplus/ACdream.git
git@gitee.com:hashplus/ACdream.git
hashplus
ACdream
ACdream
master

搜索帮助