Created
January 7, 2012 19:25
-
-
Save ryancole/1575722 to your computer and use it in GitHub Desktop.
This file contains 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
express = require 'express' | |
routes = require './routes' | |
models = require './models' | |
# initialize the application server | |
app = module.exports = express.createServer() | |
... | |
models.user.count() |
This file contains 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
mongo = require 'mongodb' | |
model_user = require './user' | |
# define the database connection | |
db_server = new mongo.Server 'localhost', 27107, {} | |
db_client = new mongo.Db 'foo', db_server | |
# open the database connection | |
db_client.open -> | |
console.log 'database connection opened' | |
# export the db object modules | |
exports.user = new model_user(db_client) |
This file contains 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
# define the user db object | |
class User | |
constructor: (@db) -> | |
count: -> | |
@db.collection 'users', (err, collection) -> | |
collection.count (err, count) -> | |
if err | |
console.log err | |
else | |
console.log "there are #{ count } users" | |
# export the db object | |
module.exports = User |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment