Created
April 16, 2012 19:25
-
-
Save mikevalstar/2400899 to your computer and use it in GitHub Desktop.
Coding with Node Part 4 - section 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var mongoose = require('mongoose'); | |
| var Schema = mongoose.Schema | |
| , ObjectId = Schema.ObjectId; | |
| var Database = module.exports = function Database(){}; | |
| Database.prototype = { | |
| _collections: { | |
| adminUser: { | |
| login : String | |
| , password : String | |
| }, | |
| blogPost:{ | |
| sid : { type: Number, required: true, unique: true, index: true }, | |
| author : { type: String }, | |
| title : { type: String }, | |
| img_lg : { type: String }, | |
| img_sm : { type: String }, | |
| content : { type: String }, | |
| short : { type: String }, | |
| ext_link: { type: String }, | |
| posted : { type: Date, index: true, default: Date.now }, | |
| edited : { type: Date, default: Date.now }, | |
| }, | |
| } | |
| , _db: null | |
| , _schema: {} | |
| , _model: {} | |
| , connect: function(url){ | |
| mongoose.connect(url); | |
| this._schema.adminUser = new Schema(this._collections.adminUser); | |
| this._model.adminUser = mongoose.model('adminUser', this._schema.adminUser); | |
| this._schema.blogPost = new Schema(this._collections.blogPost); | |
| this._model.blogPost = mongoose.model('blogPost', this._schema.blogPost); | |
| } | |
| , model: function(mod){ | |
| switch (mod){ | |
| case 'adminUser': | |
| return this._model.adminUser; | |
| case 'blogPost': | |
| return this._model.blogPost; | |
| } | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment