Skip to content
Lance Pollard edited this page Apr 16, 2012 · 1 revision

Code Snippets

Quick examples of how to do common things that are too [perhaps] specific to be included in the framework itself.

Sequential IDs in Mongo

class App.Sequence extends Tower.Model
  @field "value", type: "Integer"
  
  # only works in mongodb, refactor later.
  # collection.findAndModify(query, sort, update, options, callback)
  @next: (name, callback) ->
    @store().collection().findAndModify {_id: name}, [['_id','asc']], {"$inc": {value: 1}}, {upsert: true, new: true}, (error, record) =>
      callback.call @, error, try record.value
    
    undefined

Tower.js

Everything here will be reflected on http://towerjs.org/guides.

Clone this wiki locally