nodejs MODEL 레이 어 패키지 (2)
1616 단어 Parse
'nodejs MODEL 레이 어 링 (1)' 의 패 키 지 를 통 해 MODEL 레이 어 는 간결 해 졌 지만 모든 MODEL 레이 어 링 방법 이 같 기 때문에 다음 패 키 지 는 같은 코드 를 모두 BaseMODEL 에 패키지 한 다음 에 사용자 정의 MODEL '계승' 을 BaseMODEL 에서 하면 된다.
MODEL 디 렉 터 리 에 BaseMODEL. js 를 새로 만 들 었 습 니 다. 코드 는 다음 과 같 습 니 다.
exports.statics = {
//KeyValue JSON ,
findByKeyValue : function( KeyValue, data ) {
return this.find(KeyValue).exec( data );
},
Find : function( query, data ) {
if(!query.limit){
query.limit = 1000;
}
if(!query.order){
query.order = "-createdAt";
}
if(!query.include){
query.include = "";
}
return this.find(query.where).populate(query.include).limit(query.limit).sort(query.order).exec( data );
},
Update : function( query,data){
query.data.updatedAt = Date.now(); // , updatedAt
return this.update({_id:query._id},query.data).exec(data);
}
};
그리고 MODEL 코드 를 바 꿀 수 있 습 니 다.
var Schema = require('mongoose').Schema;
var MODEL = Schema({
Advertiser: {type:Schema.Types.ObjectId,ref:'UserMODEL'},
Name: String, //
Intro: String,
createdAt:{
type:Date,
default:Date.now()
},
updatedAt:{
type:Date,
default:Date.now()
}
}, {collection: "Plan"});
var BaseMODEL = require("./BaseMODEL");
MODEL.statics = BaseMODEL.statics;
/* global db */
module.exports = db.model('PlanMODEL', MODEL);
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Cocos2d-x로 Parse.com에 로그인Parse.com은 모바일 앱에 백엔드를 제공하는 BaaS 중 하나로 로그인 및 데이터 저장 등 서버 측에서 처리해야 하는 기능을 쉽게 추가할 수 있습니다. 이것을 Cocos2d-x에서 사용해 보겠습니다. 샘플 프로...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.