Skip to content

Instantly share code, notes, and snippets.

@hvgotcodes
Created July 16, 2012 17:45
Show Gist options
  • Save hvgotcodes/3123974 to your computer and use it in GitHub Desktop.
Save hvgotcodes/3123974 to your computer and use it in GitHub Desktop.
hsc.models.initStore = ->
server = require('com.obscure.TiTouchDB');
hsc.models.db = db = server.databaseNamed('hackersc');
db.ensureCreated();
hsc.models.design = design = db.designDocumentWithName 'hsc'
currentRoundMap = "
function(doc) {
if (doc.type === 'round' && doc.status === 'current')
emit(null, doc);
}
"
design.defineView "currentRound", currentRoundMap
design.saveChanges()
# db.deleteDatabase();
Ti.API.info "database #{ db.relativePath}: #{ db.getDocumentCount() }"
hsc.models.getCurrentRound = ->
query = hsc.models.design.queryViewNamed 'currentRound'
result = query.rows()
console.log "result #{result} #{ result.rowCount }"
if result.rowCount
console.log "getting next row"
row = result.nextRow()
doc = row.document
round = hsc.models.Round.hydrate doc
hsc.models.currentRound = round
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment